# fastbit-ljb/traffic_detection_core architecture

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

- Interactive diagram: https://gitdiagram.com/fastbit-ljb/traffic_detection_core
- Repository: https://github.com/fastbit-ljb/traffic_detection_core

## Overview

This is a web-based intelligent traffic detection and task-management system. Users interact with a React dashboard to submit detection work and manage traffic-related resources; the FastAPI backend runs detection and manages persistent history, video, dataset, training, and model operations. The README documents account-scoped records, real-time updates, adaptive signal management, and model comparison. Those are represented as capabilities, but some route and frontend wiring was not sampled, so uncertain links are omitted or marked dashed.

Main entry points: [`backend/app/main.py`](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/main.py) (FastAPI routes), [`frontend/src/components/TrafficDashboard.tsx`](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/frontend/src/components/TrafficDashboard.tsx) (Traffic dashboard), [`backend/app/services/project_service.py`](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/services/project_service.py) (Project repository), [`backend/app/middleware.py`](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/middleware.py) (Request middleware)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Web interface"]
  node_dashboard["Traffic dashboard"]
  node_nav["Pill navigation<br/>[PillNav.tsx]"]
  node_device["Device switch"]
  node_slider["Elastic slider<br/>[ElasticSlider.tsx]"]
end

subgraph group_api["API and security"]
  node_api_server["FastAPI routes<br/>[main.py]"]
  node_middleware["Request middleware<br/>[middleware.py]"]
  node_security["Authentication and security<br/>[security.py]"]
  node_models["Traffic data models<br/>[traffic_models.py]"]
end

subgraph group_traffic["Traffic intelligence"]
  node_detector["Vehicle detector"]
  node_adaptive["Adaptive signal manager"]
  node_analytics["Traffic analytics"]
end

subgraph group_projects["Projects and persistence"]
  node_repository[("Project repository<br/>[project_service.py]")]
  node_dataset["Dataset import<br/>[project_service.py]"]
  node_training["Training and validation<br/>[project_service.py]"]
  node_video["Video detection jobs<br/>[project_service.py]"]
  node_history["Detection history<br/>[project_service.py]"]
end

subgraph group_platform["Runtime support"]
  node_config["Application configuration<br/>[config.py]"]
  node_logger["Application logging<br/>[logger.py]"]
  node_metrics["Prometheus metrics<br/>[metrics.py]"]
end

node_user(("Traffic operator"))
node_model_files["YOLO model weights"]
node_operator_client(("Browser client"))

node_user -->|"uses"| node_dashboard
node_dashboard -->|"renders"| node_nav
node_dashboard -->|"renders"| node_device
node_dashboard -.-> node_slider
node_dashboard -.->|"sends requests"| node_api_server
node_operator_client -->|"connects"| node_api_server
node_api_server -->|"processes requests"| node_middleware
node_api_server -->|"calls detection"| node_detector
node_api_server -->|"reads and writes"| node_repository
node_api_server -->|"serves metrics"| node_metrics
node_api_server -.->|"authenticates users"| node_security
node_api_server -.->|"dispatches traffic operations"| node_adaptive
node_api_server -.->|"requests analytics"| node_analytics
node_detector -->|"produces detection data"| node_models
node_adaptive -->|"uses traffic models"| node_models
node_detector -.->|"loads weights"| node_model_files
node_repository -->|"stores records"| node_history
node_repository -->|"imports datasets"| node_dataset
node_repository -->|"manages jobs"| node_training
node_repository -->|"manages jobs"| node_video
node_video -->|"runs detection"| node_detector
node_middleware -->|"checks rate limits"| node_security
node_middleware -->|"logs requests"| node_logger
node_middleware -.->|"records metrics"| node_metrics
node_logger -->|"reads settings"| node_config
node_security -->|"reads settings"| node_config

click node_dashboard "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/frontend/src/components/TrafficDashboard.tsx"
click node_nav "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/frontend/src/components/PillNav.tsx"
click node_device "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/frontend/src/components/ui/GooeyDeviceSwitch.tsx"
click node_slider "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/frontend/src/components/ui/ElasticSlider.tsx"
click node_api_server "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/main.py"
click node_middleware "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/middleware.py"
click node_security "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/core/security.py"
click node_models "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/models/traffic_models.py"
click node_detector "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/services/intelligent_vehicle_detector.py"
click node_adaptive "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/services/adaptive_traffic_manager.py"
click node_analytics "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/services/analytics_service.py"
click node_repository "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/services/project_service.py"
click node_dataset "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/services/project_service.py"
click node_training "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/services/project_service.py"
click node_video "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/services/project_service.py"
click node_history "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/services/project_service.py"
click node_config "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/core/config.py"
click node_logger "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/core/logger.py"
click node_metrics "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/core/metrics.py"
click node_model_files "https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/models/trained_28068449.pt"

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_dashboard,node_nav,node_device,node_slider,node_operator_client toneBlue
class node_api_server,node_middleware,node_security,node_models toneAmber
class node_detector,node_adaptive,node_analytics toneMint
class node_repository,node_dataset,node_training,node_video,node_history toneRose
class node_config,node_logger,node_metrics,node_user,node_model_files toneIndigo
```

## Components

### Web interface

- [Traffic dashboard](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/frontend/src/components/TrafficDashboard.tsx): `frontend/src/components/TrafficDashboard.tsx`
- [Pill navigation](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/frontend/src/components/PillNav.tsx): `frontend/src/components/PillNav.tsx`
- [Device switch](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/frontend/src/components/ui/GooeyDeviceSwitch.tsx): `frontend/src/components/ui/GooeyDeviceSwitch.tsx`
- [Elastic slider](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/frontend/src/components/ui/ElasticSlider.tsx): `frontend/src/components/ui/ElasticSlider.tsx`

### API and security

- [FastAPI routes](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/main.py): `backend/app/main.py`
- [Request middleware](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/middleware.py): `backend/app/middleware.py`
- [Authentication and security](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/core/security.py): `backend/app/core/security.py`
- [Traffic data models](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/models/traffic_models.py): `backend/app/models/traffic_models.py`

### Traffic intelligence

- [Vehicle detector](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/services/intelligent_vehicle_detector.py): `backend/app/services/intelligent_vehicle_detector.py`
- [Adaptive signal manager](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/services/adaptive_traffic_manager.py): `backend/app/services/adaptive_traffic_manager.py`
- [Traffic analytics](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/services/analytics_service.py): `backend/app/services/analytics_service.py`

### Projects and persistence

- [Project repository](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/services/project_service.py): `backend/app/services/project_service.py`
- [Dataset import](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/services/project_service.py): `backend/app/services/project_service.py`
- [Training and validation](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/services/project_service.py): `backend/app/services/project_service.py`
- [Video detection jobs](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/services/project_service.py): `backend/app/services/project_service.py`
- [Detection history](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/services/project_service.py): `backend/app/services/project_service.py`

### Runtime support

- [Application configuration](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/core/config.py): `backend/app/core/config.py`
- [Application logging](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/core/logger.py): `backend/app/core/logger.py`
- [Prometheus metrics](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/app/core/metrics.py): `backend/app/core/metrics.py`

### Other components

- **Traffic operator**
- [YOLO model weights](https://github.com/fastbit-ljb/traffic_detection_core/blob/main/backend/models/trained_28068449.pt): `backend/models/trained_28068449.pt`
- **Browser client**

## Connections

- Traffic operator → Traffic dashboard: uses (evidence: `README.md`)
- Traffic dashboard → Pill navigation: renders (evidence: `frontend/src/components/TrafficDashboard.tsx`)
- Traffic dashboard → Device switch: renders (evidence: `frontend/src/components/TrafficDashboard.tsx`)
- Traffic dashboard → Elastic slider (evidence: `frontend/src/components/TrafficDashboard.tsx`)
- Traffic dashboard → FastAPI routes: sends requests
- Browser client → FastAPI routes: connects (evidence: `README.md`)
- FastAPI routes → Request middleware: processes requests (evidence: `backend/app/main.py`)
- FastAPI routes → Vehicle detector: calls detection (evidence: `backend/app/main.py`)
- FastAPI routes → Project repository: reads and writes (evidence: `backend/app/main.py`)
- FastAPI routes → Prometheus metrics: serves metrics (evidence: `backend/app/main.py`)
- FastAPI routes → Authentication and security: authenticates users (evidence: `backend/app/main.py`)
- FastAPI routes → Adaptive signal manager: dispatches traffic operations (evidence: `backend/app/main.py`)
- FastAPI routes → Traffic analytics: requests analytics (evidence: `backend/app/main.py`)
- Vehicle detector → Traffic data models: produces detection data (evidence: `backend/app/services/intelligent_vehicle_detector.py`)
- Adaptive signal manager → Traffic data models: uses traffic models (evidence: `backend/app/services/adaptive_traffic_manager.py`)
- Vehicle detector → YOLO model weights: loads weights
- Project repository → Detection history: stores records (evidence: `backend/app/services/project_service.py`)
- Project repository → Dataset import: imports datasets (evidence: `backend/app/services/project_service.py`)
- Project repository → Training and validation: manages jobs (evidence: `backend/app/services/project_service.py`)
- Project repository → Video detection jobs: manages jobs (evidence: `backend/app/services/project_service.py`)
- Video detection jobs → Vehicle detector: runs detection (evidence: `backend/app/services/project_service.py`)
- Request middleware → Authentication and security: checks rate limits (evidence: `backend/app/middleware.py`)
- Request middleware → Application logging: logs requests (evidence: `backend/app/middleware.py`)
- Request middleware → Prometheus metrics: records metrics (evidence: `backend/app/middleware.py`)
- Application logging → Application configuration: reads settings (evidence: `backend/app/core/logger.py`)
- Authentication and security → Application configuration: reads settings (evidence: `backend/app/core/security.py`)
