# sabuhibrahim/fastapi-jwt-auth-full-example architecture

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

- Interactive diagram: https://gitdiagram.com/sabuhibrahim/fastapi-jwt-auth-full-example
- Repository: https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example

## Overview

##### Main Components
- API Layer: Representing the FastAPI endpoints for authentication and article-related operations.
- Authentication & Security: Components handling JWT (in src/core/jwt.py), hashing (src/core/hash.py), and security configurations (in src/core/config.py).
- Database: Indicating the PostgreSQL database, asynchronous connection via SQLAlchemy (in src/database.py).
- Docker & Deployment: Include the Dockerfile and docker-compose.yml to show containerization and orchestration aspects.
- Supporting Modules: Additional utilities, models (src/models.py), schemas (src/schemas.py), tasks (src/tasks.py), and other dependencies.

##### Relationships and Interactions
- API Layer to the Database component, indicating the use of SQLAlchemy for asynchronous operations.
- Interaction between the API Layer and Alembic (database migrations) as part of the startup sequence managed by the start.sh script.
- Deployment orchestration using Docker where the application, PostgreSQL, and possibly other services are containerized.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly differentiate between API routing, security/authentication, data models, and database operations.
- Modularity: Each directory (src/core, src/models, etc.) encapsulates specific functionality.
- Asynchronous Processing: Mark the asynchronous nature of database interactions.
- Configuration Management: Emphasize the use of environment variables (.env) and configuration files (alembic.ini, src/core/config.py).

##### Relevant Technologies
- FastAPI for the API framework.
- SQLAlchemy for ORM (asynchronous connection).
- PostgreSQL as the database.
- Alembic for handling database migrations.
- Docker for containerization and docker-compose for orchestration.

##### Additional Recommendations
- Detail the migration process by showing that the start.sh script triggers migrations before launching the FastAPI app.
- That both Docker and non-Docker deployment paths are represented if needed.
- Maintain clarity by avoiding over-complication; separate concerns clearly but do not split components more than necessary.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "API Layer"
        API1("main.py"):::api
        API2("src/routers.py"):::api
    end

    subgraph "Authentication & Security"
        AUTH1("src/core/jwt.py"):::auth
        AUTH2("src/core/hash.py"):::auth
        AUTH3("src/core/config.py"):::auth
    end

    subgraph "Database & ORM"
        DB("src/database.py"):::db
    end

    subgraph "Migration System"
        MIG1("alembic/env.py"):::mig
        MIG2("alembic/versions"):::mig
        MIG3("alembic.ini"):::mig
    end

    subgraph "Docker & Deployment"
        DOCKER1("Dockerfile"):::docker
        DOCKER2("docker-compose.yml"):::docker
        DOCKER3("start.sh"):::docker
    end

    subgraph "Supporting Modules"
        SUP1("src/models.py"):::support
        SUP2("src/schemas.py"):::support
        SUP3("src/tasks.py"):::support
        SUP4("src/dependencies.py"):::support
        SUP5("src/utils.py"):::support
    end

    %% API interaction with Authentication & Security
    API1 -->|"uses"| AUTH1
    API1 -->|"uses"| AUTH2
    API1 -->|"uses"| AUTH3

    %% API interaction with Database
    API1 -->|"calls"| DB
    API2 -->|"calls"| DB

    %% API utilizes supporting modules
    API1 -->|"utilizes"| SUP1
    API1 -->|"utilizes"| SUP2
    API1 -->|"utilizes"| SUP3
    API1 -->|"utilizes"| SUP4
    API1 -->|"utilizes"| SUP5

    %% Deployment triggers migration before starting the app
    DOCKER3 -->|"triggers"| MIG1
    DOCKER3 -->|"triggers"| MIG2
    DOCKER3 -->|"triggers"| MIG3
    MIG1 -->|"updates"| DB

    %% Docker orchestration
    DOCKER1 -->|"builds"| API1
    DOCKER2 -->|"orchestrates"| API1
    DOCKER2 -->|"orchestrates"| DB

    %% Class Definitions for styling
    classDef api fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef auth fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef db fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef mig fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef docker fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef support fill:#FFA07A,stroke:#333,stroke-width:2px;

click API1 "https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example/blob/main/main.py"
click API2 "https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example/blob/main/src/routers.py"

click AUTH1 "https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example/blob/main/src/core/jwt.py"
click AUTH2 "https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example/blob/main/src/core/hash.py"
click AUTH3 "https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example/blob/main/src/core/config.py"

click DB "https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example/blob/main/src/database.py"

click MIG1 "https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example/blob/main/alembic/env.py"
click MIG2 "https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example/tree/main/alembic/versions"
click MIG3 "https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example/blob/main/alembic.ini"

click DOCKER1 "https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example/tree/main/Dockerfile"
click DOCKER2 "https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example/blob/main/docker-compose.yml"
click DOCKER3 "https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example/blob/main/start.sh"

click SUP1 "https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example/blob/main/src/models.py"
click SUP2 "https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example/blob/main/src/schemas.py"
click SUP3 "https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example/blob/main/src/tasks.py"
click SUP4 "https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example/blob/main/src/dependencies.py"
click SUP5 "https://github.com/sabuhibrahim/fastapi-jwt-auth-full-example/blob/main/src/utils.py"
```
