How sandipkhadka/flowwatch works
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: main.py App entry · alert_handler.py Alert handler · auto_reporter.py Auto reporter · feature_extractor.py Feature extractor
Components 22
Operator UI
Streamlit dashboard and shared presentation components
- App entry · Packaged Streamlit application entry
src/app/main.py - Live monitor · Operator view for live detections and packet activity
src/app/pages/live_monitor.py - Analytics · Trends, charts, and summary analysis views
src/app/pages/analytics.py - Reports · Report browsing and export views
src/app/pages/reports.py - Threat intel · Threat intelligence and contextual enrichment views
src/app/pages/threat_intel.py - UI widgets · Reusable cards, charts, and sidebar elements
src/app/components - Session state · Shared dashboard state across pages
src/app/session_state.py
Detection Engine
Live packet capture, feature extraction, filtering, and scoring
- Detector · Coordinates real-time detection modes and packet flow
src/detection/real_time_detector.py - Execution modes · Base, live, and demo runtime paths
src/detection/modes - Packet handler · Normalizes incoming packets for downstream detection
src/detection/handlers/packet_handler.py - Feature extractor · Builds detection features from packet data
src/detection/handlers/feature_extractor.py - Rule filters · IP, port, and traffic-rule filtering layer
src/detection/filters - Model loader · Loads persisted model artifacts for scoring
src/detection/model_loader.py - Threat predictor · ML-based attack likelihood and class prediction
src/ml/threat_predictor.py - Attack chain · Post-detection attack chaining and categorization
src/analysis/attack_chain.py
Enrichment & Response
Threat intelligence, alert handling, and defensive actions
- Alert handler · Central alert lifecycle and dispatch boundary
src/detection/handlers/alert_handler.py - Threat intel · IOC extraction, MITRE mapping, and context enrichment
src/intelligence/threat_intel.py - Firewall response · Defensive response execution boundary
src/response/firewall_manager.py
Storage & Reporting
Persistence, exports, and offline reporting
- Database · Stores alerts and operational state
data/ids_database.db - Auto reporter · Builds offline reports from stored detections
src/reports/auto_reporter.py - PDF generator · Produces PDF artifacts for reporting
src/utils/pdf_generator.py - Exports · Generated spreadsheets and exported reports
exports
Connections 25
- 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