# aresu-1704/tomato-disease-detect architecture

> Architecture diagram of the GitHub repository aresu-1704/tomato-disease-detect, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aresu-1704/tomato-disease-detect
- Repository: https://github.com/aresu-1704/tomato-disease-detect

## Overview

##### Project type and purpose
- This is a full-stack mobile application for tomato leaf disease detection.
- Frontend: Flutter app (Android & iOS) that captures or selects leaf images, handles authentication, and displays prediction results & history.
- Backend: FastAPI service hosting YOLO deep-learning models (YOLOv8–YOLOv12 Nano) for object detection and a CNN for disease classification. It also manages user accounts, OTP, and prediction history persisted in PostgreSQL.

##### File structure
- Top-level folders:
- frontend – Flutter project with Android, iOS, Dart code (models, services, view_models, views)
- backend – FastAPI app structured by controllers, services, repositories, models, utils, ai_models
- database – SQL schema file
- Backend breakdown:
- app/controllers – HTTP endpoints (auth, predict, disease_history)
- app/services & IR interfaces – business logic
- app/repositories & IR interfaces – data access to PostgreSQL
- app/ai_models – YOLO model weights and inference code
- app/utils – connections (PostgreSQL, Redis for OTP), hashing, email OTP senders
- executor_pool – parallel model inference
- config.py / main.py – app configuration & server startup
- Frontend breakdown:
- lib/constants – API base URL
- lib/models, repositories, services – data layer & HTTP calls
- lib/view_models – state management for each screen
- lib/views – UI screens for auth, camera, results, history
- Config & deployment files:
- backend/requirements.txt, Docker-style scripts can be inferred
- frontend/pubspec.yaml, Android/iOS native build files

##### README
- Confirms two main components: Flutter mobile UI and FastAPI+YOLO backend
- Lists API endpoints for authentication, prediction, history
- Mentions PostgreSQL, Redis (implied by OTP storage), Uvicorn, Pydantic
- Shows swagger UI for API

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend" 
        FlutterApp["Flutter Mobile App"]:::frontend
        APIConstants["API Constants"]:::frontend
        DataModels["Data Models"]:::frontend
        Repositories["Disease History Repository"]:::frontend
        ServicesAuth["Auth Service"]:::frontend
        ServicesPredict["Predict Service"]:::frontend
        ServicesHistory["History Service"]:::frontend
        ViewModels["View Models"]:::frontend
        UIViews["UI Screens"]:::frontend
    end

    %% Backend API Layer
    subgraph "Backend API" 
        Main["main.py"]:::backend
        Config["config.py"]:::backend
        AuthController["Auth Controller"]:::backend
        PredictController["Predict Controller"]:::backend
        HistoryController["Disease History Controller"]:::backend
        BackendServices["Business Services"]:::backend
        BackendRepos["Data Repositories"]:::backend
        BackendModels["Pydantic/ORM Models"]:::backend
    end

    %% Inference Engine
    subgraph "Inference Engine"
        ExecutorPool["Executor Pool"]:::inference
        AIModels["YOLO & CNN Models"]:::inference
        AIScripts["Support Scripts"]:::inference
    end

    %% Data Stores
    subgraph "Data Stores"
        PostgreSQL["PostgreSQL"]:::datastore
        Redis["Redis (OTP Store)"]:::datastore
        MediaStorage["Media Storage"]:::datastore
        DBSchema["DB Schema"]:::datastore
    end

    %% External Services
    subgraph "External Services"
        EmailService["Email SMTP Service"]:::external
    end

    %% Connections: Frontend → Backend
    FlutterApp -->|"Auth Requests\n(Payload: JSON)"| AuthController
    FlutterApp -->|"POST /predict\n(Image)"| PredictController
    FlutterApp -->|"GET /history\n(JSON)"| HistoryController
    AuthController -->|"Delegates"| BackendServices
    PredictController -->|"Delegates"| BackendServices
    HistoryController -->|"Delegates"| BackendServices

    %% Backend internal flows
    Main --> Config
    Main --> AuthController
    Main --> PredictController
    Main --> HistoryController
    BackendServices --> BackendRepos
    BackendServices --> PostgreSQL
    BackendRepos --> PostgreSQL
    AuthController --> Redis
    AuthController --> EmailService
    PredictController --> ExecutorPool
    PredictController --> MediaStorage
    ExecutorPool --> AIModels
    AIModels --> ExecutorPool
    AIScripts --> AIModels
    DBSchema -.-> PostgreSQL

    %% Click Events: Frontend
    click FlutterApp "https://github.com/aresu-1704/tomato-disease-detect/blob/main/frontend/lib/main.dart"
    click APIConstants "https://github.com/aresu-1704/tomato-disease-detect/blob/main/frontend/lib/constants/api_constant.dart"
    click DataModels "https://github.com/aresu-1704/tomato-disease-detect/tree/main/frontend/lib/models"
    click Repositories "https://github.com/aresu-1704/tomato-disease-detect/blob/main/frontend/lib/repositories/disease_history_repository.dart"
    click ServicesAuth "https://github.com/aresu-1704/tomato-disease-detect/blob/main/frontend/lib/services/auth_service.dart"
    click ServicesPredict "https://github.com/aresu-1704/tomato-disease-detect/blob/main/frontend/lib/services/predict_service.dart"
    click ServicesHistory "https://github.com/aresu-1704/tomato-disease-detect/blob/main/frontend/lib/services/disease_history_service.dart"
    click ViewModels "https://github.com/aresu-1704/tomato-disease-detect/tree/main/frontend/lib/view_models"
    click UIViews "https://github.com/aresu-1704/tomato-disease-detect/tree/main/frontend/lib/views"

    %% Click Events: Backend
    click Main "https://github.com/aresu-1704/tomato-disease-detect/blob/main/backend/main.py"
    click Config "https://github.com/aresu-1704/tomato-disease-detect/blob/main/backend/config.py"
    click AuthController "https://github.com/aresu-1704/tomato-disease-detect/blob/main/backend/app/controllers/auth_controller.py"
    click PredictController "https://github.com/aresu-1704/tomato-disease-detect/blob/main/backend/app/controllers/predict_controller.py"
    click HistoryController "https://github.com/aresu-1704/tomato-disease-detect/blob/main/backend/app/controllers/disease_history_controller.py"
    click BackendServices "https://github.com/aresu-1704/tomato-disease-detect/tree/main/backend/app/services"
    click BackendRepos "https://github.com/aresu-1704/tomato-disease-detect/tree/main/backend/app/repositories"
    click BackendModels "https://github.com/aresu-1704/tomato-disease-detect/tree/main/backend/app/models"

    %% Click Events: Inference Engine
    click ExecutorPool "https://github.com/aresu-1704/tomato-disease-detect/blob/main/backend/app/executor_pool.py"
    click AIModels "https://github.com/aresu-1704/tomato-disease-detect/tree/main/backend/app/ai_models"
    click AIScripts "https://github.com/aresu-1704/tomato-disease-detect/tree/main/backend/app/src"

    %% Click Events: Data Stores & External
    click PostgreSQL "https://github.com/aresu-1704/tomato-disease-detect/blob/main/backend/app/utils/database/postgreSQL_connection.py"
    click Redis "https://github.com/aresu-1704/tomato-disease-detect/blob/main/backend/app/utils/otp_storage/start_redis.py"
    click MediaStorage "https://github.com/aresu-1704/tomato-disease-detect/tree/main/backend/app/media/image_history"
    click DBSchema "https://github.com/aresu-1704/tomato-disease-detect/blob/main/database/database.sql"
    click EmailService "https://github.com/aresu-1704/tomato-disease-detect/blob/main/backend/app/utils/send_otp/send_OTP_to_email.py"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#2980B9,stroke-width:1px;
    classDef backend fill:#D5F5E3,stroke:#27AE60,stroke-width:1px;
    classDef inference fill:#FDEBD0,stroke:#D35400,stroke-width:1px;
    classDef datastore fill:#FCF3CF,stroke:#B7950B,stroke-width:1px;
    classDef external fill:#F5EEF8,stroke-dasharray: 5 5,stroke:#884EA0,stroke-width:1px;
```
