# fkdia23/mini-projet_fastapi architecture

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

- Interactive diagram: https://gitdiagram.com/fkdia23/mini-projet_fastapi
- Repository: https://github.com/fkdia23/mini-projet_fastapi

## Overview

##### Main components
- API Layer (Presentation): This is defined by the "app/api" directory, which includes endpoint modules (articles.py, auth.py, users.py). This part is where external requests enter the system.
- Business Logic / CRUD Layer: Located in "app/crud", these components encapsulate database operations for articles and users.
- Data Models: Under "app/models" (and a top-level models.py), these files define the SQLAlchemy models such as Article and User, as well as the database configuration (see database.py).
- Schemas: In "app/schemas", these define the Pydantic models for data validation and serialization (e.g., article.py, token.py, user.py).
- Configuration & Dependencies: "app/config.py", "app/dependencies.py", and "app/utils" (including security operations) offer support for project configuration, dependency injection, and utility functions.
- Web Server Entrypoint: "app/main.py" is the entrypoint where the FastAPI application is initialized and configured.
- Database Migrations: The "alembic" directory shows migration scripts, configuration files (alembic.ini, alembic/env.py, versions folder) that ensure database evolution is tracked properly.
- Persistent Storage: The presence of "app.db" indicates that the application is using a local database (likely SQLite).

##### Relationships and interactions
- The API Layer receives HTTP requests and calls into the CRUD layer which then interacts with the Data Models to perform database operations.
- CRUD functions interact with the database (through SQLAlchemy models defined in "app/models") and return data. This data is validated/serialized via the Schemas layer before sending a response.
- The utility and dependency modules, such as those handling security (from app/utils/security.py) and dependency injection (from app/dependencies.py), support both API and CRUD operations.
- Alembic manages migrations to keep the database schema synchronized with the models in "app/models".

##### Design patterns and principles
- Layered (or N-tier) architecture: separating API endpoints, business logic (CRUD), models/schemas, and configuration.
- Use of dependency injection for modularizing configuration and security.
- Clear separation of controllers (API endpoints) from data access logic (CRUD) and data definitions (Models/Schemas).

##### Relevant technologies/frameworks
- FastAPI for the web framework and handling API requests.
- SQLAlchemy (as seen in the models and CRUD operations) as the ORM interface to the database.
- Alembic for handling database migrations.
- Pydantic for defining schemas and validating data.
- Possibly SQLite, as suggested by the "app.db" file.

##### Final checklist
- Dependency relationships (for example, API relies on CRUD, which in turn relies on Models and the Database).
- Annotations or notes that mention frameworks and libraries like FastAPI, SQLAlchemy, Pydantic, and Alembic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    userReq["User Request"]:::external
    userResp["User Response"]:::external

    subgraph "Presentation Layer"
        mainEntrypoint["Web Server Entrypoint"]:::presentation
        apiLayer["API Layer"]:::presentation
    end

    subgraph "Business Logic"
        crudOps["CRUD Operations"]:::business
    end

    subgraph "Data Layer"
        modelsDir["Data Models"]:::data
        coreModels["Core Models"]:::data
        schemas["Schemas"]:::data
        db["Persistent Storage (Database)"]:::data
        migrations["Database Migrations"]:::data
    end

    subgraph "Support"
        config["Config"]:::support
        dependencies["Dependencies"]:::support
        security["Security Utilities"]:::support
    end

    %% Flow: Request processing chain
    userReq -->|"HTTP_Request"| apiLayer
    mainEntrypoint -->|"initializes"| apiLayer
    apiLayer -->|"routes_request"| crudOps
    crudOps -->|"calls_DB_logic"| modelsDir
    modelsDir -->|"ORM_interaction"| db
    db -->|"returns_data"| modelsDir
    modelsDir -->|"data_flow"| crudOps
    crudOps -->|"validate_serialize"| schemas
    schemas -->|"formats_response"| apiLayer
    apiLayer -->|"HTTP_Response"| userResp

    %% Parallel interaction with Core Models (top-level models file)
    crudOps -->|"uses_core_models"| coreModels
    coreModels -->|"ORM_interaction"| db

    %% Supporting dependencies (dashed arrows)
    apiLayer -.->|"dependency"| config
    apiLayer -.->|"dependency"| dependencies
    apiLayer -.->|"dependency"| security
    crudOps -.->|"dependency"| config
    crudOps -.->|"dependency"| dependencies
    crudOps -.->|"dependency"| security

    %% Database Migrations connection
    migrations -->|"manages_schema"| db

    %% Click Events for Component Mappings
    click apiLayer "https://github.com/fkdia23/mini-projet_fastapi/tree/main/app/api"
    click crudOps "https://github.com/fkdia23/mini-projet_fastapi/tree/main/app/crud"
    click modelsDir "https://github.com/fkdia23/mini-projet_fastapi/tree/main/app/models"
    click coreModels "https://github.com/fkdia23/mini-projet_fastapi/blob/main/models.py"
    click schemas "https://github.com/fkdia23/mini-projet_fastapi/tree/main/app/schemas"
    click config "https://github.com/fkdia23/mini-projet_fastapi/blob/main/app/config.py"
    click dependencies "https://github.com/fkdia23/mini-projet_fastapi/blob/main/app/dependencies.py"
    click security "https://github.com/fkdia23/mini-projet_fastapi/blob/main/app/utils/security.py"
    click mainEntrypoint "https://github.com/fkdia23/mini-projet_fastapi/blob/main/app/main.py"
    click migrations "https://github.com/fkdia23/mini-projet_fastapi/tree/main/alembic"
    click db "https://github.com/fkdia23/mini-projet_fastapi/blob/main/app.db"

    %% Styles
    classDef presentation fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef business fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef data fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef support fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
