# highoncarbs/hafta architecture

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

- Interactive diagram: https://gitdiagram.com/highoncarbs/hafta
- Repository: https://github.com/highoncarbs/hafta

## Overview

##### Main Components
- Client Side (Frontend):
– User Interface components rendered through HTML templates in the “app/templates” folder.
– Static assets (CSS, JavaScript files, images, and HTML component fragments) found under “app/static.”
– Frontend libraries like Bulma, Vue.js, and Buefy.
- Server Side (Backend):
– The core Flask application initialized in “app/__init__.py” and constructed modularly using Blueprints.
– Modules responsible for specific functionalities:
- Authentication (app/auth)
- Employee management (app/employee)
- Main operations (app/main)
- Master data management (app/master) for handling entities like departments, benefits, and attendance rules.
- Reporting (app/report)
- Transactions (app/transaction) handling payroll, performance, etc.
– Configuration settings in “config.py.”
– The main entry point “run.py” which starts the Flask server.
- Database Layer:
– MySQL as the backend database configured via SQLAlchemy.
– Models that represent business entities, primarily defined in various module-specific model files.
– Migration scripts maintained in the “migrations” folder using Alembic.
- Deployment & Infrastructure:
– Deployment-related configuration (like nginx-site-conf.txt) and service definitions (hafta.service).
– Possible role of external tools (e.g., Nginx as a reverse proxy).

##### Out Relationships & Interactions
- How requests flow from the client (web browser) to the Flask server.
- That each Blueprint (auth, employee, etc.) handles specific URL routes (visible in “routes.py” files) and interacts with the underlying database via SQLAlchemy.
- Connection from the Flask application to the MySQL database and how migrations fit into this architecture.
- External dependencies: client-side framework libraries (Vue.js, Bulma), and any deployment tools (Nginx).

##### Architectural Patterns and Important Details
- Modular design provided by Flask Blueprints – each major function (auth, employee, master, report, transaction) is encapsulated into its own module.
- That the project uses Model-View-Controller (MVC) or rather a similar separation; the “models” (both in app/model.py and module-specific model files) handle data, “views” are represented by the HTML templates and routes, and the “controllers” are the logic in the route functions.
- Components such as:
– Controller Layer: route handlers in each module (e.g., app/auth/routes.py, app/main/routes.py).
– Views: HTML templates in “app/templates.”
– Models: Data models in “app/master/model.py”, “app/employee/model.py”, etc.
– Migration and configuration: “migrations” directory and “config.py.”

##### Relevant Technologies
- Python3 and Flask for the backend.
- SQLAlchemy for data modeling.
- Alembic for database migrations.
- MySQL as the database.
- Frontend technologies: Bulma (CSS), Vue.js (JS framework), and Buefy.
- Additional files such as nginx-site-conf.txt suggest a recommendation for using Nginx in production.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Client Side (Frontend)"
        Browser["Web Browser"]:::frontend
        Templates["HTML Templates"]:::frontend
        Static["Static Assets"]:::frontend
    end

    %% Backend Layer
    subgraph "Server Side (Backend)"
        FlaskApp["Flask Core App"]:::backend
        Config["Configuration (config.py)"]:::backend
        Entry["Entry Point (run.py)"]:::backend
        subgraph "Blueprint Modules"
            Auth["Authentication Module"]:::backend
            Employee["Employee Management Module"]:::backend
            MainModule["Main Operations Module"]:::backend
            Master["Master Data Module"]:::backend
            ReportMod["Reporting Module"]:::backend
            Transaction["Transactions Module"]:::backend
        end
        Migration["Database Migrations"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        DB["MySQL Database (via SQLAlchemy)"]:::database
    end

    %% Deployment & Infrastructure
    subgraph "Deployment & Infrastructure"
        Nginx["Nginx Config"]:::deployment
        Service["Service Definition"]:::deployment
    end

    %% Connections: Frontend -> Backend
    Browser -->|"HTTP_Request"| FlaskApp
    FlaskApp -->|"Uses_Config"| Config
    FlaskApp -->|"Starts"| Entry
    FlaskApp -->|"Routes_to"| Auth
    FlaskApp -->|"Routes_to"| Employee
    FlaskApp -->|"Routes_to"| MainModule
    FlaskApp -->|"Routes_to"| Master
    FlaskApp -->|"Routes_to"| ReportMod
    FlaskApp -->|"Routes_to"| Transaction
    FlaskApp -->|"Renders"| Templates
    FlaskApp -->|"Serves"| Static

    %% Connections: Backend Modules -> Database
    Auth -->|"DB_Query"| DB
    Employee -->|"DB_Query"| DB
    MainModule -->|"DB_Query"| DB
    Master -->|"DB_Query"| DB
    ReportMod -->|"DB_Query"| DB
    Transaction -->|"DB_Query"| DB
    Migration -->|"Manages_Migrations"| DB

    %% Connections: Deployment & Infrastructure
    FlaskApp -->|"Reverse_Proxy"| Nginx
    Nginx -->|"Routes_to"| FlaskApp
    Service -->|"Manages"| FlaskApp

    %% Styles
    classDef frontend fill:#a8d8ea,stroke:#333,stroke-width:2px;
    classDef backend fill:#dcedc1,stroke:#333,stroke-width:2px;
    classDef database fill:#ffcccb,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
    classDef deployment fill:#fceabb,stroke:#333,stroke-width:2px;

    %% Click Events
    click Templates "https://github.com/highoncarbs/hafta/tree/master/app/templates"
    click Static "https://github.com/highoncarbs/hafta/tree/master/app/static"
    click FlaskApp "https://github.com/highoncarbs/hafta/blob/master/app/__init__.py"
    click Auth "https://github.com/highoncarbs/hafta/tree/master/app/auth"
    click Employee "https://github.com/highoncarbs/hafta/tree/master/app/employee"
    click MainModule "https://github.com/highoncarbs/hafta/tree/master/app/main"
    click Master "https://github.com/highoncarbs/hafta/tree/master/app/master"
    click ReportMod "https://github.com/highoncarbs/hafta/tree/master/app/report"
    click Transaction "https://github.com/highoncarbs/hafta/tree/master/app/transaction"
    click Config "https://github.com/highoncarbs/hafta/blob/master/config.py"
    click Entry "https://github.com/highoncarbs/hafta/blob/master/run.py"
    click Migration "https://github.com/highoncarbs/hafta/tree/master/migrations"
    click Nginx "https://github.com/highoncarbs/hafta/blob/master/nginx-site-conf.txt"
    click Service "https://github.com/highoncarbs/hafta/blob/master/hafta.service"
```
