# zain-ul-abdin45/anpr-toll-processing architecture

> Architecture diagram of the GitHub repository zain-ul-abdin45/anpr-toll-processing, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zain-ul-abdin45/anpr-toll-processing
- Repository: https://github.com/zain-ul-abdin45/anpr-toll-processing

## Overview

##### Project Type & Purpose
- This is a backend Toll‐Processing microservice built in Python using FastAPI.
- Its purpose is to read vehicle plates via ANPR (camera) or RFID, apply security checks, store transactions in PostgreSQL, generate alerts, and send notifications.

##### File Structure
- Top level:
- main.py – FastAPI app entrypoint
- api/ – HTTP route modules (plate, RFID, toll, notification, security)
- modules/ – Core business‐logic components (anpr, rfid, security checks, toll logic, SQL layer, logger, notification, vehicle simulation)
- configs/ – JSON/INI config files for DB, logger, system settings
- db_scripts/ – DDLs and seed scripts for PostgreSQL
- logs/ – Rolling directories capturing all runtime logs
- seeds_data.py & requirements.txt
- Architectural pattern: layered monolith separating API, business logic, data access, and cross‐cutting concerns (logging, config).

##### README Insights
- Tech stack: Python 3.10+, FastAPI, PostgreSQL
- Deployment: Uvicorn server, optional Render cloud hosting
- Logging is file‐based per concern (alerts, transactions, plate reads)

##### Main Components & Their Relationships
a. External Hardware / Services:
- ANPR Camera (plate image feed)
- RFID Reader
- Notification Channels (e.g., email/SMS gateway)
b. API Layer (FastAPI) – main.py + api/*.py
- Exposes REST endpoints for plate reads, RFID scans, toll transactions, security checks, notification triggers.
c. Business Logic Layer – modules/*.py
- anpr.py: image‐to‐plate parsing
- rfid.py: RFID tag validation
- security.py: user access checks
- toll_logic.py & toll_transaction.py: pricing, transaction creation
- vehicle.py & vehicle_simulation.py: vehicle modeling/testing
- notification.py: message formatting & dispatch
- sql.py: data‐access functions (CRUD in PostgreSQL)
- logger.py: centralized logger configuration & writes
d. Configuration Subsystem – configs/config.json, logger.ini, system.ini
e. Persistence Layer – PostgreSQL Database
f. Logging Subsystem – logs/… (alert_logs, plate_logs, rfid_logs, txn_logs, general_logs)
g. Deployment – Uvicorn ASGI server

##### Data Flows & Interactions
1. ANPR camera → HTTP POST /plate endpoint → api/plate_routes.py
2. Route handler calls modules/anpr.py → plate number
3. modules/security.py validates vehicle/user
4. modules/toll_logic.py computes toll, modules/sql.py persists transaction to PostgreSQL
5. modules/notification.py sends out alerts via configured channels
6. All steps log to modules/logger.py → rolling log files

##### Architectural Patterns & Design Principles
- Layered architecture: separation of concerns between API, business logic, data access
- Config‐driven: behavior controlled by configs under configs/
- Modular code: each domain function in its own module for testability & maintenance
- File‐based logging per concern for auditability

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    subgraph "External Systems"
        Camera["ANPR Camera"]:::external
        Reader["RFID Reader"]:::external
    end

    %% API Layer
    subgraph "API Layer"
        PlateRoute["/plate (api/plate_routes.py)"]:::api
        RFIDRoute["/rfid (api/rfid_routes.py)"]:::api
        TollRoute["/toll (api/toll_routes.py)"]:::api
        SecurityRoute["/security (api/security_routes.py)"]:::api
        NotificationRoute["/notification (api/notification_routes.py)"]:::api
        VehicleRoute["/vehicle (api/vehicle_routes.py)"]:::api
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        Anpr["ANPR Parser (modules/anpr.py)"]:::business
        RfidMod["RFID Validator (modules/rfid.py)"]:::business
        SecMod["Security Checks (modules/security.py)"]:::business
        TollLogic["Toll Logic (modules/toll_logic.py)"]:::business
        TollTrans["Toll Transaction (modules/toll_transaction.py)"]:::business
        NotificationMod["Notification Dispatch (modules/notification.py)"]:::business
        VehicleMod["Vehicle Model (modules/vehicle.py)"]:::business
        VehicleSim["Vehicle Simulation (modules/vehicle_simulation.py)"]:::business
        SqlMod["SQL Access (modules/sql.py)"]:::business
        LoggerMod["Logger Config (modules/logger.py)"]:::business
        AlertsMod["Alerts Handling (modules/alerts.py)"]:::business
    end

    %% Data Persistence and External Services
    DB[(PostgreSQL)]:::db
    NotifGateway["Notification Gateway"]:::external
    Logs["Log Storage\n(plate, rfid, txn, alert, general)"]:::config
    Configs["Configs\n(config.json, logger.ini, system.ini)"]:::config

    %% Data Flows
    Camera -->|"HTTP/JSON"| PlateRoute
    Reader -->|"HTTP/JSON"| RFIDRoute

    PlateRoute -->|"calls"| Anpr
    RFIDRoute -->|"calls"| RfidMod
    SecurityRoute -->|"calls"| SecMod
    TollRoute -->|"calls"| TollLogic
    TollRoute -->|"calls"| TollTrans
    NotificationRoute -->|"calls"| NotificationMod
    VehicleRoute -->|"calls"| VehicleMod

    Anpr --> SecMod
    RfidMod --> SecMod
    SecMod --> TollLogic
    TollLogic --> TollTrans
    TollTrans --> SqlMod
    SqlMod -->|"SQL"| DB

    NotificationMod -->|"send"| NotifGateway

    %% Logging flows
    Anpr --> LoggerMod
    RfidMod --> LoggerMod
    SecMod --> LoggerMod
    TollLogic --> LoggerMod
    TollTrans --> LoggerMod
    NotificationMod --> LoggerMod
    VehicleMod --> LoggerMod
    AlertsMod --> LoggerMod
    LoggerMod --> Logs

    %% Config flows
    Configs -.-> PlateRoute
    Configs -.-> Anpr
    Configs -.-> SqlMod
    Configs -.-> LoggerMod

    %% Click Events
    click PlateRoute "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/api/plate_routes.py"
    click RFIDRoute "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/api/rfid_routes.py"
    click TollRoute "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/api/toll_routes.py"
    click SecurityRoute "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/api/security_routes.py"
    click NotificationRoute "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/api/notification_routes.py"
    click VehicleRoute "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/api/vehicle_routes.py"
    click Anpr "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/modules/anpr.py"
    click RfidMod "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/modules/rfid.py"
    click SecMod "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/modules/security.py"
    click TollLogic "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/modules/toll_logic.py"
    click TollTrans "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/modules/toll_transaction.py"
    click NotificationMod "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/modules/notification.py"
    click VehicleMod "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/modules/vehicle.py"
    click VehicleSim "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/modules/vehicle_simulation.py"
    click SqlMod "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/modules/sql.py"
    click LoggerMod "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/modules/logger.py"
    click AlertsMod "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/modules/alerts.py"
    click Configs "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/configs/config.json"
    click Logs "https://github.com/zain-ul-abdin45/anpr-toll-processing/blob/main/logs/plate_logs/plate_logs.log"
    classDef external fill:#DDA0DD,stroke:#884EA0,color:#000
    classDef api fill:#ADD8E6,stroke:#1B4F72,color:#000
    classDef business fill:#90EE90,stroke:#145A32,color:#000
    classDef db fill:#FFA500,stroke:#A04000,color:#000
    classDef config fill:#D3D3D3,stroke:#7F8C8D,color:#000
```
