# farhaouiayoub/mini_projet_flask_ayoub-farhaoui-idai architecture

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

- Interactive diagram: https://gitdiagram.com/farhaouiayoub/mini_projet_flask_ayoub-farhaoui-idai
- Repository: https://github.com/farhaouiayoub/mini_projet_flask_ayoub-farhaoui-idai

## Overview

##### Main Components
- Application Entry Point: app.py – This is where the Flask application is initialized and started.
- Configuration: config.py – Contains settings such as SECRET_KEY, DATABASE_URL, SESSION_TYPE, and CACHE_TYPE.
- Models: The "models" directory, mainly user.py, where the data model (e.g., user schema) is defined with SQLite as the default database.
- Controllers: The "controllers" directory that holds business logic, especially in auth_controller.py for handling authentication tasks.
- Views/Routes: The "views" directory includes auth_views.py that maps routes to controller actions and renders responses.
- Templates: The "templates" directory contains HTML files (base.html, login.html, register.html, profile.html, edit_profile.html) responsible for rendering the user interface.
- Static Resources: The "static" directory holds assets like CSS (style.css) and JavaScript (script.js) to support client-side interactions.
- Utilities: The "utils" folder provides helper functionalities (e.g., decorators for route protection with login_required and cache management).
- Session Management: Although integrated via Flask-Session, the “flask_session” directory reflects the file-based session storage.
- Database: The "instance" directory includes SQLite database file (app.db).

##### Relationships and Interactions
- The Web Browser (Client) sends HTTP requests to the Flask Application via different URLs (e.g., /login, /register, /profile).
- The Flask Application (app.py) handles incoming requests by routing them to the appropriate view functions defined in the views.
- View functions call the corresponding controller functions (from controllers/auth_controller.py) to process business logic.
- Controllers interact with the models (in models/user.py) to perform database operations (such as creating users, hashing passwords, and retrieving user info).
- Utilities (in utils/decorators.py and utils/cache.py) provide cross-cutting concerns like route protection and caching to optimize performance.
- The configuration parameters (from config.py) ensure that sessions (managed by Flask-Session) are correctly handled using a file system-based session store.
- Finally, the rendered templates combine with static assets to produce the final HTML sent back to the client.

##### Architectural Patterns and Design Principles
- Modularity: Separation of concerns is clear with dedicated directories for models, controllers, views, templates, and utilities.
- MVC-like Separation: While Flask doesn’t enforce a strict MVC pattern, controllers (for business logic), views (for request routing), and templates (for presentation) mimic this design.
- Security Practices: Usage of password hashing (Werkzeug), session management with expiration, and route protection using custom decorators.
- Caching Pattern: Use of a simple caching mechanism to store frequently accessed user data to reduce database hits.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    A["Client Browser"]:::frontend

    %% Flask Application Layer
    subgraph "Flask Application"
        B["Flask App (app.py)"]:::backend
        C["Configuration (config.py)"]:::backend
        D["Views (auth_views.py)"]:::backend
        E["Controllers (auth_controller.py)"]:::backend
        F["Models (user.py)"]:::backend
        G["Utilities (decorators & cache)"]:::backend
    end

    %% Frontend Assets
    subgraph "Frontend Assets"
        H["Templates (templates/)"]:::frontend
        I["Static Files (static/)"]:::frontend
    end

    %% Infrastructure
    subgraph "Infrastructure"
        J["Session Store (flask_session/)"]:::infrastructure
        K["Database (app.db)"]:::infrastructure
    end

    %% Connections
    A -->|"HTTP_request"| B
    B -->|"loads_config"| C
    B -->|"manages_session"| J
    B -->|"routes"| D
    D -->|"calls"| E
    E -->|"CRUD_ops"| F
    F -->|"reads/writes"| K
    K -->|"returns_data"| F
    E -->|"uses_helpers"| G
    F -->|"returns_result"| E
    D -->|"renders"| H
    H -->|"includes_static"| I
    I -->|"delivers_assets"| A

    %% Click Events
    click B "https://github.com/farhaouiayoub/mini_projet_flask_ayoub-farhaoui-idai/blob/main/app.py"
    click C "https://github.com/farhaouiayoub/mini_projet_flask_ayoub-farhaoui-idai/blob/main/config.py"
    click F "https://github.com/farhaouiayoub/mini_projet_flask_ayoub-farhaoui-idai/blob/main/models/user.py"
    click E "https://github.com/farhaouiayoub/mini_projet_flask_ayoub-farhaoui-idai/blob/main/controllers/auth_controller.py"
    click D "https://github.com/farhaouiayoub/mini_projet_flask_ayoub-farhaoui-idai/blob/main/views/auth_views.py"
    click H "https://github.com/farhaouiayoub/mini_projet_flask_ayoub-farhaoui-idai/tree/main/templates/"
    click I "https://github.com/farhaouiayoub/mini_projet_flask_ayoub-farhaoui-idai/tree/main/static/"
    click G "https://github.com/farhaouiayoub/mini_projet_flask_ayoub-farhaoui-idai/tree/main/utils/"
    click J "https://github.com/farhaouiayoub/mini_projet_flask_ayoub-farhaoui-idai/tree/main/flask_session/"
    click K "https://github.com/farhaouiayoub/mini_projet_flask_ayoub-farhaoui-idai/blob/main/instance/app.db"

    %% Styles
    classDef frontend fill:#BDE0FE,stroke:#333,stroke-width:2px;
    classDef backend fill:#F2D7D5,stroke:#333,stroke-width:2px;
    classDef infrastructure fill:#D5F5E3,stroke:#333,stroke-width:2px;
```
