-
Notifications
You must be signed in to change notification settings - Fork 0
Architecture
DHANUSH G edited this page Mar 4, 2026
·
1 revision
Back to Home | Setup-Guide | API-Reference
The platform follows a 3-tier architecture with a clear separation between the AI/data layer, the API layer, and the presentation layer.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PRESENTATION LAYER β
β Next.js 14 Dashboard (localhost:3000) β
β βββ Recharts (2D graphs: traffic, anomalies) β
β βββ 3D Threat Globe (React Three Fiber) β
β βββ 3D Network Topology (nodes & edges) β
βββββββββββββββββββββββββββ²ββββββββββββββββββββββββββ
β REST API (JSON)
βββββββββββββββββββββββββββΌββββββββββββββββββββββββββ
β API LAYER β
β FastAPI Backend (localhost:8000) β
β βββ GET / β Health Check β
β βββ POST /logs/ β Log Ingestion β
β βββ GET /logs/ β Log Retrieval + Pagination β
β βββ POST /predict/ β AI Anomaly Score β
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββ
β
βββββββββββΌββββββββββ
βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ
β DATA LAYER β β AI LAYER β
β SQLite (via ORM) β β Isolation Forest β
β SQLAlchemy modelsβ β (.pkl model file) β
β Log records β β Scikit-learn β
βββββββββββββββββββ βββββββββββββββββββ
Client/Agent
β
β POST /logs/ {source_ip, dest_ip, protocol, bytes, event_type, details}
βΌ
FastAPI Router
β
βββ Pydantic Schema Validation
β
βββ SQLAlchemy β SQLite (persist raw log)
β
βββ Return saved log record (JSON)
Client
β
β POST /predict/ {feature vector}
βΌ
FastAPI Router
β
βββ Load Isolation Forest model (.pkl)
β
βββ Feature extraction (NumPy/Pandas)
β
βββ model.predict() β anomaly score
β
βββ Classify: Normal / Suspicious / Critical
β
βββ Return {score, label, confidence}
| Property | Benefit |
|---|---|
| Unsupervised | No labeled attack data needed |
| Handles high-dimensional data | Works with IPs, ports, bytes, timing |
| Scales well | Faster than LOF for large log volumes |
| Zero-day friendly | Detects unknown/novel attack patterns |
| Low false-positive rate | Tuned contamination parameter |
-
Training:
train_model.pygenerates synthetic logs (generated_logs.csv) simulating both normal and anomalous traffic patterns - Feature Engineering: Numeric features (bytes transferred, port numbers, protocol encoding) are extracted
-
Model Fitting:
IsolationForest(contamination=0.05)is trained on the dataset -
Serialization: Model saved to
ai-model/isolation_forest_model.pklvia joblib -
Inference: On each
/predict/call, the model scores the input and returns a classification
| Score Range | Classification | Action |
|---|---|---|
| score > -0.1 | Normal | Log and continue |
| -0.3 < score β€ -0.1 | Suspicious | Flag for review |
| score β€ -0.3 | Critical | Immediate alert |
CREATE TABLE logs (
id INTEGER PRIMARY KEY AUTOINCREMENT,
source_ip VARCHAR NOT NULL,
destination_ip VARCHAR NOT NULL,
protocol VARCHAR NOT NULL,
bytes_transferred INTEGER NOT NULL,
event_type VARCHAR NOT NULL, -- 'normal' | 'suspicious' | 'critical'
details TEXT,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
);SQLite is used for local development. For production, replace the DATABASE_URL with a PostgreSQL connection string β SQLAlchemy handles the transition seamlessly.
| Component | Technology | Purpose |
|---|---|---|
| Traffic Charts | Recharts (LineChart, BarChart) | Visualize log volume and traffic over time |
| Threat Pie Chart | Recharts (PieChart) | Distribution of Normal / Suspicious / Critical |
| 3D Threat Globe | React Three Fiber + drei | Global geographic threat origin map |
| Network Topology | React Three Fiber | Real-time node-edge graph of connections |
| Log Table | Next.js + Tailwind | Paginated, searchable raw log viewer |
| Alert Banner | Lucide + Tailwind | Live critical event notifications |
# .github/workflows/ci.yml
Trigger: push / pull_request to main
Steps:
1. Checkout code
2. Set up Python 3.10
3. Install backend dependencies (pip install -r requirements.txt)
4. Set PYTHONPATH=. (for backend module resolution)
5. Run pytest (backend/tests/)
6. Report test results-
WebSockets: Replace REST polling with
ws://streams for real-time push alerts - Celery + Redis: Async task queue for background model retraining
- Kafka / RabbitMQ: Message broker for high-throughput log ingestion
- Docker Compose: Orchestrate backend, frontend, and DB as containers
- Autoencoder Model: Deep learning replacement for Isolation Forest for richer embeddings
- PostgreSQL: Production-grade database with full-text search
Back to Home | Next: Setup-Guide