Skip to content

Fullstack demo that detects and classifies click events as human or bot. Built with a Node.js + PostgreSQL backend and a React + Chart.js frontend, it stores events, runs classification logic, and visualizes results through interactive dashboards (daily real vs. fake counts, fake rate, user table).

Notifications You must be signed in to change notification settings

ndrada/clickstream-classifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ClickStream Classifier (Demo)

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).

Stack

  • Node 18+, Express, CORS
  • PostgreSQL (pg)
  • Chart.js (frontend)
  • Vanilla HTML/CSS/JS

Project structure

repo/

    backend/

      server.js

      db.js

      package.json

      .env.example

    public/

      index.html

      app.js

      styles.css

    README.md

Prereqs

  • Node 18+
  • PostgreSQL running locally
  • VS Code Live Server (or any static file server)

Environment

Create backend/.env (copy from .env.example)

DATABASE_URL=postgres://bytebrew_user:bytebrew_pass@localhost:5432/bytebrew

PORT=3000

Database schema

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);

Run

  1. Install & start backend API

    cd backend

    npm install

    npm run dev

    (Health check: http://127.0.0.1:3000/api/events should return JSON)

  2. Serve frontend with Live Server

    CORS is enabled on the API so cross-origin calls from :5500 will work

  3. ENDPOINTS

    • POST /api/generate?pattern=human|bot creates & classifies a synthetic event

    • GET /api/events returns latest 100 events (for table + totals donut)

    • GET /api/metrics daily aggregates:

      [
        { "day":"YYYY-MM-DD", "human":N, "bot":M, "total":T, "fakeRate": M/T }
      ]
      

Features delivered

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

About

Fullstack demo that detects and classifies click events as human or bot. Built with a Node.js + PostgreSQL backend and a React + Chart.js frontend, it stores events, runs classification logic, and visualizes results through interactive dashboards (daily real vs. fake counts, fake rate, user table).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published