# ganesh4060/nids architecture

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

- Interactive diagram: https://gitdiagram.com/ganesh4060/nids
- Repository: https://github.com/ganesh4060/nids

## Overview

This Flask NIDS accepts a CSV, validates it, streams records through per-source-IP detection, and presents alerts, statistics, charts, and downloadable reports. The main analysis workflow is documented in the README and supported by the sampled controller, analysis, and processing code. Detection stages and key internal layers are shown separately; several page and chart relationships are documented but their full route/template implementation was not sampled.

Main entry points: [`backend/processing/stream_processor.py`](https://github.com/ganesh4060/nids/blob/master/backend/processing/stream_processor.py) (Record processing), [`backend/services/controller.py`](https://github.com/ganesh4060/nids/blob/master/backend/services/controller.py) (Application facade), [`app.py`](https://github.com/ganesh4060/nids/blob/master/app.py) (Flask routes), [`backend/services/analysis_service.py`](https://github.com/ganesh4060/nids/blob/master/backend/services/analysis_service.py) (Job analysis)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_flask["Flask routes<br/>[app.py]"]
  node_pages["NIDS pages"]
  node_controller["Application facade<br/>[controller.py]"]
end

subgraph group_ingest["Dataset intake"]
  node_upload["Uploaded CSV"]
  node_csvcheck["CSV validation<br/>[csv_service.py]"]
  node_rowvalidation["Row parsing<br/>[validators.py]"]
  node_source["CSV record source<br/>[traffic_source.py]"]
end

subgraph group_engine["Analysis engine"]
  node_record["Traffic record<br/>[traffic_record.py]"]
  node_parallel["IP-sharded workers"]
  node_stream["Record processing"]
  node_window["Sliding window<br/>[sliding_window.py]"]
  node_statistics["Window and totals"]
  node_rules["Attack rules<br/>[attack_detector.py]"]
  node_anomaly["Anomaly detection"]
  node_alertmanager["Alert management<br/>[alert_manager.py]"]
  node_alert["Alert model<br/>[alert.py]"]
  node_config["Detection settings<br/>[config.py]"]
end

subgraph group_presentation["Results and reports"]
  node_analysis["Job analysis"]
  node_results[("Job status and results")]
  node_charts["SVG charts<br/>[charts.py]"]
  node_reports["CSV and PDF reports<br/>[report_service.py]"]
  node_reportfiles["Generated reports"]
end

node_analyst(("Analyst"))

node_analyst -->|"uses"| node_flask
node_flask -->|"delegates to"| node_controller
node_flask -->|"renders"| node_pages
node_controller -->|"validates upload"| node_csvcheck
node_controller -->|"saves CSV"| node_upload
node_csvcheck -->|"parses rows"| node_rowvalidation
node_controller -->|"starts job"| node_analysis
node_analysis -->|"streams CSV"| node_source
node_source -->|"parses records"| node_rowvalidation
node_source -->|"yields"| node_record
node_analysis -->|"runs processor"| node_parallel
node_parallel -->|"dispatches batches"| node_stream
node_stream -->|"updates window"| node_window
node_stream -->|"records metrics"| node_statistics
node_stream -->|"checks patterns"| node_rules
node_stream -->|"checks anomalies"| node_anomaly
node_stream -->|"ingests findings"| node_alertmanager
node_window -->|"stores events"| node_record
node_statistics -->|"reads aggregates"| node_window
node_alertmanager -->|"creates alerts"| node_alert
node_analysis -->|"writes JSON"| node_results
node_flask -->|"renders charts"| node_charts
node_controller -->|"generates exports"| node_reports
node_reports -->|"writes files"| node_reportfiles
node_config -->|"configures workers"| node_parallel

click node_flask "https://github.com/ganesh4060/nids/blob/master/app.py"
click node_pages "https://github.com/ganesh4060/nids/tree/master/templates"
click node_controller "https://github.com/ganesh4060/nids/blob/master/backend/services/controller.py"
click node_upload "https://github.com/ganesh4060/nids/tree/master/uploads"
click node_csvcheck "https://github.com/ganesh4060/nids/blob/master/backend/services/csv_service.py"
click node_rowvalidation "https://github.com/ganesh4060/nids/blob/master/backend/utils/validators.py"
click node_source "https://github.com/ganesh4060/nids/blob/master/backend/processing/traffic_source.py"
click node_record "https://github.com/ganesh4060/nids/blob/master/backend/models/traffic_record.py"
click node_parallel "https://github.com/ganesh4060/nids/blob/master/backend/processing/parallel_processor.py"
click node_stream "https://github.com/ganesh4060/nids/blob/master/backend/processing/stream_processor.py"
click node_window "https://github.com/ganesh4060/nids/blob/master/backend/detection/sliding_window.py"
click node_statistics "https://github.com/ganesh4060/nids/blob/master/backend/detection/statistics_engine.py"
click node_rules "https://github.com/ganesh4060/nids/blob/master/backend/detection/attack_detector.py"
click node_anomaly "https://github.com/ganesh4060/nids/blob/master/backend/detection/anomaly_detector.py"
click node_alertmanager "https://github.com/ganesh4060/nids/blob/master/backend/detection/alert_manager.py"
click node_alert "https://github.com/ganesh4060/nids/blob/master/backend/models/alert.py"
click node_config "https://github.com/ganesh4060/nids/blob/master/config.py"
click node_analysis "https://github.com/ganesh4060/nids/blob/master/backend/services/analysis_service.py"
click node_results "https://github.com/ganesh4060/nids/tree/master/results"
click node_charts "https://github.com/ganesh4060/nids/blob/master/backend/utils/charts.py"
click node_reports "https://github.com/ganesh4060/nids/blob/master/backend/services/report_service.py"
click node_reportfiles "https://github.com/ganesh4060/nids/tree/master/reports"

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_flask,node_pages,node_controller toneBlue
class node_upload,node_csvcheck,node_rowvalidation,node_source toneAmber
class node_record,node_parallel,node_stream,node_window,node_statistics,node_rules,node_anomaly,node_alertmanager,node_alert,node_config toneMint
class node_analysis,node_results,node_charts,node_reports,node_reportfiles toneRose
class node_analyst toneIndigo
```

## Components

### Web application

- [Flask routes](https://github.com/ganesh4060/nids/blob/master/app.py): `app.py`
- [NIDS pages](https://github.com/ganesh4060/nids/tree/master/templates): `templates`
- [Application facade](https://github.com/ganesh4060/nids/blob/master/backend/services/controller.py): `backend/services/controller.py`

### Dataset intake

- [Uploaded CSV](https://github.com/ganesh4060/nids/tree/master/uploads): `uploads`
- [CSV validation](https://github.com/ganesh4060/nids/blob/master/backend/services/csv_service.py): `backend/services/csv_service.py`
- [Row parsing](https://github.com/ganesh4060/nids/blob/master/backend/utils/validators.py): `backend/utils/validators.py`
- [CSV record source](https://github.com/ganesh4060/nids/blob/master/backend/processing/traffic_source.py): `backend/processing/traffic_source.py`

### Analysis engine

- [Traffic record](https://github.com/ganesh4060/nids/blob/master/backend/models/traffic_record.py): `backend/models/traffic_record.py`
- [IP-sharded workers](https://github.com/ganesh4060/nids/blob/master/backend/processing/parallel_processor.py): `backend/processing/parallel_processor.py`
- [Record processing](https://github.com/ganesh4060/nids/blob/master/backend/processing/stream_processor.py): `backend/processing/stream_processor.py`
- [Sliding window](https://github.com/ganesh4060/nids/blob/master/backend/detection/sliding_window.py): `backend/detection/sliding_window.py`
- [Window and totals](https://github.com/ganesh4060/nids/blob/master/backend/detection/statistics_engine.py): `backend/detection/statistics_engine.py`
- [Attack rules](https://github.com/ganesh4060/nids/blob/master/backend/detection/attack_detector.py): `backend/detection/attack_detector.py`
- [Anomaly detection](https://github.com/ganesh4060/nids/blob/master/backend/detection/anomaly_detector.py): `backend/detection/anomaly_detector.py`
- [Alert management](https://github.com/ganesh4060/nids/blob/master/backend/detection/alert_manager.py): `backend/detection/alert_manager.py`
- [Alert model](https://github.com/ganesh4060/nids/blob/master/backend/models/alert.py): `backend/models/alert.py`
- [Detection settings](https://github.com/ganesh4060/nids/blob/master/config.py): `config.py`

### Results and reports

- [Job analysis](https://github.com/ganesh4060/nids/blob/master/backend/services/analysis_service.py): `backend/services/analysis_service.py`
- [Job status and results](https://github.com/ganesh4060/nids/tree/master/results): `results`
- [SVG charts](https://github.com/ganesh4060/nids/blob/master/backend/utils/charts.py): `backend/utils/charts.py`
- [CSV and PDF reports](https://github.com/ganesh4060/nids/blob/master/backend/services/report_service.py): `backend/services/report_service.py`
- [Generated reports](https://github.com/ganesh4060/nids/tree/master/reports): `reports`

### Other components

- **Analyst**

## Connections

- Analyst → Flask routes: uses (evidence: `README.md`)
- Flask routes → Application facade: delegates to (evidence: `app.py`)
- Flask routes → NIDS pages: renders (evidence: `README.md`)
- Application facade → CSV validation: validates upload (evidence: `backend/services/controller.py`)
- Application facade → Uploaded CSV: saves CSV (evidence: `backend/services/controller.py`)
- CSV validation → Row parsing: parses rows (evidence: `backend/services/csv_service.py`)
- Application facade → Job analysis: starts job (evidence: `backend/services/controller.py`)
- Job analysis → CSV record source: streams CSV (evidence: `backend/services/analysis_service.py`)
- CSV record source → Row parsing: parses records (evidence: `backend/processing/traffic_source.py`)
- CSV record source → Traffic record: yields (evidence: `backend/processing/traffic_source.py`)
- Job analysis → IP-sharded workers: runs processor (evidence: `backend/services/analysis_service.py`)
- IP-sharded workers → Record processing: dispatches batches (evidence: `README.md`)
- Record processing → Sliding window: updates window (evidence: `backend/processing/stream_processor.py`)
- Record processing → Window and totals: records metrics (evidence: `backend/processing/stream_processor.py`)
- Record processing → Attack rules: checks patterns (evidence: `backend/processing/stream_processor.py`)
- Record processing → Anomaly detection: checks anomalies (evidence: `backend/processing/stream_processor.py`)
- Record processing → Alert management: ingests findings (evidence: `backend/processing/stream_processor.py`)
- Sliding window → Traffic record: stores events (evidence: `backend/detection/sliding_window.py`)
- Window and totals → Sliding window: reads aggregates (evidence: `backend/detection/statistics_engine.py`)
- Alert management → Alert model: creates alerts (evidence: `backend/detection/alert_manager.py`)
- Job analysis → Job status and results: writes JSON (evidence: `backend/services/analysis_service.py`)
- Flask routes → SVG charts: renders charts (evidence: `app.py`)
- Application facade → CSV and PDF reports: generates exports (evidence: `backend/services/controller.py`)
- CSV and PDF reports → Generated reports: writes files (evidence: `backend/services/report_service.py`)
- Detection settings → IP-sharded workers: configures workers (evidence: `backend/processing/parallel_processor.py`)
