# abhiveeramallu/threatlensai architecture

> Architecture diagram of the GitHub repository abhiveeramallu/threatlensai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhiveeramallu/threatlensai
- Repository: https://github.com/abhiveeramallu/threatlensai

## Overview

ThreatLens AI collects browser interaction and fingerprint telemetry during login, scores each attempt with an explainable rule engine and optionally a separately served ML model, then applies adaptive verification and produces an analyst report. Results feed the session store and security dashboard. The repository also includes a bot-simulation and ML training workflow. Some subsystem links are based on README descriptions because their implementation was not sampled; those limits are reflected in the evidence citations.

Main entry points: [`server/app.js`](https://github.com/abhiveeramallu/threatlensai/blob/master/server/app.js) (Application API), [`ml/generate_dataset.py`](https://github.com/abhiveeramallu/threatlensai/blob/master/ml/generate_dataset.py) (Dataset Generation), [`server/geminiThreatAnalyst.js`](https://github.com/abhiveeramallu/threatlensai/blob/master/server/geminiThreatAnalyst.js) (Threat Report), [`ml/serve.py`](https://github.com/abhiveeramallu/threatlensai/blob/master/ml/serve.py) (ML Scoring Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["Login and Simulation"]
  node_login_ui["Login UI<br/>[app.js]"]
  node_bot_tools["Bot Simulators"]
end

subgraph group_detection["Detection and Response"]
  node_api["Application API<br/>[app.js]"]
  node_rules["Rule Scorer<br/>[aiScoring.js]"]
  node_response["Adaptive Response<br/>[app.js]"]
  node_ml_client["ML Scoring Client<br/>[mlScoring.js]"]
end

subgraph group_analysis["Threat Intelligence"]
  node_reporter["Threat Report"]
  node_prompt_versions["Versioned Prompts<br/>[v1.js]"]
end

subgraph group_operations["Dashboard and Storage"]
  node_dashboard_ui["Admin Dashboard<br/>[admin.js]"]
  node_session_store[("Session Store<br/>[storage.js]")]
end

subgraph group_learning["ML Lifecycle"]
  node_ml_service["ML Scoring Service<br/>[serve.py]"]
  node_feature_engineering["Feature Extraction<br/>[features.py]"]
  node_dataset_generation["Dataset Generation"]
  node_model_training["Model Training<br/>[train.py]"]
  node_model_files["Trained Models"]
end

node_visitor(("Login User"))
node_gemini{{"Gemini API"}}
node_postgres[("PostgreSQL")]

node_visitor -->|"uses"| node_login_ui
node_login_ui -->|"submits login"| node_api
node_bot_tools -->|"simulates logins"| node_api
node_api -->|"scores attempt"| node_rules
node_api -->|"requests ML score"| node_ml_client
node_ml_client -->|"calls scoring service"| node_ml_service
node_ml_service -->|"extracts features"| node_feature_engineering
node_ml_service -->|"loads models"| node_model_files
node_api -->|"chooses action"| node_response
node_api -->|"generates report"| node_reporter
node_reporter -->|"uses prompt"| node_prompt_versions
node_reporter -.->|"requests analysis"| node_gemini
node_api -->|"persists sessions"| node_session_store
node_dashboard_ui -->|"requests dashboard data"| node_api
node_api -->|"reads dashboard data"| node_session_store
node_session_store -->|"stores records"| node_postgres
node_dataset_generation -->|"runs bot sessions"| node_bot_tools
node_dataset_generation -->|"posts sessions"| node_api
node_dataset_generation -->|"extracts training features"| node_feature_engineering
node_model_training -->|"uses feature schema"| node_feature_engineering
node_model_training -->|"writes models"| node_model_files

click node_login_ui "https://github.com/abhiveeramallu/threatlensai/blob/master/public/app.js"
click node_bot_tools "https://github.com/abhiveeramallu/threatlensai/tree/master/bots"
click node_api "https://github.com/abhiveeramallu/threatlensai/blob/master/server/app.js"
click node_rules "https://github.com/abhiveeramallu/threatlensai/blob/master/server/aiScoring.js"
click node_response "https://github.com/abhiveeramallu/threatlensai/blob/master/server/app.js"
click node_ml_client "https://github.com/abhiveeramallu/threatlensai/blob/master/server/mlScoring.js"
click node_ml_service "https://github.com/abhiveeramallu/threatlensai/blob/master/ml/serve.py"
click node_feature_engineering "https://github.com/abhiveeramallu/threatlensai/blob/master/ml/features.py"
click node_dataset_generation "https://github.com/abhiveeramallu/threatlensai/blob/master/ml/generate_dataset.py"
click node_model_training "https://github.com/abhiveeramallu/threatlensai/blob/master/ml/train.py"
click node_model_files "https://github.com/abhiveeramallu/threatlensai/tree/master/ml/models"
click node_reporter "https://github.com/abhiveeramallu/threatlensai/blob/master/server/geminiThreatAnalyst.js"
click node_prompt_versions "https://github.com/abhiveeramallu/threatlensai/blob/master/server/prompts/v1.js"
click node_dashboard_ui "https://github.com/abhiveeramallu/threatlensai/blob/master/public/admin.js"
click node_session_store "https://github.com/abhiveeramallu/threatlensai/blob/master/server/storage.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_login_ui,node_bot_tools,node_visitor toneBlue
class node_api,node_rules,node_response,node_ml_client,node_postgres toneAmber
class node_reporter,node_prompt_versions,node_gemini toneMint
class node_dashboard_ui,node_session_store toneRose
class node_ml_service,node_feature_engineering,node_dataset_generation,node_model_training,node_model_files toneIndigo
```

## Components

### Login and Simulation

- [Login UI](https://github.com/abhiveeramallu/threatlensai/blob/master/public/app.js): `public/app.js`
- [Bot Simulators](https://github.com/abhiveeramallu/threatlensai/tree/master/bots): `bots`

### Detection and Response

- [Application API](https://github.com/abhiveeramallu/threatlensai/blob/master/server/app.js): `server/app.js`
- [Rule Scorer](https://github.com/abhiveeramallu/threatlensai/blob/master/server/aiScoring.js): `server/aiScoring.js`
- [Adaptive Response](https://github.com/abhiveeramallu/threatlensai/blob/master/server/app.js): `server/app.js`
- [ML Scoring Client](https://github.com/abhiveeramallu/threatlensai/blob/master/server/mlScoring.js): `server/mlScoring.js`

### Threat Intelligence

- [Threat Report](https://github.com/abhiveeramallu/threatlensai/blob/master/server/geminiThreatAnalyst.js): `server/geminiThreatAnalyst.js`
- [Versioned Prompts](https://github.com/abhiveeramallu/threatlensai/blob/master/server/prompts/v1.js): `server/prompts/v1.js`

### Dashboard and Storage

- [Admin Dashboard](https://github.com/abhiveeramallu/threatlensai/blob/master/public/admin.js): `public/admin.js`
- [Session Store](https://github.com/abhiveeramallu/threatlensai/blob/master/server/storage.js): `server/storage.js`

### ML Lifecycle

- [ML Scoring Service](https://github.com/abhiveeramallu/threatlensai/blob/master/ml/serve.py): `ml/serve.py`
- [Feature Extraction](https://github.com/abhiveeramallu/threatlensai/blob/master/ml/features.py): `ml/features.py`
- [Dataset Generation](https://github.com/abhiveeramallu/threatlensai/blob/master/ml/generate_dataset.py): `ml/generate_dataset.py`
- [Model Training](https://github.com/abhiveeramallu/threatlensai/blob/master/ml/train.py): `ml/train.py`
- [Trained Models](https://github.com/abhiveeramallu/threatlensai/tree/master/ml/models): `ml/models`

### Other components

- **Login User**
- **Gemini API**
- **PostgreSQL**

## Connections

- Login User → Login UI: uses (evidence: `README.md`)
- Login UI → Application API: submits login (evidence: `README.md`)
- Bot Simulators → Application API: simulates logins (evidence: `README.md`)
- Application API → Rule Scorer: scores attempt (evidence: `server/app.js`)
- Application API → ML Scoring Client: requests ML score (evidence: `server/app.js`)
- ML Scoring Client → ML Scoring Service: calls scoring service (evidence: `README.md`)
- ML Scoring Service → Feature Extraction: extracts features (evidence: `ml/features.py`)
- ML Scoring Service → Trained Models: loads models (evidence: `README.md`)
- Application API → Adaptive Response: chooses action (evidence: `server/app.js`)
- Application API → Threat Report: generates report (evidence: `server/app.js`)
- Threat Report → Versioned Prompts: uses prompt (evidence: `server/geminiThreatAnalyst.js`)
- Threat Report → Gemini API: requests analysis (evidence: `server/geminiThreatAnalyst.js`)
- Application API → Session Store: persists sessions (evidence: `server/app.js`)
- Admin Dashboard → Application API: requests dashboard data (evidence: `README.md`)
- Application API → Session Store: reads dashboard data (evidence: `server/app.js`)
- Session Store → PostgreSQL: stores records (evidence: `server/storage.js`)
- Dataset Generation → Bot Simulators: runs bot sessions (evidence: `ml/generate_dataset.py`)
- Dataset Generation → Application API: posts sessions (evidence: `ml/generate_dataset.py`)
- Dataset Generation → Feature Extraction: extracts training features (evidence: `ml/generate_dataset.py`)
- Model Training → Feature Extraction: uses feature schema (evidence: `ml/train.py`)
- Model Training → Trained Models: writes models (evidence: `README.md`)
