# chetan0402/tidytrack architecture

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

- Interactive diagram: https://gitdiagram.com/chetan0402/tidytrack
- Repository: https://github.com/chetan0402/tidytrack

## Overview

##### Project type and purpose
- This is a monolithic, full-stack web application built with FastAPI that also exposes a REST/JSON API consumed by an Android client (app-release.apk).
- It provides user-facing HTML pages (via Jinja2 templates in `templates/`) for web users (report generation, dashboards, public pages) and programmatic endpoints for the Android app (BSNL OTP authentication, data submission, version checks).

##### Key directories/files and their roles
- fastapi_app.py: entry point for the FastAPI application.
- database.py: database connection / session management (MySQL).
- models.py: ORM / database table definitions.
- schema.py: Pydantic request/response schemas.
- constants/: domain constants (report types, location data, tags).
- settings/config.py: application configuration (DB credentials, OTP limits, template IDs).
- templates/: Jinja2 templates + static assets (CSS, JS, images, mail php).
- LEARNING.md: possibly docs/training material.
- app-release.apk: compiled Android client that hits the API.
- utils.py: shared utility functions.
- requirements.txt: Python dependencies.

##### Architectural pattern
- MVC-style:
- Models ↔ models.py
- Views ↔ templates/ + static assets
- Controllers ↔ fastapi_app.py route handlers
- Pydantic for request validation and response modeling (schema.py).
- Central configuration (settings/config.py) injected into the app.
- External integration with BSNL OTP service via HTTP calls using credentials/config.
- Single relational database (MySQL) backend.

##### Main components and interactions
A. Clients
1. Web browser
- Requests HTML pages (GET /, /generate_report, dashboards, error pages).
- Submits forms (POST /generate_report).
2. Android app
- Calls REST endpoints for OTP generation/verification.
- Checks version (currentVersion vs latestAppLocalPath).
- Submits report data via JSON.
B. API / Web server (FastAPI)
- Routes defined in fastapi_app.py.
- Uses Pydantic schemas (schema.py) to parse/validate.
- Business logic uses utils.py and constants/.
- Renders templates using Jinja2.
- Reads settings from settings/config.py.
C. Database (MySQL)
- Stores user submissions, OTP objects, report logs, ban counters.
- Accessed via database.py session and models.py definitions.
D. External Service
- BSNL OTP SMS service for sending/validating OTPs.
- Configured via auth, templateID, Entity_ID.
E. Static assets
- CSS/JS/images in templates/assets served by FastAPI’s static file mount.

- Web Browser
- Android Client
- FastAPI Server
– Route Handlers
– Pydantic Schemas
– Business Logic (utils, constants)
– Template Engine
– Static File Server
- MySQL Database
- BSNL OTP Service
- Web Browser → FastAPI: HTTP GET/POST for HTML
- FastAPI → Templates: inject data → HTML → Browser
- Android → FastAPI: REST API calls (JSON)
- FastAPI → MySQL: SQL queries via ORM
- FastAPI → BSNL OTP Service: HTTP POST for SMS
c. Technologies:
- FastAPI (Python)
- Jinja2 templates, static assets (CSS/JS)
- Pydantic for schema validation
- SQLAlchemy or direct MySQL driver
- External SMS HTTP API
d. Call out config:
- settings/config.py drives DB connection, OTP policies, versioning

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Clients" 
        Browser["Web Browser"]:::client
        Android["Android App"]:::client
    end

    subgraph "FastAPI Server"
        entry["fastapi_app.py"]:::server
        schema["schema.py"]:::server
        utils["utils.py"]:::server
        subgraph "Configuration"
            config["settings/config.py"]:::config
        end
        subgraph "Domain Constants"
            rt["ReportType.py"]:::config
            lm["location_mess.json"]:::config
            lr["location_room.json"]:::config
            tg["tags.py"]:::config
        end
        subgraph "Data Layer"
            dbconn["database.py"]:::data
            models["models.py"]:::data
        end
        subgraph "Views & Assets"
            templates["templates/*.html"]:::view
            css["css/"]:::view
            js["js/"]:::view
            images["images/"]:::view
            fonts["fonts/"]:::view
            mailphp["mail.php"]:::view
        end
    end

    db["MySQL Database"]:::db
    otp["BSNL OTP Service"]:::external

    Browser -->|HTTP/HTML| entry
    entry -->|renders| templates
    entry -->|serves| css
    entry -->|serves| js
    entry -->|serves| images
    entry -->|serves| fonts
    entry -->|serves| mailphp
    Android -->|HTTP/JSON| entry
    entry -->|validates| schema
    entry -->|calls| utils
    entry -->|loads| config
    entry -->|loads| rt
    entry -->|loads| lm
    entry -->|loads| lr
    entry -->|loads| tg
    entry -->|manages session| dbconn
    dbconn -->|defines| models
    entry -->|SQL via ORM| db
    entry -->|HTTP/JSON| otp

    click entry "https://github.com/chetan0402/tidytrack/blob/master/fastapi_app.py"
    click schema "https://github.com/chetan0402/tidytrack/blob/master/schema.py"
    click utils "https://github.com/chetan0402/tidytrack/blob/master/utils.py"
    click config "https://github.com/chetan0402/tidytrack/blob/master/settings/config.py"
    click rt "https://github.com/chetan0402/tidytrack/blob/master/constants/ReportType.py"
    click lm "https://github.com/chetan0402/tidytrack/blob/master/constants/location_mess.json"
    click lr "https://github.com/chetan0402/tidytrack/blob/master/constants/location_room.json"
    click tg "https://github.com/chetan0402/tidytrack/blob/master/constants/tags.py"
    click dbconn "https://github.com/chetan0402/tidytrack/blob/master/database.py"
    click models "https://github.com/chetan0402/tidytrack/blob/master/models.py"
    click templates "https://github.com/chetan0402/tidytrack/blob/master/templates/index.html"
    click css "https://github.com/chetan0402/tidytrack/tree/master/templates/assets/css/"
    click js "https://github.com/chetan0402/tidytrack/tree/master/templates/assets/js/"
    click images "https://github.com/chetan0402/tidytrack/tree/master/templates/assets/images/"
    click fonts "https://github.com/chetan0402/tidytrack/tree/master/templates/assets/fonts/"
    click mailphp "https://github.com/chetan0402/tidytrack/blob/master/templates/assets/mail/mail.php"
    click Android "https://github.com/chetan0402/tidytrack/blob/master/app-release.apk"

    classDef client fill:#add8e6,stroke:#000
    classDef server fill:#90ee90,stroke:#000
    classDef db fill:#ffa500,stroke:#000
    classDef external fill:#d8bfd8,stroke:#000
    classDef config fill:#f0e68c,stroke:#000
    classDef data fill:#98fb98,stroke:#000
    classDef view fill:#87cefa,stroke:#000
```
