# sivagirivisakan/trail-app architecture

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

- Interactive diagram: https://gitdiagram.com/sivagirivisakan/trail-app
- Repository: https://github.com/sivagirivisakan/trail-app

## Overview

##### Main Components
- Frontend: This includes all static assets (CSS, JavaScript, fonts, images) and HTML templates. Notice the "static" folder for assets and the "templates" folder which holds various layout and page files.
- Backend (Flask Application): The core of the app is built using Flask. The main application is defined in app.py with additional business logic split across directories such as "controllers", "views", and "helpers".
- Controllers and Views: The “controllers” directory houses the API endpoints (e.g., API, auth, organisation) which handle incoming requests. The “views” directory further handles the routing for dashboards, organisations, and projects.
- Database Layer: There are dual database components:
- MySQL – for general application data and mutable records.
- ClickHouse – for logging and analytics; especially dealing with immutable and high-query-frequency data.
- Caching: Redis is used to provide a caching layer, as noted in the README.
- Configuration & Environment: Configurations are handled from config.py, .flaskenv, and Docker-related files (Dockerfile, docker-compose.yml) indicate the deployment strategy.

- User actions (e.g., log-in, page interaction) send requests to the Flask server.
- Flask processes these requests with controllers (ex: controllers/api.py for event tracking and controllers/auth.py for authentication) that then interact with controllers/views.
- The backend makes calls to helper modules (e.g., helpers/db.py) to handle business logic related to database interactions.
- Data Storage and Analytics:
- MySQL handles mutable data such as user details or organisational configurations.
- ClickHouse is used for writing and querying high-volume event logs, as per the README explanation (capturing immutable data for analytics).
- Redis acts as a caching layer to improve performance in real-time dashboard updates.

##### Architectural Patterns and Design Principles
- MVC / Separation of Concerns: The code is separated into controllers, views, and templates for clear responsibilities.
- API-Driven Design: Controllers handle API routes (especially for event tracking) that update databases.
- Layered Architecture: Distinguish between presentation (templates & static), application logic (Flask app, controllers, views), and data layers (MySQL, ClickHouse, Redis).

##### Technologies and Frameworks
- Flask as the web framework.
- MySQL and ClickHouse as databases differentiated by use case (OLTP vs. OLAP).
- Redis for caching.
- Frontend frameworks and libraries: Argon Dashboard assets, Bootstrap, and custom JS/CSS are used for the UI.
- Docker for containerization and orchestration, as evidenced by Dockerfile, .dockerignore, and docker-compose.yml.

## Diagram (Mermaid)

```mermaid
flowchart TD
    CB("Client/Browser"):::client

    subgraph "Presentation Layer"
        FE("Static Assets"):::frontend
        TE("HTML Templates"):::frontend
    end

    subgraph "Application Layer"
        BA("Flask Application"):::backend
        subgraph "Controllers & Views"
            CT("Controllers"):::backend
            VW("Views"):::backend
        end
        HM("Helper Modules"):::backend
        subgraph "Configuration"
            CP("config.py"):::backend
            FL(".flaskenv"):::backend
        end
    end

    subgraph "Data Layer"
        DB1("MySQL Database"):::database
        DB2("ClickHouse Database"):::database
        RED("Redis Cache"):::database
    end

    subgraph "Deployment"
        DF("Dockerfile"):::deployment
        DC("docker-compose.yml"):::deployment
        DI(".dockerignore"):::deployment
        DOCK("Docker Container"):::deployment
    end

    %% Client to Application Flow
    CB -->|"HTTP_Request"| BA
    BA -->|"Serves"| FE
    BA -->|"Renders"| TE
    TE -->|"Delivers"| CB

    %% Application Layer internal interactions
    BA --> CT
    BA --> VW
    BA --> HM
    CP -->|"Sets"| BA
    FL -->|"Sets"| BA
    CT -->|"Routes"| VW

    %% Interactions with Data Layer
    CT -->|"Writes_UserData"| DB1
    CT -->|"Writes_Analytics"| DB2
    CT -->|"Caches"| RED
    HM -->|"Accesses"| DB1

    %% Deployment flows
    DF -->|"Deploys"| DOCK
    DC -->|"Deploys"| DOCK
    DI -->|"Deploys"| DOCK
    DOCK -->|"Hosts"| BA

    %% Click Events
    click FE "https://github.com/sivagirivisakan/trail-app/tree/develop/static"
    click TE "https://github.com/sivagirivisakan/trail-app/tree/develop/templates"
    click BA "https://github.com/sivagirivisakan/trail-app/blob/develop/app.py"
    click CP "https://github.com/sivagirivisakan/trail-app/blob/develop/config.py"
    click FL "https://github.com/sivagirivisakan/trail-app/blob/develop/.flaskenv"
    click CT "https://github.com/sivagirivisakan/trail-app/tree/develop/controllers"
    click VW "https://github.com/sivagirivisakan/trail-app/tree/develop/views"
    click HM "https://github.com/sivagirivisakan/trail-app/tree/develop/helpers"
    click DB1 "https://github.com/sivagirivisakan/trail-app/tree/develop/database_scripts/sql"
    click DB2 "https://github.com/sivagirivisakan/trail-app/tree/develop/database_scripts/clickhouse"
    click DF "https://github.com/sivagirivisakan/trail-app/tree/develop/Dockerfile"
    click DC "https://github.com/sivagirivisakan/trail-app/blob/develop/docker-compose.yml"
    click DI "https://github.com/sivagirivisakan/trail-app/blob/develop/.dockerignore"

    %% Styling
    classDef client fill:#FFEEAD,stroke:#333,stroke-width:2px;
    classDef frontend fill:#C5E1A5,stroke:#333,stroke-width:2px;
    classDef backend fill:#81D4FA,stroke:#333,stroke-width:2px;
    classDef database fill:#FFE082,stroke:#333,stroke-width:2px;
    classDef deployment fill:#FFAB91,stroke:#333,stroke-width:2px;
```
