You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Includes FastAPI stack, Motor, auth libs, ML libs, PDF/charting libs, and dev/test packages.
backend/server.py
FastAPI entrypoint
Sets Windows Proactor loop policy, initializes app, wires startup/shutdown DB lifecycle, serves /api and /api/health, mounts auth/scan/report routers.
backend/setup_backend.ps1
Backend setup script
Automates environment bootstrap for Windows backend dev/runtime setup.
4.2 App Package Root
File
What It Contains
Detailed Behavior
backend/app/__init__.py
Package marker
Marks app as a Python package for imports.
backend/app/config.py
Legacy config constants
Loads dotenv and exposes simple constants (MONGO_URI, DB_NAME, JWT_SECRET, ALGORITHM, expiry); superseded by app/core/config.py in active app wiring.
4.3 API Layer (backend/app/api)
File
What It Contains
Detailed Behavior
backend/app/api/__init__.py
Package marker
Marks API package.
backend/app/api/auth.py
Auth router
POST /auth/register, POST /auth/login, GET /auth/me; uses AuthService; maps ValueError to HTTP 4xx and unexpected errors to 500.
backend/app/api/report.py
Report router
GET /report/{scan_id}; requires auth via get_current_user; resolves report through MLService.get_report(scan_id, user_id).
Implementation note:
/auth/me in backend/app/api/auth.py currently has unusual dependency wiring (Depends(get_database) assigned to current_user) and then manually calls get_current_user().
4.4 Core Layer (backend/app/core)
File
What It Contains
Detailed Behavior
backend/app/core/config.py
Pydantic settings object
Defines Settings(BaseSettings) with API metadata, auth configuration, DB config (MONGO_URL, DB_NAME), CORS, and exports singleton settings.
backend/app/core/init_.py
Stray marker file
Named init_.py (single underscore); not used as package initializer.
ScanCreate with target validator, plus status/results response models (ScanResponse, ScanStatusResponse, ScanResultsResponse).
backend/app/schemas/report.py
Report API contracts
ReportResponse and VulnerabilitySummary for typed report payload structure.
4.8 Route Layer (backend/app/routes)
File
What It Contains
Detailed Behavior
backend/app/routes/scan.py
Active orchestration endpoints + background worker
Exposes GET /scan/health, GET /scan/scanners, GET /scan/history, POST /scan/start, GET /scan/status/{scan_id}, GET /scan/results/{scan_id}, GET /scan/report/{scan_id}/pdf; background run_all_scanners handles progress updates, log streaming, scanner execution, ML analysis, and final persistence.
4.9 Scanner Layer (backend/app/scanners)
File
What It Contains
Detailed Behavior
backend/app/scanners/__init__.py
Scanner registry bootstrap
Registers known scanner classes, instantiates for availability checks, builds AVAILABLE_SCANNERS, exports get_scanner, get_available_scanners, get_scanner_info.
backend/app/scanners/base.py
Scanner interface
BaseScannerInterface with async scan(target) contract and tool name handling.
backend/app/scanners/nmap_scanner.py
Nmap adapter
Resolves Nmap binary (tool_paths.txt/common paths/PATH), runs nmap -sV -T4 --top-ports 100 -oX -, parses XML + fallback text, applies canonical service mapping and severity heuristics, emits normalized findings and formatted raw output.
backend/app/scanners/nikto_scanner.py
Nikto adapter
Resolves Nikto + Perl paths, enforces HTTP scheme, runs Nikto with bounded tuning/time, parses line-based findings with dedupe and type/severity mapping, generates recommendations and formatted raw output.
backend/app/scanners/sslscan_scanner.py
SSL/TLS adapter
Hybrid scanner: optional testssl.sh execution plus Python-native TLS probe; detects deprecated protocols, weak ciphers, cert/self-signed/expiry states; converts into standardized findings and summary.
Creates scans and launches async scanner execution via asyncio.gather; updates scan status transitions and exposes status/results/history retrieval helpers.
backend/app/services/scanner_orchestrator.py
Legacy orchestrator
Async orchestrator currently wired for Nmap + Nikto only; SSLScan/DirSearch sections are intentionally commented.
backend/app/services/aggregator_service.py
Generic result aggregator
Normalizes multi-scanner findings, computes severity distribution, groups findings by type, and emits scanner execution summary.
backend/app/services/vulnerability_aggregator.py
Compatibility aggregator
Converts Nmap/Nikto result shapes (new and legacy formats) into simplified vulnerability records and CVSS estimates; SSL/DirSearch logic is commented out.
backend/app/services/ml_service.py
ML bridge + report service
Imports advanced predictor from ml/src/inference.py (from src.inference import predict_attack), exposes hybrid/rule-based analysis paths, legacy RF helpers, report creation (_create_report) and retrieval (get_report), and currently used analyze_scan(findings, scanner_results) wrapper.
backend/app/services/pdf_report.py
PDF rendering engine
ReportLab/matplotlib report generation, large REMEDIATION_MAP and _lookup_remediation, risk/severity chart embedding, ML analysis + finding tables + raw output sections.