Tiny full-stack demo that generates click events, classifies them as human or bot, stores them in Postgres and visualizes results with Chart.js (daily Real/Fake counts, Fake Rate, and a Users table).
- Node 18+, Express, CORS
- PostgreSQL (
pg) - Chart.js (frontend)
- Vanilla HTML/CSS/JS
repo/
backend/
server.js
db.js
package.json
.env.example
public/
index.html
app.js
styles.css
README.md
- Node 18+
- PostgreSQL running locally
- VS Code Live Server (or any static file server)
Create backend/.env (copy from .env.example)
DATABASE_URL=postgres://bytebrew_user:bytebrew_pass@localhost:5432/bytebrew
PORT=3000
CREATE TABLE IF NOT EXISTS public.events (
id SERIAL PRIMARY KEY,
ad_id TEXT NOT NULL,
clicks JSONB NOT NULL,
classification TEXT NOT NULL,
domain TEXT,
user_agent TEXT,
browser TEXT,
ip TEXT,
country TEXT,
created_at TIMESTAMPTZ DEFAULT now()
);
CREATE INDEX IF NOT EXISTS events_created_at_idx ON public.events (created_at);
CREATE INDEX IF NOT EXISTS events_classification_idx ON public.events (classification);-
Install & start backend API
cd backendnpm installnpm run dev(Health check:
http://127.0.0.1:3000/api/eventsshould return JSON) -
Serve frontend with Live Server
CORS is enabled on the API so cross-origin calls from :5500 will work
-
ENDPOINTS
-
POST /api/generate?pattern=human|botcreates & classifies a synthetic event -
GET /api/eventsreturns latest 100 events (for table + totals donut) -
GET /api/metricsdaily aggregates:[ { "day":"YYYY-MM-DD", "human":N, "bot":M, "total":T, "fakeRate": M/T } ]
-
Charts: Real/day, Fake/day, Fake Rate/day (Chart.js)
Totals donut (human vs bot, all recent events)
Users table: adId, domain, userAgent, browser, ip, country, classification, createdAt, clickCount
Randomized generator: variable count & timing for human/bot patterns
Lightweight classifier: interval stats + heuristics
Debug overlay (toggle) for raw event JSON