# viktorviskov/fastapi-mvc architecture

> Architecture diagram of the GitHub repository viktorviskov/fastapi-mvc, 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/viktorviskov/fastapi-mvc
- Repository: https://github.com/viktorviskov/fastapi-mvc

## Overview

##### Main Components
- Controllers: Represented by the files in the app/controllers folder (auth_controller.py, page_controller.py, user_controller.py). These handle incoming HTTP requests and map them to the appropriate business logic.
- Models: Located in the app/models directory (db.py, dto.py). They form the data layer and define the application’s domain models and data schemas.
- Services: Found in app/services (jwt_service.py, user_service.py). These implement core business logic and often interact with both models and external components.
- Database Layer: In the app/db folder (context.py and the initialization scripts). This component manages database connections, context, and interact with SQLAlchemy/Alembic migrations.
- Middlewares: In app/middlewares (cors_middleware.py, static_middleware.py). These intercept requests and responses to handle cross-cutting concerns like CORS and serving static files.
- Views: Although this is an API-driven application, the app/templates and app/static folders suggest that there is also some HTML rendering capability—handle views or static content to be served to the client.
- Utilities: In app/utils, containing auxiliary functions and tasks (e.g., hashing, background scheduling). These are supportive modules used across multiple layers.
- Infrastructure/Deployment: Dockerfile, docker-compose.yml, and related bash scripts (dev.bash, prod.sh, db_init.bash) indicate how the application is containerized and deployed.

- One branch directed toward the services layer (user_service, jwt_service).
- Another branch could go to serving static files or rendering templates (views) if applicable.
- Utility modules can be represented as support modules attached to both services and controllers, highlighting tasks like hashing and dependency injection.

##### Architectural Patterns
- Separation of concerns: Controllers handle routing and request management, services encapsulate business logic, models represent data structures, and utility functions provide common infrastructure support.
- Deployment practices with Docker and docker-compose, representing how the application is containerized and how it interacts with external database services if any.

##### Technologies and External Libraries
- Optionally, denote the Docker integration and bash scripts that manage development and production setups.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Client (Web Browser/API Client)"]:::client
    B["Middlewares (CORS & Static)"]:::middleware
    C["Controllers (Auth, Page, User)"]:::controller
    D["Services (JWT, User Service)"]:::service
    E["Models (db, dto)"]:::model
    F["Database (SQLAlchemy, PyMySQL)"]:::database
    subgraph "Views"
        G1["Templates (Jinja)"]:::view
        G2["Static Assets"]:::view
    end
    H["Utilities (Hashing, Scheduling, etc.)"]:::utility
    subgraph "Infrastructure/Deployment"
        I1["Dockerfile"]:::infra
        I2["docker-compose.yml"]:::infra
        I3["dev.bash"]:::infra
        I4["prod.sh"]:::infra
        I5["install_env.sh"]:::infra
    end

    A -->|"sendRequest"| B
    B -->|"route"| C
    B -->|"serveStatic"| G2
    B -->|"renderTemplate"| G1
    C -->|"delegate"| D
    D -->|"processData"| E
    E <-->|"dbOps"| F
    H ---|"support"| C
    H ---|"support"| D
    I1 -->|"containerize"| A
    I2 -->|"orchestrate"| F

    click C "https://github.com/viktorviskov/fastapi-mvc/tree/main/app/controllers"
    click D "https://github.com/viktorviskov/fastapi-mvc/tree/main/app/services"
    click E "https://github.com/viktorviskov/fastapi-mvc/tree/main/app/models"
    click F "https://github.com/viktorviskov/fastapi-mvc/tree/main/app/db"
    click B "https://github.com/viktorviskov/fastapi-mvc/tree/main/app/middlewares"
    click G1 "https://github.com/viktorviskov/fastapi-mvc/tree/main/app/templates"
    click G2 "https://github.com/viktorviskov/fastapi-mvc/tree/main/app/static"
    click H "https://github.com/viktorviskov/fastapi-mvc/tree/main/app/utils"
    click I1 "https://github.com/viktorviskov/fastapi-mvc/tree/main/Dockerfile"
    click I2 "https://github.com/viktorviskov/fastapi-mvc/blob/main/docker-compose.yml"
    click I3 "https://github.com/viktorviskov/fastapi-mvc/blob/main/app/dev.bash"
    click I4 "https://github.com/viktorviskov/fastapi-mvc/blob/main/app/prod.sh"
    click I5 "https://github.com/viktorviskov/fastapi-mvc/blob/main/install_env.sh"

    classDef client fill:#90ee90,stroke:#333,stroke-width:2px;
    classDef middleware fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef controller fill:#ffa500,stroke:#333,stroke-width:2px;
    classDef service fill:#98fb98,stroke:#333,stroke-width:2px;
    classDef model fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef database fill:#fdd835,stroke:#333,stroke-width:2px;
    classDef view fill:#dda0dd,stroke:#333,stroke-width:2px;
    classDef utility fill:#d3d3d3,stroke:#333,stroke-width:2px;
    classDef infra fill:#ffff99,stroke:#333,stroke-width:2px;
```
