# sandipkhadka/flowwatch architecture

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

- Interactive diagram: https://gitdiagram.com/sandipkhadka/flowwatch
- Repository: https://github.com/sandipkhadka/flowwatch

## Overview

1. **What the system is**
   FlowWatch AI is a hybrid intrusion detection system built around two execution paths: **real-time network monitoring** and **offline analysis/reporting**. The live path captures packets, scores them with rules and ML, and raises alerts; the offline path turns stored alerts and traffic data into dashboards, PDFs, and exports.

2. **Primary runtime entry points**
   The repository exposes both top-level launch files (`app.py`, `main.py`) and a packaged Streamlit app under `src/app/main.py`. This strongly suggests the UI is the main operator-facing entrypoint, while the underlying detection engine runs as a separate service/module that the UI consumes.

3. **Packet ingestion and mode selection**
   `src/detection/real_time_detector.py` is the orchestration layer for detection. It works through `src/detection/modes/` with a `base_mode`, `live_mode`, and `demo_mode`, which separates actual packet capture from simulated/demo traffic. The packet-capture side is Scapy-based per the README.

4. **Detection pipeline structure**
   Incoming packets flow through `src/detection/handlers/packet_handler.py` into `feature_extractor.py`, then through filtering logic in `src/detection/filters/` for IP, port, and traffic-rule checks. This is the boundary where raw network events become normalized detection features and rule hits.

5. **Hybrid decision engine**
   The core detection approach combines **signature/rule-based filtering** with **anomaly-based ML scoring**. The ML side is loaded via `src/detection/model_loader.py` and likely uses the persisted model artifacts in `models/`, especially the XGBoost model mentioned in the README. `src/ml/threat_predictor.py` and `src/analysis/anamoly_scorer.py` indicate the scoring/classification layer for attack likelihood and category.

6. **Attack classification and analytics**
   Attack mapping and categorization are handled by `src/utils/attack_mapper.py`, `src/analysis/attack_chain.py`, and `src/analysis/traffic_analyzer.py`. The project explicitly targets categories such as DoS, Probe, R2L, and U2R, so the architecture includes post-detection labeling rather than only binary malicious/benign output.

7. **Threat intelligence and enrichment**
   Alerts are enriched by `src/intelligence/` using IOC extraction, MITRE ATT&CK mapping, and higher-level threat-intel logic. This layer adds context to raw detections so the system can explain *what* was detected and *how it relates* to known attacker behavior.

8. **Alerting, response, and automation**
   `src/utils/alert_manager.py` and `src/detection/handlers/alert_handler.py` centralize alert lifecycle management. `src/response/firewall_manager.py` is the response boundary, implying the system can trigger defensive actions, not just observe. `src/integration/seim_integrator.py` suggests alerts can also be forwarded to an external SIEM pipeline.

9. **Persistence, exports, and reports**
   Alerts and operational state are stored in `data/ids_database.db` through `src/utils/database_manager.py`. Reporting is split across `src/reports/auto_reporter.py` and `src/utils/pdf_generator.py`, with generated artifacts landing in `reports/` and `exports/`. The presence of Excel and PDF outputs shows the system is designed for auditability and post-incident review.

10. **Operator dashboard**
   The Streamlit UI lives under `src/app/`, with pages for live monitoring, analytics, reports, and threat intelligence. Shared UI components are in `src/app/components/`, and `src/app/session_state.py` indicates the dashboard keeps live app state between pages. This UI is the main human control plane for viewing detections, trends, and report artifacts.

11. **Visualization and analysis utilities**
   `src/visualization/` contains traffic and timeline visualizations, plus word cloud generation, which are likely consumed by the analytics pages. `src/analysis/benchmark.py` suggests the repo also supports evaluating model quality or comparing detection modes outside the live pipeline.

12. **Configuration and deployment boundaries**
   Configuration is split across `config.py`, `src/config.py`, `src/app/config.py`, and `config/alert_config.json`, indicating separate configuration scopes for engine behavior, UI behavior, and alert thresholds/routing. `Dockerfile` and `docker-compose.yml` show the system is containerized for reproducible deployment, while `requirements.txt` anchors the Python runtime and dependencies.

13. **Test and simulation support**
   `simulate_attack.py`, `test_model.py`, and `test_system.py` provide synthetic traffic generation and validation of the model/system path. These files indicate the repo is meant to be exercised both with real packet capture and with repeatable test inputs, which is important for demonstrating and verifying end-to-end behavior.

Main entry points: [`src/app/main.py`](https://github.com/sandipkhadka/flowwatch/blob/main/src/app/main.py) (App entry), [`src/detection/handlers/alert_handler.py`](https://github.com/sandipkhadka/flowwatch/blob/main/src/detection/handlers/alert_handler.py) (Alert handler), [`src/reports/auto_reporter.py`](https://github.com/sandipkhadka/flowwatch/blob/main/src/reports/auto_reporter.py) (Auto reporter), [`src/detection/handlers/feature_extractor.py`](https://github.com/sandipkhadka/flowwatch/blob/main/src/detection/handlers/feature_extractor.py) (Feature extractor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Operator UI"]
  node_src_app_main["App entry<br/>streamlit entrypoint<br/>[main.py]"]
  node_src_app_pages_live["Live monitor<br/>dashboard page<br/>[live_monitor.py]"]
  node_src_app_pages_analytics["Analytics<br/>dashboard page<br/>[analytics.py]"]
  node_src_app_pages_reports["Reports<br/>dashboard page<br/>[reports.py]"]
  node_src_app_pages_threat["Threat intel<br/>dashboard page<br/>[threat_intel.py]"]
  node_src_app_components["UI widgets<br/>shared components"]
  node_src_app_state["Session state<br/>ui state<br/>[session_state.py]"]
end

subgraph group_detect["Detection Engine"]
  node_src_detector["Detector<br/>runtime orchestrator"]
  node_src_modes["Execution modes<br/>capture modes"]
  node_src_packet_handler["Packet handler<br/>packet pipeline<br/>[packet_handler.py]"]
  node_src_feature_extractor["Feature extractor<br/>feature pipeline"]
  node_src_filters["Rule filters<br/>signature rules"]
  node_src_model_loader["Model loader<br/>ml runtime<br/>[model_loader.py]"]
  node_src_threat_predictor["Threat predictor<br/>ml scoring"]
  node_src_attack_chain["Attack chain<br/>analysis logic<br/>[attack_chain.py]"]
end

subgraph group_intel["Enrichment & Response"]
  node_src_alert_handler["Alert handler<br/>alert orchestration<br/>[alert_handler.py]"]
  node_src_threat_intel["Threat intel<br/>enrichment<br/>[threat_intel.py]"]
  node_src_firewall["Firewall response<br/>response action"]
end

subgraph group_data["Storage & Reporting"]
  node_src_db[("Database<br/>sqlite persistence<br/>[ids_database.db]")]
  node_src_reporter["Auto reporter<br/>report generation<br/>[auto_reporter.py]"]
  node_src_pdf["PDF generator<br/>export formatting<br/>[pdf_generator.py]"]
  node_src_exports["Exports<br/>artifact output"]
end

node_src_app_main -->|"navigates to"| node_src_app_pages_live
node_src_app_main -->|"navigates to"| node_src_app_pages_analytics
node_src_app_main -->|"navigates to"| node_src_app_pages_reports
node_src_app_main -->|"navigates to"| node_src_app_pages_threat
node_src_app_pages_live -->|"reads live status"| node_src_detector
node_src_app_pages_analytics -->|"queries history"| node_src_db
node_src_app_pages_reports -->|"opens reports"| node_src_reporter
node_src_app_pages_threat -->|"shows enrichment"| node_src_threat_intel
node_src_app_components -->|"supports UI"| node_src_app_pages_live
node_src_app_state -->|"shares state"| node_src_app_main
node_src_detector -->|"selects mode"| node_src_modes
node_src_modes -->|"feeds packets"| node_src_packet_handler
node_src_packet_handler -->|"extracts features"| node_src_feature_extractor
node_src_feature_extractor -->|"applies rules"| node_src_filters
node_src_feature_extractor -->|"loads model"| node_src_model_loader
node_src_model_loader -->|"powers scoring"| node_src_threat_predictor
node_src_filters -->|"raises hits"| node_src_alert_handler
node_src_threat_predictor -->|"classifies attacks"| node_src_attack_chain
node_src_attack_chain -->|"emits verdicts"| node_src_alert_handler
node_src_alert_handler -->|"enriches"| node_src_threat_intel
node_src_alert_handler -->|"responds"| node_src_firewall
node_src_alert_handler -->|"persists"| node_src_db
node_src_db -->|"reports from"| node_src_reporter
node_src_reporter -->|"formats as"| node_src_pdf
node_src_reporter -->|"exports to"| node_src_exports

click node_src_app_main "https://github.com/sandipkhadka/flowwatch/blob/main/src/app/main.py"
click node_src_app_pages_live "https://github.com/sandipkhadka/flowwatch/blob/main/src/app/pages/live_monitor.py"
click node_src_app_pages_analytics "https://github.com/sandipkhadka/flowwatch/blob/main/src/app/pages/analytics.py"
click node_src_app_pages_reports "https://github.com/sandipkhadka/flowwatch/blob/main/src/app/pages/reports.py"
click node_src_app_pages_threat "https://github.com/sandipkhadka/flowwatch/blob/main/src/app/pages/threat_intel.py"
click node_src_app_components "https://github.com/sandipkhadka/flowwatch/tree/main/src/app/components"
click node_src_app_state "https://github.com/sandipkhadka/flowwatch/blob/main/src/app/session_state.py"
click node_src_detector "https://github.com/sandipkhadka/flowwatch/blob/main/src/detection/real_time_detector.py"
click node_src_modes "https://github.com/sandipkhadka/flowwatch/tree/main/src/detection/modes"
click node_src_packet_handler "https://github.com/sandipkhadka/flowwatch/blob/main/src/detection/handlers/packet_handler.py"
click node_src_feature_extractor "https://github.com/sandipkhadka/flowwatch/blob/main/src/detection/handlers/feature_extractor.py"
click node_src_filters "https://github.com/sandipkhadka/flowwatch/tree/main/src/detection/filters"
click node_src_model_loader "https://github.com/sandipkhadka/flowwatch/blob/main/src/detection/model_loader.py"
click node_src_threat_predictor "https://github.com/sandipkhadka/flowwatch/blob/main/src/ml/threat_predictor.py"
click node_src_attack_chain "https://github.com/sandipkhadka/flowwatch/blob/main/src/analysis/attack_chain.py"
click node_src_alert_handler "https://github.com/sandipkhadka/flowwatch/blob/main/src/detection/handlers/alert_handler.py"
click node_src_threat_intel "https://github.com/sandipkhadka/flowwatch/blob/main/src/intelligence/threat_intel.py"
click node_src_firewall "https://github.com/sandipkhadka/flowwatch/blob/main/src/response/firewall_manager.py"
click node_src_db "https://github.com/sandipkhadka/flowwatch/blob/main/data/ids_database.db"
click node_src_reporter "https://github.com/sandipkhadka/flowwatch/blob/main/src/reports/auto_reporter.py"
click node_src_pdf "https://github.com/sandipkhadka/flowwatch/blob/main/src/utils/pdf_generator.py"
click node_src_exports "https://github.com/sandipkhadka/flowwatch/tree/main/exports"

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_src_app_main,node_src_app_pages_live,node_src_app_pages_analytics,node_src_app_pages_reports,node_src_app_pages_threat,node_src_app_components,node_src_app_state toneBlue
class node_src_detector,node_src_modes,node_src_packet_handler,node_src_feature_extractor,node_src_filters,node_src_model_loader,node_src_threat_predictor,node_src_attack_chain toneAmber
class node_src_alert_handler,node_src_threat_intel,node_src_firewall toneMint
class node_src_db,node_src_reporter,node_src_pdf,node_src_exports toneRose
```

## Components

### Operator UI

Streamlit dashboard and shared presentation components

- [App entry](https://github.com/sandipkhadka/flowwatch/blob/main/src/app/main.py): streamlit entrypoint · Packaged Streamlit application entry · `src/app/main.py`
- [Live monitor](https://github.com/sandipkhadka/flowwatch/blob/main/src/app/pages/live_monitor.py): dashboard page · Operator view for live detections and packet activity · `src/app/pages/live_monitor.py`
- [Analytics](https://github.com/sandipkhadka/flowwatch/blob/main/src/app/pages/analytics.py): dashboard page · Trends, charts, and summary analysis views · `src/app/pages/analytics.py`
- [Reports](https://github.com/sandipkhadka/flowwatch/blob/main/src/app/pages/reports.py): dashboard page · Report browsing and export views · `src/app/pages/reports.py`
- [Threat intel](https://github.com/sandipkhadka/flowwatch/blob/main/src/app/pages/threat_intel.py): dashboard page · Threat intelligence and contextual enrichment views · `src/app/pages/threat_intel.py`
- [UI widgets](https://github.com/sandipkhadka/flowwatch/tree/main/src/app/components): shared components · Reusable cards, charts, and sidebar elements · `src/app/components`
- [Session state](https://github.com/sandipkhadka/flowwatch/blob/main/src/app/session_state.py): ui state · Shared dashboard state across pages · `src/app/session_state.py`

### Detection Engine

Live packet capture, feature extraction, filtering, and scoring

- [Detector](https://github.com/sandipkhadka/flowwatch/blob/main/src/detection/real_time_detector.py): runtime orchestrator · Coordinates real-time detection modes and packet flow · `src/detection/real_time_detector.py`
- [Execution modes](https://github.com/sandipkhadka/flowwatch/tree/main/src/detection/modes): capture modes · Base, live, and demo runtime paths · `src/detection/modes`
- [Packet handler](https://github.com/sandipkhadka/flowwatch/blob/main/src/detection/handlers/packet_handler.py): packet pipeline · Normalizes incoming packets for downstream detection · `src/detection/handlers/packet_handler.py`
- [Feature extractor](https://github.com/sandipkhadka/flowwatch/blob/main/src/detection/handlers/feature_extractor.py): feature pipeline · Builds detection features from packet data · `src/detection/handlers/feature_extractor.py`
- [Rule filters](https://github.com/sandipkhadka/flowwatch/tree/main/src/detection/filters): signature rules · IP, port, and traffic-rule filtering layer · `src/detection/filters`
- [Model loader](https://github.com/sandipkhadka/flowwatch/blob/main/src/detection/model_loader.py): ml runtime · Loads persisted model artifacts for scoring · `src/detection/model_loader.py`
- [Threat predictor](https://github.com/sandipkhadka/flowwatch/blob/main/src/ml/threat_predictor.py): ml scoring · ML-based attack likelihood and class prediction · `src/ml/threat_predictor.py`
- [Attack chain](https://github.com/sandipkhadka/flowwatch/blob/main/src/analysis/attack_chain.py): analysis logic · Post-detection attack chaining and categorization · `src/analysis/attack_chain.py`

### Enrichment & Response

Threat intelligence, alert handling, and defensive actions

- [Alert handler](https://github.com/sandipkhadka/flowwatch/blob/main/src/detection/handlers/alert_handler.py): alert orchestration · Central alert lifecycle and dispatch boundary · `src/detection/handlers/alert_handler.py`
- [Threat intel](https://github.com/sandipkhadka/flowwatch/blob/main/src/intelligence/threat_intel.py): enrichment · IOC extraction, MITRE mapping, and context enrichment · `src/intelligence/threat_intel.py`
- [Firewall response](https://github.com/sandipkhadka/flowwatch/blob/main/src/response/firewall_manager.py): response action · Defensive response execution boundary · `src/response/firewall_manager.py`

### Storage & Reporting

Persistence, exports, and offline reporting

- [Database](https://github.com/sandipkhadka/flowwatch/blob/main/data/ids_database.db): sqlite persistence · Stores alerts and operational state · `data/ids_database.db`
- [Auto reporter](https://github.com/sandipkhadka/flowwatch/blob/main/src/reports/auto_reporter.py): report generation · Builds offline reports from stored detections · `src/reports/auto_reporter.py`
- [PDF generator](https://github.com/sandipkhadka/flowwatch/blob/main/src/utils/pdf_generator.py): export formatting · Produces PDF artifacts for reporting · `src/utils/pdf_generator.py`
- [Exports](https://github.com/sandipkhadka/flowwatch/tree/main/exports): artifact output · Generated spreadsheets and exported reports · `exports`

## Connections

- App entry → Live monitor: navigates to · Dashboard routes operator to live monitoring
- App entry → Analytics: navigates to · Dashboard routes operator to analytics
- App entry → Reports: navigates to · Dashboard routes operator to reports
- App entry → Threat intel: navigates to · Dashboard routes operator to threat intel
- Live monitor → Detector: reads live status · Live page consumes detector state and alerts
- Analytics → Database: queries history · Analytics views use persisted events and alerts
- Reports → Auto reporter: opens reports · Reports page surfaces generated artifacts
- Threat intel → Threat intel: shows enrichment · Threat intel page displays contextual mappings
- UI widgets → Live monitor: supports UI · Shared UI elements used across pages
- Session state → App entry: shares state · Maintains session continuity across pages
- Detector → Execution modes: selects mode · Detector chooses live or demo execution path
- Execution modes → Packet handler: feeds packets · Capture mode delivers packets into the pipeline
- Packet handler → Feature extractor: extracts features · Raw packets become normalized feature records
- Feature extractor → Rule filters: applies rules · Features are evaluated by signature and traffic filters
- Feature extractor → Model loader: loads model · Feature pipeline relies on persisted model artifacts
- Model loader → Threat predictor: powers scoring · Loaded model is used for anomaly or class prediction
- Rule filters → Alert handler: raises hits · Rule matches trigger alert lifecycle handling
- Threat predictor → Attack chain: classifies attacks · ML output is mapped into attack categories
- Attack chain → Alert handler: emits verdicts · Categorized detections are sent to alert handling
- Alert handler → Threat intel: enriches · Alerts gain IOC and MITRE context
- Alert handler → Firewall response: responds · Alert lifecycle can trigger defensive action
- Alert handler → Database: persists · Alerts and state are written to storage
- Database → Auto reporter: reports from · Offline reports are generated from stored data
- Auto reporter → PDF generator: formats as · Report generator produces PDF outputs
- Auto reporter → Exports: exports to · Artifacts are saved for audit and review
