# kiran797979/cyber-res architecture

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

- Interactive diagram: https://gitdiagram.com/kiran797979/cyber-res
- Repository: https://github.com/kiran797979/cyber-res

## Overview

#### Purpose and entry points
Cyber Resilience Platform is a browser-based SOC workbench that turns security events into live monitoring, attack correlation, response guidance, CVE priority, and executive resilience posture. The backend starts at `backend/main.py` as a FastAPI API/WebSocket service; the dashboard starts at `frontend/src/main.jsx` and is orchestrated by `frontend/src/App.jsx`. Container deployment is defined in `Dockerfile`.

#### API orchestration and contracts
`backend/main.py` owns REST endpoints under `/api/*`, CORS, rate limiting for AI routes, initial demo data setup, and the `/ws/logs` live stream. Pydantic response/request contracts centralize backend boundaries in `backend/models.py`. The frontend uses a single HTTP/WebSocket boundary in `frontend/src/api/client.js`, keeping panels decoupled from transport details.

#### Event ingestion, state, and live delivery
Demo SIEM events are produced by `backend/log_generator.py`; current events drive logs, stats, map origins, mappings, incidents, scoring, and analysis. `backend/live_stream.py` broadcasts newly generated events to connected WebSocket clients. `frontend/src/App.jsx` combines initial REST hydration with pushed updates, while `frontend/src/components/LogTable.jsx` and `frontend/src/components/StatsCharts.jsx` render the operational event view.

#### Resilience and campaign correlation
`backend/resilience.py` is the primary decision layer: it computes the explainable 0–100 resilience score from incident load, containment, reporting exposure, and attack surface; it also correlates events into ordered kill-chain campaigns. Results feed executive and analyst-facing panels in `frontend/src/components/ResiliencePanel.jsx` and `frontend/src/components/ThreatSummary.jsx`.

#### Security enrichment and response workflow
Event classification is enriched through MITRE mapping, IP intelligence, incident derivation, and CVE risk ranking:
- `backend/attack_mapper.py` maps event types to ATT&CK techniques, optionally loading a local STIX bundle.
- `backend/ip_intel.py` resolves attacker geo/reputation for map origins and per-IP details.
- `backend/incident_responder.py` creates incidents, playbook progression, CERT-In reporting context, and tamper-evident audit records.
- `backend/cve_prioritiser.py` ranks curated or NVD-sourced CVEs using exploitability, KEV, and India-sector relevance.
UI boundaries are `frontend/src/components/AttackPanel.jsx`, `frontend/src/components/IncidentTimeline.jsx`, `frontend/src/components/CveQueue.jsx`, and `frontend/src/components/WorldMap.jsx`.

#### AI and ML analysis paths
`backend/openrouter_analyzer.py` provides threat narratives and prioritization. It calls OpenRouter when configured, otherwise uses deterministic rules; rate limiting and fallback preserve dashboard availability. `backend/nsl_model.py` serves intrusion detections from CSV replay by default or an optional trained model artifact. Training is offline in `model/train_and_validate.py`, using NSL-KDD data and writing `backend/intrusion_model.pkl`; `frontend/src/components/IntrusionPanel.jsx` renders detections and accuracy.

#### Runtimes, deployment, and external boundaries
Runtime stack is Python 3.11+/FastAPI and Node 18+/React 18/Vite. The backend is independently deployable in Docker (`Dockerfile`); the Vite frontend builds to static assets. Optional external services are OpenRouter, NVD 2.0, AbuseIPDB, GreyNoise, IPinfo, ip-api.com, MITRE ATT&CK STIX, and Leaflet/OpenStreetMap. Environment-controlled integration boundaries are documented by `backend/.env.example` and `frontend/.env.example`; all core flows retain offline/demo fallbacks.

Main entry points: [`backend/main.py`](https://github.com/kiran797979/cyber-res/blob/master/backend/main.py) (FastAPI API + WebSocket), [`frontend/src/App.jsx`](https://github.com/kiran797979/cyber-res/blob/master/frontend/src/App.jsx) (Dashboard orchestration), [`frontend/src/api/client.js`](https://github.com/kiran797979/cyber-res/blob/master/frontend/src/api/client.js) (HTTP + WebSocket client), [`backend/log_generator.py`](https://github.com/kiran797979/cyber-res/blob/master/backend/log_generator.py) (Demo SIEM events)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["FastAPI backend"]
  node_api["FastAPI API + WebSocket<br/>[main.py]"]
  node_contracts["API contracts<br/>Pydantic models<br/>[models.py]"]
  node_event_generator["Demo SIEM events<br/>event source<br/>[log_generator.py]"]
  node_live_stream["Live event broadcaster<br/>WebSocket delivery<br/>[live_stream.py]"]
  node_resilience["Resilience + campaign engine<br/>decision layer<br/>[resilience.py]"]
  node_attack_mapper["MITRE mapper<br/>enrichment<br/>[attack_mapper.py]"]
  node_ip_intel["IP intelligence<br/>enrichment<br/>[ip_intel.py]"]
  node_incident["Incident response<br/>workflow"]
  node_cve["CVE prioritiser<br/>risk ranking<br/>[cve_prioritiser.py]"]
  node_ai["Threat narrative analyzer<br/>AI analysis"]
  node_intrusion["Intrusion detector<br/>ML inference<br/>[nsl_model.py]"]
  node_training["Offline model training<br/>ML pipeline"]
end

subgraph group_frontend["React dashboard"]
  node_app["Dashboard orchestration<br/>React application<br/>[App.jsx]"]
  node_client["HTTP + WebSocket client<br/>transport boundary<br/>[client.js]"]
  node_ops_view["Operational event view<br/>dashboard panels<br/>[LogTable.jsx]"]
  node_resilience_view["Resilience + threat view<br/>dashboard panels"]
  node_response_view["Enrichment + response views<br/>dashboard panels<br/>[AttackPanel.jsx]"]
  node_intrusion_view["Intrusion panel<br/>dashboard panel<br/>[IntrusionPanel.jsx]"]
end

subgraph group_external["Optional integrations"]
  node_openrouter(("OpenRouter<br/>external AI API"))
  node_security_feeds(("Security intelligence feeds<br/>external APIs"))
  node_map_tiles(("OpenStreetMap tiles<br/>map service"))
end

node_docker{{"Docker deployment<br/>container build"}}

node_docker -->|"deploys"| node_api
node_api -->|"validates"| node_contracts
node_event_generator -->|"current events"| node_api
node_event_generator -->|"new events"| node_live_stream
node_live_stream -->|"/ws/logs"| node_client
node_client -->|"/api/*"| node_api
node_client -->|"data + updates"| node_app
node_app -->|"renders"| node_ops_view
node_app -->|"renders"| node_resilience_view
node_app -->|"renders"| node_response_view
node_app -->|"renders"| node_intrusion_view
node_api -->|"scores and correlates events"| node_resilience
node_api -->|"enriches events"| node_attack_mapper
node_api -->|"enriches origins"| node_ip_intel
node_api -->|"derives incidents"| node_incident
node_api -->|"prioritizes CVEs"| node_cve
node_api -->|"requests analysis"| node_ai
node_api -->|"serves detections"| node_intrusion
node_training -.->|"produces optional model"| node_intrusion
node_ai -.->|"when configured"| node_openrouter
node_attack_mapper -.->|"optional STIX"| node_security_feeds
node_ip_intel -.->|"optional reputation + geo"| node_security_feeds
node_cve -.->|"optional NVD"| node_security_feeds
node_response_view -.->|"map tiles"| node_map_tiles

click node_docker "https://github.com/kiran797979/cyber-res/blob/master/Dockerfile"
click node_api "https://github.com/kiran797979/cyber-res/blob/master/backend/main.py"
click node_contracts "https://github.com/kiran797979/cyber-res/blob/master/backend/models.py"
click node_event_generator "https://github.com/kiran797979/cyber-res/blob/master/backend/log_generator.py"
click node_live_stream "https://github.com/kiran797979/cyber-res/blob/master/backend/live_stream.py"
click node_resilience "https://github.com/kiran797979/cyber-res/blob/master/backend/resilience.py"
click node_attack_mapper "https://github.com/kiran797979/cyber-res/blob/master/backend/attack_mapper.py"
click node_ip_intel "https://github.com/kiran797979/cyber-res/blob/master/backend/ip_intel.py"
click node_incident "https://github.com/kiran797979/cyber-res/blob/master/backend/incident_responder.py"
click node_cve "https://github.com/kiran797979/cyber-res/blob/master/backend/cve_prioritiser.py"
click node_ai "https://github.com/kiran797979/cyber-res/blob/master/backend/openrouter_analyzer.py"
click node_intrusion "https://github.com/kiran797979/cyber-res/blob/master/backend/nsl_model.py"
click node_training "https://github.com/kiran797979/cyber-res/blob/master/model/train_and_validate.py"
click node_app "https://github.com/kiran797979/cyber-res/blob/master/frontend/src/App.jsx"
click node_client "https://github.com/kiran797979/cyber-res/blob/master/frontend/src/api/client.js"
click node_ops_view "https://github.com/kiran797979/cyber-res/blob/master/frontend/src/components/LogTable.jsx"
click node_resilience_view "https://github.com/kiran797979/cyber-res/blob/master/frontend/src/components/ResiliencePanel.jsx"
click node_response_view "https://github.com/kiran797979/cyber-res/blob/master/frontend/src/components/AttackPanel.jsx"
click node_intrusion_view "https://github.com/kiran797979/cyber-res/blob/master/frontend/src/components/IntrusionPanel.jsx"

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_api,node_contracts,node_event_generator,node_live_stream,node_resilience,node_attack_mapper,node_ip_intel,node_incident,node_cve,node_ai,node_intrusion,node_training toneBlue
class node_app,node_client,node_ops_view,node_resilience_view,node_response_view,node_intrusion_view toneAmber
class node_openrouter,node_security_feeds,node_map_tiles toneMint
class node_docker toneNeutral
```

## Components

### FastAPI backend

API orchestration, enrichment, and decision services.

- [FastAPI API + WebSocket](https://github.com/kiran797979/cyber-res/blob/master/backend/main.py): service · Owns REST, live stream endpoint, demo setup, and AI rate limits. · `backend/main.py`
- [API contracts](https://github.com/kiran797979/cyber-res/blob/master/backend/models.py): Pydantic models · Central request and response boundary. · `backend/models.py`
- [Demo SIEM events](https://github.com/kiran797979/cyber-res/blob/master/backend/log_generator.py): event source · Produces current security events. · `backend/log_generator.py`
- [Live event broadcaster](https://github.com/kiran797979/cyber-res/blob/master/backend/live_stream.py): WebSocket delivery · Broadcasts newly generated events to connected clients. · `backend/live_stream.py`
- [Resilience + campaign engine](https://github.com/kiran797979/cyber-res/blob/master/backend/resilience.py): decision layer · Scores posture and correlates ordered kill-chain campaigns. · `backend/resilience.py`
- [MITRE mapper](https://github.com/kiran797979/cyber-res/blob/master/backend/attack_mapper.py): enrichment · Maps event types to ATT&CK techniques. · `backend/attack_mapper.py`
- [IP intelligence](https://github.com/kiran797979/cyber-res/blob/master/backend/ip_intel.py): enrichment · Resolves attacker geography and reputation. · `backend/ip_intel.py`
- [Incident response](https://github.com/kiran797979/cyber-res/blob/master/backend/incident_responder.py): workflow · Derives incidents, playbooks, reporting context, and audit records. · `backend/incident_responder.py`
- [CVE prioritiser](https://github.com/kiran797979/cyber-res/blob/master/backend/cve_prioritiser.py): risk ranking · Ranks CVEs by exploitability, KEV, and sector relevance. · `backend/cve_prioritiser.py`
- [Threat narrative analyzer](https://github.com/kiran797979/cyber-res/blob/master/backend/openrouter_analyzer.py): AI analysis · Uses OpenRouter or deterministic fallback rules. · `backend/openrouter_analyzer.py`
- [Intrusion detector](https://github.com/kiran797979/cyber-res/blob/master/backend/nsl_model.py): ML inference · Uses CSV replay or an optional trained model. · `backend/nsl_model.py`
- [Offline model training](https://github.com/kiran797979/cyber-res/blob/master/model/train_and_validate.py): ML pipeline · Trains the optional intrusion model. · `model/train_and_validate.py`

### React dashboard

Browser workbench and decoupled API client.

- [Dashboard orchestration](https://github.com/kiran797979/cyber-res/blob/master/frontend/src/App.jsx): React application · Hydrates via REST and merges pushed event updates. · `frontend/src/App.jsx`
- [HTTP + WebSocket client](https://github.com/kiran797979/cyber-res/blob/master/frontend/src/api/client.js): transport boundary · Keeps dashboard panels decoupled from transport. · `frontend/src/api/client.js`
- [Operational event view](https://github.com/kiran797979/cyber-res/blob/master/frontend/src/components/LogTable.jsx): dashboard panels · Logs and statistics charts. · `frontend/src/components/LogTable.jsx`
- [Resilience + threat view](https://github.com/kiran797979/cyber-res/blob/master/frontend/src/components/ResiliencePanel.jsx): dashboard panels · Executive posture and campaign summaries. · `frontend/src/components/ResiliencePanel.jsx`
- [Enrichment + response views](https://github.com/kiran797979/cyber-res/blob/master/frontend/src/components/AttackPanel.jsx): dashboard panels · Attack, incident, CVE, and world-map interfaces. · `frontend/src/components/AttackPanel.jsx`
- [Intrusion panel](https://github.com/kiran797979/cyber-res/blob/master/frontend/src/components/IntrusionPanel.jsx): dashboard panel · Shows detections and accuracy. · `frontend/src/components/IntrusionPanel.jsx`

### Optional integrations

Environment-configured services with offline fallbacks.

- **OpenRouter**: external AI API
- **Security intelligence feeds**: external APIs · NVD, IP reputation, geo, and MITRE STIX sources.
- **OpenStreetMap tiles**: map service · Leaflet map data source.

### Other components

- [Docker deployment](https://github.com/kiran797979/cyber-res/blob/master/Dockerfile): container build · Independently deploys the backend. · `Dockerfile`

## Connections

- Docker deployment → FastAPI API + WebSocket: deploys
- FastAPI API + WebSocket → API contracts: validates
- Demo SIEM events → FastAPI API + WebSocket: current events
- Demo SIEM events → Live event broadcaster: new events
- Live event broadcaster → HTTP + WebSocket client: /ws/logs
- HTTP + WebSocket client → FastAPI API + WebSocket: /api/*
- HTTP + WebSocket client → Dashboard orchestration: data + updates
- Dashboard orchestration → Operational event view: renders
- Dashboard orchestration → Resilience + threat view: renders
- Dashboard orchestration → Enrichment + response views: renders
- Dashboard orchestration → Intrusion panel: renders
- FastAPI API + WebSocket → Resilience + campaign engine: scores and correlates events
- FastAPI API + WebSocket → MITRE mapper: enriches events
- FastAPI API + WebSocket → IP intelligence: enriches origins
- FastAPI API + WebSocket → Incident response: derives incidents
- FastAPI API + WebSocket → CVE prioritiser: prioritizes CVEs
- FastAPI API + WebSocket → Threat narrative analyzer: requests analysis
- FastAPI API + WebSocket → Intrusion detector: serves detections
- Offline model training → Intrusion detector: produces optional model
- Threat narrative analyzer → OpenRouter: when configured
- MITRE mapper → Security intelligence feeds: optional STIX
- IP intelligence → Security intelligence feeds: optional reputation + geo
- CVE prioritiser → Security intelligence feeds: optional NVD
- Enrichment + response views → OpenStreetMap tiles: map tiles
