# cristian-beltran/plate-recognition architecture

> Architecture diagram of the GitHub repository cristian-beltran/plate-recognition, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cristian-beltran/plate-recognition
- Repository: https://github.com/cristian-beltran/plate-recognition

## Overview

##### Main Components
- ML Detection & OCR:
- YOLO Model: The “model” directory contains training images, weights (e.g., yolov8n.pt, best.pt), and logs that indicate training, validation, and test data for plate detection.
- Tesseract OCR: Referenced in the README for reading the text from the detected plates.
- Application User Interface (UI):
- Flet Frontend: The application runs using Flet (“flet run” command) and contains the “pages” directory with modules such as camera.py, history.py, users.py, and vehicles.py.
- Services / Business Logic:
- The “services” directory holds modules (history_service.py, user_service.py, vehicles_service.py) that manage core business processes.
- Persistence Layer:
- Database (app.db): The main SQLite database stores records, likely including vehicle entries, user credentials, and historical logs.
- Supporting/Static Files:
- Assets and configuration files including requirements.txt and others are helpers for deployment and setup.

##### Relationships and Interactions
- User Interaction Flow:
- Users interact with the Flet-based UI (pages) which route actions such as vehicle registration, user login, and viewing history.
- Backend Services:
- The UI triggers calls to the service layer (e.g., vehicles_service, user_service, history_service) to process and validate data.
- ML Processing Pipeline:
- When a vehicle image is captured (likely through the “camera” page), it is sent to the ML detection component (YOLO). The detected plate image data is then passed to Tesseract for digitizing the plate text.
- Persistence:
- Data from the ML analysis as well as service layer decisions are stored and retrieved from the SQLite database (app.db).

##### Architectural Patterns and Design Principles
- Layered Architecture:
- The system can be visualized as layers: a frontend layer (Flet pages), an application/service layer (business logic in “services”), a ML/processing layer (YOLO and Tesseract under “model”), and a persistence layer (SQLite database).
- Separation of Concerns:
- The clear separation between UI, services, and ML components ensures maintainability and scalability.
- Modularity:
- Directory partitioning (pages for UI, services for business logic, model for ML work) helps in isolating functionality.

##### Relevant Technologies
- Flet for interfacing, Python for the main application logic.
- Ultralytics YOLO via the “ultralytics” package to handle object detection and model inference.
- Tesseract for OCR.
- SQLite (app.db) as the local database.
- Various Python libraries as shown in requirements.txt.

##### Final Detailed Advice
- Do not try to capture every file—but rather focus on grouping the project into its main architectural layers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    U["User"]:::external

    %% Frontend Layer
    subgraph "Flet UI (Pages)"
        CAM["Camera"]:::frontend
        HIS["History"]:::frontend
        USR["Users"]:::frontend
        VEH["Vehicles"]:::frontend
    end

    %% Service Layer
    subgraph "Service Layer"
        USR_SRV["User Service"]:::backend
        VEH_SRV["Vehicles Service"]:::backend
        HIS_SRV["History Service"]:::backend
    end

    %% ML Processing Pipeline
    subgraph "ML Processing"
        YOLO["YOLO Detection (ultralytics)"]:::ml
        OCR["OCR Module (Tesseract)"]:::ml
    end

    %% Persistence Layer
    DB["Database (SQLite)"]:::database

    %% Model Training & Data Management
    subgraph "Model Training & Data"
        TRAIN["Training Data & Config"]:::training
    end

    %% Connections
    U -->|"uses"| CAM
    U -->|"uses"| HIS
    U -->|"uses"| USR
    U -->|"uses"| VEH

    CAM -->|"captures image"| USR_SRV
    HIS -->|"view logs"| HIS_SRV
    USR -->|"login/register"| USR_SRV
    VEH -->|"register/update"| VEH_SRV

    USR_SRV -->|"process request"| VEH_SRV
    VEH_SRV -->|"process request"| HIS_SRV

    %% Service Layer interactions
    USR_SRV -->|"calls for detection"| YOLO
    VEH_SRV -->|"calls for detection"| YOLO
    YOLO -->|"sends OCR image"| OCR
    OCR -->|"returns plate text"| USR_SRV

    %% Persistence interactions
    USR_SRV -->|"stores/retrieves data"| DB
    VEH_SRV -->|"stores/retrieves data"| DB
    HIS_SRV -->|"stores/retrieves data"| DB

    %% ML training data interaction
    TRAIN -->|"updates model"| YOLO

    %% Click Events
    click CAM "https://github.com/cristian-beltran/plate-recognition/blob/main/pages/camera.py"
    click HIS "https://github.com/cristian-beltran/plate-recognition/blob/main/pages/history.py"
    click USR "https://github.com/cristian-beltran/plate-recognition/blob/main/pages/users.py"
    click VEH "https://github.com/cristian-beltran/plate-recognition/blob/main/pages/vehicles.py"
    click U "https://github.com/cristian-beltran/plate-recognition/tree/main/pages/"
    click USR_SRV "https://github.com/cristian-beltran/plate-recognition/blob/main/services/user_service.py"
    click VEH_SRV "https://github.com/cristian-beltran/plate-recognition/blob/main/services/vehicles_service.py"
    click HIS_SRV "https://github.com/cristian-beltran/plate-recognition/blob/main/services/history_service.py"
    click YOLO "https://github.com/cristian-beltran/plate-recognition/blob/main/model/yolov8n.pt"
    click DB "https://github.com/cristian-beltran/plate-recognition/blob/main/app.db"
    click TRAIN "https://github.com/cristian-beltran/plate-recognition/tree/main/model/"

    %% Styles
    classDef external fill:#e0e0e0,stroke:#333,stroke-width:2px;
    classDef frontend fill:#fceabb,stroke:#333,stroke-width:2px;
    classDef backend fill:#c9e4f7,stroke:#333,stroke-width:2px;
    classDef ml fill:#d5e8d4,stroke:#333,stroke-width:2px;
    classDef database fill:#fff2cc,stroke:#333,stroke-width:2px;
    classDef training fill:#f4cccc,stroke:#333,stroke-width:2px;
```
