A full-stack bot detection platform with behavior tracking, risk scoring, an admin dashboard, and a traffic simulator for end-to-end testing.
Ensure you have Node.js >= 18.0.0, npm >= 9.0.0, and MongoDB >= 5.0.
npm installCopy the .env.example to .env in the root folder.
cp .env.example .env| Variable | Description |
|---|---|
MONGODB_URI |
MongoDB connection string (See MongoDB Schemas) |
JWT_SECRET |
Secret for signing JWTs (change in production) |
PORT |
Detection API Backend port (default: 5000) |
VITE_API_URL |
API URL for Detection Frontend App (default: http://localhost:5000) |
SIMULATOR_PORT |
Simulator API Backend port (default: 5001) |
VITE_SIMULATOR_API_URL |
API URL for Simulator Frontend UI (default: http://localhost:5001) |
CORS_ORIGIN |
Allowed origins, comma-separated (default: http://localhost:3000,http://localhost:3001) |
npm run setup:db- Admin:
admin@botguard.local/Admin@123 - Sample User:
ahmed_1@botguard.pk/Password123
Option A: Detection platform only (Server 5000 + App 3000)
npm run devOption B: Full Lab (Recommended) Open 4 separate terminals to run all interconnected services:
| Service | Command | URL |
|---|---|---|
| Detection API | cd bot-detection-platform/server && npm run dev |
http://localhost:5000 |
| Detection App | cd bot-detection-platform/client && npm run dev |
http://localhost:3000 |
| Simulator API | cd bot-traffic-simulator/server && npm run dev |
http://localhost:5001 |
| Simulator UI | cd bot-traffic-simulator/client && npm run dev |
http://localhost:3001 |
botguard-lab/
βββ bot-detection-platform/ # Main detection platform
β βββ client/ # Vite + React SPA (marketing + dashboard)
β βββ server/ # Express API + Socket.io
βββ bot-traffic-simulator/ # Bot / human traffic & attack simulator
β βββ client/ # Simulator UI (Vite)
β βββ server/ # Traffic generation API
βββ LICENSE # MIT License
βββ README.md # You are here
Client Architecture (Detection Platform)
bot-detection-platform/client/src/
βββ main.jsx # Entry (ReactDOM)
βββ App.jsx # Providers + behavior tracking init
βββ index.css # Tailwind
βββ routes/ # AppRoutes, ProtectedRoute, GuestRoute
βββ pages/ # Home, Dashboard, Replay, Login, β¦
βββ components/
β βββ layout/ # Navbar, Footer, NotificationBell
β βββ notifications/ # NotificationItem, NotificationList
β βββ ui/ # Button, Card, Loader, β¦
βββ context/ # AuthContext, NotificationContext
βββ hooks/ # useAuth, useNotifications, useDashboard
βββ services/ # api, authService, notificationService
βββ utils/ # BehaviorTracker, DetectionClient, replay helpers
| Layer | Technologies |
|---|---|
| Frontend | React 18, React Router 6, Vite 5, Tailwind CSS 4, Axios, Socket.io client |
| Backend | Express, Node.js (ES modules) |
| Database | MongoDB, Mongoose |
| Auth | JWT (botguard_token in localStorage), bcryptjs |
| Real-time | Socket.io (/dashboard namespace) |
| Quality | ESLint, Prettier, Jest |
- SPA & Website: Built with React Router and responsive Tailwind layout.
- Auth & Security: JWT-based protection with guest/auth guards, rate limiting, and bcrypt hashing.
- Behavior Tracking: Mouse, scroll, click, typing, navigation, session duration, idle metrics.
- Detection Engine: Risk score 0β100 mapping to
HUMAN(0-29),SUSPICIOUS(30-59), andBOT(60-100). - Admin Dashboard: Real-time analytics, widget dashboards, session replay viewers with interactive canvas playback.
- Real-time Eventing: Socket.io-driven detection alerts and UI optimisations.
- Multi-modal Traffic: Simulate single-session attacks, benign human traffic, or concurrent bot assaults.
- Simulated Attacks:
- Login Attack β Repeated failed logins.
- Spam Bot β Form submission floods.
- Scraper Bot β Rapid cross-page crawling.
- Interactive Console: View status, classification, blocked states, and risk scores in real time.
View Schema Definitions
Below is an overview of the core MongoDB schemas used by the bot detection engine.
name(String, required)email(String, required, unique)password(String, required, min 6 chars)role(String, enum: user/admin, default: user)
userId(ObjectId, ref: User)sessionToken(String, unique, required)status(String, active/completed/abandoned/blocked)startTime/endTime/durationipAddress,userAgent,pageUrl,referer- Behavior tracking:
eventCount,mouseEvents,scrollEvents,clickEvents,keyEvents,navigationEvents,idleTime,maxIdlePeriod - Scores:
riskScore(0-100),classification(HUMAN/SUSPICIOUS/BOT) - Metadata flags:
hasFastNavigation,hasNoMouseMovement,hasNoScroll, etc.
sessionId(ObjectId, ref: Session, required)userId(ObjectId, ref: User)eventType(String, enum: mousemove, scroll, click, keydown, navigation, form_submit, login_attempt)x,y,scrollX,scrollY,targetElement,keyCodetimestamp(Date)metadata(userAgent, ipAddress, referer)
userId(ObjectId, ref: User)type(String, enum: bot-detected, session-ended, high-risk, anomaly, system)severity(String, enum: info, warning, critical)title,message(String)data(contains sessionId, riskScore, classification, etc.)
email,ipAddress(String)success(Boolean)userAgent(String)
npm run lint # ESLint (all workspaces)
npm run lint:fix # Fix linting issues
npm run format # Prettier write
npm run format:check # Check formatting
npm test # Jest (all packages)
npm run test:coverage # Test coverage report
npm run build # Production client builds
npm run dev # Detection server + client
npm run setup # Install dependencies + Seed
npm run setup:db # Seed onlyPre-Commit Checklist: Ensure you run npm run lint, npm test, and npm run build prior to committing.
| Service | URL | Notes |
|---|---|---|
| Main Site | http://localhost:3000 |
Public marketing pages |
| Login/Register | http://localhost:3000/login |
Redirects to dashboard when already signed in |
| Admin Dashboard | http://localhost:3000/dashboard |
Requires JWT (admin recommended for full API data) |
| Session Replay | http://localhost:3000/replay/:sessionId |
Protected route |
| Simulator | http://localhost:3001 |
Traffic + Simulated attacks |
Note: Visiting
/with a valid token auto-redirects to/dashboard. Unauthorized access to protected routes redirects to/login.
This project is licensed under the MIT License.