# jashmevada/mad-1-project architecture

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

- Interactive diagram: https://gitdiagram.com/jashmevada/mad-1-project
- Repository: https://github.com/jashmevada/mad-1-project

## Overview

##### Main Components
- Frontend Layer: Represent the UI aspect handled by the "templates" and "static" directories. Note that there are subdirectories within "templates" for different user roles such as influencer, sponsor, and admin, as well as different layouts and dashboards.
- Backend Layer: Center the core application logic around "app.py" and the "controllers" directory which is split into admin, auth, common, and validation functionalities. This layer processes client requests, controls application flow, and returns appropriate responses.
- Data Layer: Show the management of persistence via the "db" folder (with db.py) and "models" directory that contains entity definitions like adRequest, campaign, influencer, and sponsor. This layer underscores the use of Flask SQLAlchemy as indicated in the README.
- Utility/Configuration: Include auxiliary components like "utils.py" and configuration files (e.g., requirements.txt, .gitignore, project specific IDE configurations) that support development and deployment.

##### Relationships and Data Flow
- From the Browser (or Client) to Frontend: The client renders the HTML/CSS and executes JavaScript; data exchange is enhanced by htmx for dynamic interactions.
- Communication with the Backend: The frontend’s forms and asynchronous calls reach designated endpoints (via controllers) in the Flask app.
- Business Logic: Controllers (admin.py, auth.py, etc.) process requests, perform validations (referencing validation.py), and interact with models.
- External Libraries: Optionally include external integrations (e.g., Chart.js for dashboards) as part of the frontend analytics components.

##### Important Architectural Patterns
- Separation of Concerns: The project organizes the code into folders (controllers, models, templates) clearly segregating presentation, business logic, and data layers.
- Role-Based Modules: Distinct sections exist for different user types (admin, influencer, sponsor) which should be depicted as distinct modules with interactions toward common services.
- MVC-like Flow: While not a strict MVC framework, the division aligns closely to the Model (models), View (templates and static), and Controller (controllers) pattern ensuring maintainability.

##### Detail and Clarity
- Avoid oversimplification; capture as many core components as possible.
- That all interactions and dependencies (like validation steps, data flow between controllers and models) are clearly represented.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    Client["Client (Browser)"]:::frontend

    %% Frontend Layer
    subgraph "Frontend Layer"
        TEMPLATES["Templates Directory"]:::frontend
        STATIC["Static Assets"]:::frontend
        HTMX["htmx Library"]:::frontend
        CHARTJS["Chart.js Library"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        FLASK["Flask Application (app.py)"]:::backend
        subgraph "Controllers"
            ADMIN["Admin Controller"]:::backend
            AUTH["Auth Controller"]:::backend
            COMMON["Common Controller"]:::backend
            VALIDATION["Validation Controller"]:::backend
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        DBMODULE["Database Module (db.py)"]:::database
        subgraph "Models"
            ADREQ["adResquest Model"]:::database
            CAMPAIGN["Campaign Model"]:::database
            INFLUENCER["Influencer Model"]:::database
            SPONSOR["Sponsor Model"]:::database
            GENERAL["General Model"]:::database
        end
    end

    %% Utility / Configuration
    subgraph "Utility / Configuration"
        UTILS["Utils Module"]:::utility
        REQ["requirements.txt"]:::utility
        GIT[".gitignore"]:::utility
        IDE["IDE Configs (.idea & .vscode)"]:::utility
    end

    %% Data Flow Connections
    Client -->|"HTTP Request"| TEMPLATES
    Client -->|"HTTP Request"| STATIC
    TEMPLATES -->|"Render Request"| FLASK
    STATIC -->|"Assets Load"| FLASK
    FLASK -->|"Process Request"| ADMIN
    FLASK -->|"Process Request"| AUTH
    FLASK -->|"Process Request"| COMMON
    FLASK -->|"Process Request"| VALIDATION
    
    ADMIN -->|"DB Operations"| DBMODULE
    AUTH -->|"DB Operations"| DBMODULE
    COMMON -->|"DB Operations"| DBMODULE
    %% Assuming Validation assists controllers before DB ops
    VALIDATION -->|"Validate Data"| ADMIN
    VALIDATION -->|"Validate Data"| AUTH
    VALIDATION -->|"Validate Data"| COMMON

    DBMODULE -->|"Query Execution"| ADMIN
    DBMODULE -->|"Query Execution"| AUTH
    DBMODULE -->|"Query Execution"| COMMON

    %% Models interaction with Database Module
    ADMIN -->|"Uses Models"| ADREQ
    ADMIN -->|"Uses Models"| CAMPAIGN
    ADMIN -->|"Uses Models"| INFLUENCER
    ADMIN -->|"Uses Models"| SPONSOR
    ADMIN -->|"Uses Models"| GENERAL

    AUTH -->|"Uses Models"| ADREQ
    AUTH -->|"Uses Models"| CAMPAIGN
    AUTH -->|"Uses Models"| INFLUENCER
    AUTH -->|"Uses Models"| SPONSOR
    AUTH -->|"Uses Models"| GENERAL

    COMMON -->|"Uses Models"| ADREQ
    COMMON -->|"Uses Models"| CAMPAIGN
    COMMON -->|"Uses Models"| INFLUENCER
    COMMON -->|"Uses Models"| SPONSOR
    COMMON -->|"Uses Models"| GENERAL

    %% Response Flow
    ADMIN -->|"Response"| FLASK
    AUTH -->|"Response"| FLASK
    COMMON -->|"Response"| FLASK
    FLASK -->|"Render Response"| TEMPLATES
    TEMPLATES -->|"Rendered Page"| Client

    %% External Libraries in Frontend
    HTMX -->|"Enhances Interactions"| TEMPLATES
    CHARTJS -->|"Dashboard Analytics"| TEMPLATES

    %% Click Events
    click TEMPLATES "https://github.com/jashmevada/mad-1-project/tree/master/templates/"
    click STATIC "https://github.com/jashmevada/mad-1-project/tree/master/static/"
    click FLASK "https://github.com/jashmevada/mad-1-project/blob/master/app.py"
    click ADMIN "https://github.com/jashmevada/mad-1-project/blob/master/controllers/admin.py"
    click AUTH "https://github.com/jashmevada/mad-1-project/blob/master/controllers/auth.py"
    click COMMON "https://github.com/jashmevada/mad-1-project/blob/master/controllers/common.py"
    click VALIDATION "https://github.com/jashmevada/mad-1-project/blob/master/controllers/validation.py"
    click DBMODULE "https://github.com/jashmevada/mad-1-project/blob/master/db/db.py"
    click ADREQ "https://github.com/jashmevada/mad-1-project/blob/master/models/adResquest.py"
    click CAMPAIGN "https://github.com/jashmevada/mad-1-project/blob/master/models/campaign.py"
    click INFLUENCER "https://github.com/jashmevada/mad-1-project/blob/master/models/influencer.py"
    click SPONSOR "https://github.com/jashmevada/mad-1-project/blob/master/models/sponsor.py"
    click GENERAL "https://github.com/jashmevada/mad-1-project/blob/master/models/model.py"
    click UTILS "https://github.com/jashmevada/mad-1-project/blob/master/utils.py"
    click REQ "https://github.com/jashmevada/mad-1-project/blob/master/requirements.txt"
    click GIT "https://github.com/jashmevada/mad-1-project/blob/master/.gitignore"
    click IDE "https://github.com/jashmevada/mad-1-project/blob/master/.idea"

    %% Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:2px;
    classDef backend fill:#bbf,stroke:#333,stroke-width:2px;
    classDef database fill:#cfc,stroke:#333,stroke-width:2px;
    classDef utility fill:#fc9,stroke:#333,stroke-width:2px;
```
