# mo7yw4ng/ai-speeding-ticket architecture

> Architecture diagram of the GitHub repository mo7yw4ng/ai-speeding-ticket, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mo7yw4ng/ai-speeding-ticket
- Repository: https://github.com/mo7yw4ng/ai-speeding-ticket

## Overview

##### Main System Components

A. Frontend Layer (AI-FE)
- Vue.js based web application
- Components for violation form handling
- Image viewing capabilities
- User interface elements

B. Backend Services
##### AI Backend (AI-BE)
- License plate recognition service
- Python-based image processing
- REST API endpoints

##### Dashboard Backend (Dashboard-BE)
- Go-based service
- Authentication handling
- WebSocket support
- Data management endpoints

##### Data Engineering Layer (Dashboard-DE)
- Apache Airflow DAGs
- ETL pipelines
- Data processing workflows

##### Component Relationships

- User → Frontend: HTTP/HTTPS
- Frontend → AI Backend: REST API calls
- Frontend → Dashboard Backend: WebSocket/REST
- Backend Services → Database: Persistent storage
- Dashboard-DE → Data Sources: ETL processes

##### Specific Architectural Elements

Key components:
**┌─────────────────────────────────────────────────────────┐**
- Client Layer                        │
- ┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Frontend (Vue.js)                     │
- ┬─────────────────────────┬─────────────────┤
- Violation   │     Image Viewer        │    Forms        │
- System    │                         │                 │
- ┴─────────────────────────┴─────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Backend Services                      │
- ┬─────────────────────────┬─────────────────┤
- AI Service  │  Dashboard Service      │  ETL Pipeline   │
- (Python)    │  (Go)                   │  (Airflow)      │
- ┴─────────────────────────┴─────────────────┘
- ↓
**┌─────────────────────────────────────────────────────────┐**
- Data Layer                           │
- ┬─────────────────────────┬─────────────────┤
- Redis      │     PostgreSQL          │    Storage      │
- Cache      │     Database            │                 │
- ┴─────────────────────────┴─────────────────┘

##### Additional Details

A. Security Layer
- Authentication flow
- Rate limiting middleware
- Authorization checks

B. Integration Points
- External API connections
- Data flow between services
- Cache interaction points

C. Deployment Infrastructure
- Docker containers
- Nginx configurations
- Service orchestration

##### Specific Implementation Notes

- Plate recognition pipeline in the AI-BE section
- Real-time websocket connections for the dashboard
- ETL processes for data engineering
- Demonstrate the cache layer with Redis
- Separation of concerns between different backend services

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        User((User))
    end

    subgraph "Frontend Layer"
        App["Main Application"]:::frontend
        ViolationForm["Violation Form"]:::frontend
        ImageViewer["Image Viewer"]:::frontend
        FormHandler["Form Handler"]:::frontend
        
        App --> ViolationForm
        App --> ImageViewer
        App --> FormHandler
    end

    subgraph "Backend Services"
        subgraph "AI Backend"
            LPR["License Plate Recognition"]:::ai
            MainService["Main Service"]:::ai
            BackendAPI["Backend API"]:::ai
            
            BackendAPI --> MainService
            MainService --> LPR
        end

        subgraph "Dashboard Backend"
            Auth["Authentication"]:::dashboard
            WebSocket["WebSocket Handler"]:::dashboard
            RateLimit["Rate Limiting"]:::dashboard
            Models["Database Models"]:::dashboard
            Routes["Routes"]:::dashboard
            
            Routes --> Auth
            Routes --> WebSocket
            RateLimit --> Routes
            Routes --> Models
        end

        subgraph "Data Engineering"
            ETLBase["ETL Pipeline Base"]:::etl
            DAGOps["DAG Operators"]:::etl
            DataUtils["Data Processing Utils"]:::etl
            ETLJobs["ETL Jobs"]:::etl
            
            ETLBase --> DAGOps
            DAGOps --> DataUtils
            DAGOps --> ETLJobs
        end
    end

    subgraph "Data Layer"
        Redis[(Redis Cache)]:::database
        PostgreSQL[(PostgreSQL DB)]:::database
        Storage[(File Storage)]:::database
    end

    User --> App
    App --> BackendAPI
    App --> WebSocket
    BackendAPI --> Redis
    BackendAPI --> PostgreSQL
    WebSocket --> Redis
    WebSocket --> PostgreSQL
    ETLJobs --> PostgreSQL
    LPR --> Storage

    %% Click Events
    click App "https://github.com/MO7YW4NG/AI-Speeding-Ticket/blob/main/AI-FE/src/App.vue"
    click ViolationForm "https://github.com/MO7YW4NG/AI-Speeding-Ticket/blob/main/AI-FE/src/components/ViolationForm.vue"
    click ImageViewer "https://github.com/MO7YW4NG/AI-Speeding-Ticket/blob/main/AI-FE/src/components/ImageViewer.vue"
    click FormHandler "https://github.com/MO7YW4NG/AI-Speeding-Ticket/blob/main/AI-FE/src/components/Form.vue"
    click LPR "https://github.com/MO7YW4NG/AI-Speeding-Ticket/blob/main/AI-BE/recognizer/plate_recognizer.py"
    click MainService "https://github.com/MO7YW4NG/AI-Speeding-Ticket/blob/main/AI-BE/main.py"
    click BackendAPI "https://github.com/MO7YW4NG/AI-Speeding-Ticket/blob/main/AI-BE/be.py"
    click Auth "https://github.com/MO7YW4NG/AI-Speeding-Ticket/blob/main/Dashboard-BE/app/controllers/auth.go"
    click WebSocket "https://github.com/MO7YW4NG/AI-Speeding-Ticket/blob/main/Dashboard-BE/app/controllers/websocket.go"
    click RateLimit "https://github.com/MO7YW4NG/AI-Speeding-Ticket/blob/main/Dashboard-BE/app/middleware/rateLimit.go"
    click Models "https://github.com/MO7YW4NG/AI-Speeding-Ticket/tree/main/Dashboard-BE/app/models/"
    click Routes "https://github.com/MO7YW4NG/AI-Speeding-Ticket/blob/main/Dashboard-BE/app/routes/router.go"
    click ETLBase "https://github.com/MO7YW4NG/AI-Speeding-Ticket/blob/main/Dashboard-DE/dags/operators/common_pipeline.py"
    click DAGOps "https://github.com/MO7YW4NG/AI-Speeding-Ticket/tree/main/Dashboard-DE/dags/operators/"
    click DataUtils "https://github.com/MO7YW4NG/AI-Speeding-Ticket/tree/main/Dashboard-DE/dags/utils/"
    click ETLJobs "https://github.com/MO7YW4NG/AI-Speeding-Ticket/tree/main/Dashboard-DE/dags/proj_city_dashboard/"

    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef ai fill:#2ecc71,stroke:#27ae60,color:white
    classDef dashboard fill:#e67e22,stroke:#d35400,color:white
    classDef etl fill:#9b59b6,stroke:#8e44ad,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:black
    classDef default fill:#95a5a6,stroke:#7f8c8d,color:white
```
