backend-optimization

# πŸ›‘οΈ Detect Backend Threat ### Production-Grade Cyber Intelligence & Infrastructure Defense Platform [![Next.js](https://img.shields.io/badge/Next.js-14-black?style=for-the-badge&logo=next.js)](https://nextjs.org/) [![TypeScript](https://img.shields.io/badge/TypeScript-5.6-blue?style=for-the-badge&logo=typescript)](https://www.typescriptlang.org/) [![Docker](https://img.shields.io/badge/Docker-Compose-2496ED?style=for-the-badge&logo=docker)](https://www.docker.com/) [![PostgreSQL](https://img.shields.io/badge/PostgreSQL-16-336791?style=for-the-badge&logo=postgresql)](https://www.postgresql.org/) [![Redis](https://img.shields.io/badge/Redis-7-DC382D?style=for-the-badge&logo=redis)](https://redis.io/) > **Cyberpunk-themed real-time threat detection platform** with a live attack globe, threat scanner, infrastructure heatmap, and SOC incident center β€” fully containerized and production-ready.

image image image

✨ Features

# Feature Description
🌐 Live Attack Globe Three.js WebGL globe with real-time animated attack arcs β€” DDoS (red), Malware (amber), Brute-Force (cyan)
πŸ” Threat Scanner Scan files with ClamAV, URLs with URLScan.io, hashes with VirusTotal β€” D3.js radar chart analysis
πŸ—ΊοΈ Infrastructure Heatmap D3.js force-directed graph of your servers/APIs/DBs colored by live risk score
πŸ“‘ Live Threat Feed Terminal-style real-time event stream via Redis pub/sub + Socket.io with sound alerts
🚫 API Abuse Detector Auto-detects API floods & brute-force attacks, blocks IPs, AbuseIPDB lookup + D3 charts
⚠️ Incident Command Center SOC-style incident queue with Gemini AI summaries and DETECTED β†’ RESOLVED workflow

πŸ–₯️ Tech Stack

Layer Technology
Frontend Next.js 14 (App Router) + TailwindCSS + Framer Motion
3D / Charts Three.js (WebGL globe) + D3.js (force graph, radar, timeline)
Backend Node.js + Express + TypeScript
Database PostgreSQL 16 via Prisma ORM
Cache + Realtime Redis pub/sub β†’ Socket.io WebSockets
File Scanning ClamAV (Dockerized)
Threat Intel VirusTotal API v3 + AbuseIPDB + URLScan.io
AI Google Gemini (incident summarization)
Observability Prometheus metrics + Grafana dashboards
Containers Docker Compose (8 services)

πŸ“‹ Prerequisites

Before you start, make sure you have these installed on your machine:

πŸ”‘ API Keys You Need

Service Where to Get It Free Limit Used For
VirusTotal virustotal.com/gui/my-apikey 500 req/day Hash & URL malware lookup
AbuseIPDB abuseipdb.com/register β†’ API 1,000 req/day IP reputation scoring
URLScan.io urlscan.io/user/signup β†’ API Keys 100 scans/day URL screenshot + verdict
Google Gemini aistudio.google.com/apikey Free tier AI incident summaries

πŸš€ Quick Start β€” Step by Step

Step 1 β€” Clone the Repository

git clone https://github.com/vignesh2027/backend-optimization.git
cd backend-optimization

Step 2 β€” Set Up Your Environment File

Copy the example env file:

cp .env.example .env

Now open .env in any text editor and fill in your API keys:

# Open with nano (terminal)
nano .env

# Or open with VS Code
code .env

Your .env file should look like this:

# ── Database ──────────────────────────────────
POSTGRES_USER=dbt
POSTGRES_PASSWORD=dbtpass
POSTGRES_DB=detectthreat
DATABASE_URL=postgresql://dbt:dbtpass@localhost:5432/detectthreat

# ── Redis ─────────────────────────────────────
REDIS_PASSWORD=redispass
REDIS_URL=redis://:redispass@localhost:6379

# ── API Keys (paste yours here) ───────────────
VIRUSTOTAL_API_KEY=your_virustotal_key_here
ABUSEIPDB_API_KEY=your_abuseipdb_key_here
URLSCAN_API_KEY=your_urlscan_key_here
GEMINI_API_KEY=your_gemini_key_here

# ── App ───────────────────────────────────────
NEXT_PUBLIC_API_URL=http://localhost:4000
NEXT_PUBLIC_WS_URL=ws://localhost:4000
PORT=4000
NODE_ENV=production

⚠️ Never commit your .env file to GitHub. It’s already in .gitignore so you’re safe.


Step 3 β€” Start Everything with Docker

docker compose up -d

This single command starts 8 containers:

Container What It Does Port
dbt-frontend Next.js cyberpunk UI 3000
dbt-backend Express API + WebSocket 4000
dbt-postgres PostgreSQL database 5432
dbt-redis Redis pub/sub + cache 6379
dbt-clamav Antivirus file scanner 3310
dbt-prometheus Metrics collection 9090
dbt-grafana Metrics dashboards 3001

⏳ First run takes 5–10 minutes β€” Docker needs to download and build all images. Subsequent starts take under 30 seconds.


Step 4 β€” Wait for All Containers to Be Healthy

Check that everything is running:

docker compose ps

You should see all containers showing Up or Up (healthy):

NAME             STATUS
dbt-backend      Up
dbt-clamav       Up (healthy)
dbt-frontend     Up
dbt-grafana      Up
dbt-postgres     Up (healthy)
dbt-prometheus   Up
dbt-redis        Up (healthy)

⚠️ If the backend shows Restarting, wait 30 seconds and check again. It waits for PostgreSQL and Redis to be ready first.


Step 5 β€” Initialize the Database

Run this once to create all the database tables:

docker compose exec backend npx prisma db push

You should see:

βœ” Your database is now in sync with your Prisma schema.

Seed the Incident Command Center with 3 realistic demo incidents:

curl -X POST http://localhost:4000/api/incidents/seed

Step 7 β€” Open Your Platform πŸŽ‰

Service URL Login
πŸ›‘οΈ Main Platform http://localhost:3000 β€”
βš™οΈ Backend API http://localhost:4000 β€”
πŸ“Š Grafana Dashboards http://localhost:3001 admin / admin123
πŸ“ˆ Prometheus Metrics http://localhost:9090 β€”

πŸ—ΊοΈ Platform Pages

🌐 Attack Globe β€” http://localhost:3000

πŸ” Threat Scanner β€” http://localhost:3000/scanner

πŸ—ΊοΈ Infrastructure Heatmap β€” http://localhost:3000/infrastructure

πŸ“‘ Live Threat Feed β€” http://localhost:3000/feed

🚫 API Abuse Detector β€” http://localhost:3000/abuse

⚠️ Incident Command Center β€” http://localhost:3000/incidents


πŸ›‘ Stopping the Platform

# Stop all containers (keeps your data)
docker compose down

# Stop AND delete all data (fresh start)
docker compose down -v

πŸ”§ Troubleshooting

Backend keeps restarting

docker compose logs backend --tail=30

Usually means database tables aren’t created yet. Run:

docker compose exec backend npx prisma db push

Globe shows no attacks

The backend might not have finished starting. Check:

docker compose logs backend --tail=20

Look for: [Server] Running on port 4000

Port already in use error

Another app is using a port. Stop it or change the port in docker-compose.yml.

On Apple Silicon Mac (M1/M2) β€” ClamAV error

Already handled β€” ClamAV runs via Rosetta emulation (platform: linux/amd64).

Force a full clean rebuild

docker compose down -v
docker compose build --no-cache
docker compose up -d

πŸ“ Project Structure

detect-backend-threat/
β”œβ”€β”€ 🐳 docker-compose.yml          # All 8 services
β”œβ”€β”€ πŸ“‹ .env.example                # Copy this to .env
β”‚
β”œβ”€β”€ πŸ–₯️  frontend/                  # Next.js 14 App Router
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ page.tsx               # 🌐 Attack Globe
β”‚   β”‚   β”œβ”€β”€ scanner/page.tsx       # πŸ” Threat Scanner
β”‚   β”‚   β”œβ”€β”€ infrastructure/page.tsx # πŸ—ΊοΈ Infra Heatmap
β”‚   β”‚   β”œβ”€β”€ feed/page.tsx          # πŸ“‘ Live Feed
β”‚   β”‚   β”œβ”€β”€ abuse/page.tsx         # 🚫 Abuse Detector
β”‚   β”‚   └── incidents/page.tsx     # ⚠️ Incident Center
β”‚   └── components/
β”‚       β”œβ”€β”€ AttackGlobe.tsx        # Three.js WebGL globe
β”‚       β”œβ”€β”€ InfraGraph.tsx         # D3 force graph
β”‚       β”œβ”€β”€ ThreatRadar.tsx        # D3 radar chart
β”‚       └── Sidebar.tsx            # Navigation
β”‚
β”œβ”€β”€ βš™οΈ  backend/                   # Node.js + Express
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ index.ts               # Server entry + Prometheus
β”‚   β”‚   β”œβ”€β”€ routes/                # scan, incidents, abuse, infra
β”‚   β”‚   β”œβ”€β”€ services/              # virustotal, urlscan, abuseipdb, gemini, clamav
β”‚   β”‚   β”œβ”€β”€ middleware/            # requestLogger, ipBlock
β”‚   β”‚   └── websocket/             # Socket.io + Redis pub/sub
β”‚   └── prisma/schema.prisma       # DB schema
β”‚
β”œβ”€β”€ πŸ“Š prometheus/prometheus.yml   # Metrics scrape config
└── πŸ“ˆ grafana/provisioning/       # Auto-provisioned dashboards

πŸ”Œ API Endpoints

Method Endpoint Description
POST /api/scan/file ClamAV file scan (multipart)
POST /api/scan/url URLScan.io URL scan
POST /api/scan/hash VirusTotal hash lookup
GET /api/scan/history Recent scan results
GET /api/incidents All incidents (priority sorted)
POST /api/incidents Create new incident
PATCH /api/incidents/:id/status Update incident status
POST /api/incidents/:id/summarize Generate Gemini AI summary
POST /api/incidents/seed Load demo incidents
GET /api/abuse/stats Request rate stats + top IPs
POST /api/abuse/check-ip AbuseIPDB IP lookup
GET /api/abuse/blocked List blocked IPs
DELETE /api/abuse/blocked/:ip Unblock an IP
GET /api/infrastructure/topology Force graph node/link data
GET /metrics Prometheus metrics endpoint
GET /health Health check

🎨 Design System

The platform uses a cyberpunk dark theme:

Token Color Usage
Background #0a0a0f Page base
Panel #0d0d1a Glass panels
Neon Cyan #00f5ff Primary accent, borders
Neon Green #39ff14 Safe/clean/online
Threat Red #ff2d55 Critical threats, DDoS
Threat Amber #ff9500 Malware, warnings
Font JetBrains Mono All text

CSS effects: glassmorphism panels, CRT scanline animation, neon glow shadows, animated attack arcs.


🀝 Contributing

  1. Fork the repo
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Commit your changes: git commit -m 'feat: add your feature'
  4. Push to the branch: git push origin feature/your-feature
  5. Open a Pull Request

πŸ“„ License

MIT License β€” free to use, modify, and distribute.


**Built with ❀️ · Cyberpunk theme · Production ready** ⭐ Star this repo if you found it useful!