# pebpung/fastapi-tutorial architecture

> Architecture diagram of the GitHub repository pebpung/fastapi-tutorial, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pebpung/fastapi-tutorial
- Repository: https://github.com/pebpung/fastapi-tutorial

## Overview

##### Project Overview
This is a multi-application FastAPI project with three main components:
- Todo application
- Planner application
- NiceGUI Template application

##### Main Components

A. Application Layer
1. Todo Application
- API endpoints (api.py)
- Data model (model.py)
- Template rendering (templates/)

2. Planner Application
- Main application (main.py)
- Models (models/)
- Events model
- Users model
- Routes (routes/)
- Events routes
- Users routes

3. NiceGUI Template
- Web Application (WebApp/)
- Authentication system
- Page components
- Base templates
- Database utilities

B. Infrastructure Layer
- Docker containers (separate for each application)
- Poetry dependency management
- FastAPI framework
- Database layer (implied by db_utils.py)

**[Client Layer]**

- ▼
**[Load Balancer/Reverse Proxy]**

- ▼
**[Application Layer]**
- Todo App Container
- FastAPI Server
- API Endpoints
- Models
- Templates

- Planner App Container
- FastAPI Server
- User Management
- Event Management

- NiceGUI Template Container
- Web Interface
- Authentication
- Page Components
- Database Utils

**[Data Layer]**
- Database Systems

##### Important Details to Highlight

- Separation between the three main applications
- Containerization strategy (Docker)
- Demonstrate the API routes and their relationships
- Authentication flow in the NiceGUI template
- Template rendering flow in the Todo application
- Model-route relationship in the Planner application

##### Additional Recommendations

- A version indicator
- Environment configurations
- Scaling possibilities
- Development vs production paths
- Monitoring points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CL[Client Browser]
    end

    subgraph LoadBalancer
        LB[Reverse Proxy/Load Balancer]
    end

    subgraph Applications
        subgraph TodoApp
            TD_MAIN["Todo Main App"]:::app
            click TD_MAIN "https://github.com/PEBpung/fastapi-tutorial/blob/main/todo/todo.py"
            TD_API["API Layer"]:::api
            click TD_API "https://github.com/PEBpung/fastapi-tutorial/blob/main/todo/api.py"
            TD_MODEL["Data Model"]:::model
            click TD_MODEL "https://github.com/PEBpung/fastapi-tutorial/blob/main/todo/model.py"
            TD_TEMPL["Template System"]:::ui
            click TD_TEMPL "https://github.com/PEBpung/fastapi-tutorial/tree/main/todo/templates/"
            TD_DOCKER["Todo Docker"]:::infra
            click TD_DOCKER "https://github.com/PEBpung/fastapi-tutorial/tree/main/todo/Dockerfile"
        end

        subgraph PlannerApp
            PL_MAIN["Planner Main"]:::app
            click PL_MAIN "https://github.com/PEBpung/fastapi-tutorial/blob/main/planner/main.py"
            
            subgraph PL_Models
                PL_EVENT_M["Events Model"]:::model
                click PL_EVENT_M "https://github.com/PEBpung/fastapi-tutorial/blob/main/planner/models/events.py"
                PL_USER_M["Users Model"]:::model
                click PL_USER_M "https://github.com/PEBpung/fastapi-tutorial/blob/main/planner/models/users.py"
            end
            
            subgraph PL_Routes
                PL_EVENT_R["Events Routes"]:::api
                click PL_EVENT_R "https://github.com/PEBpung/fastapi-tutorial/blob/main/planner/routes/events.py"
                PL_USER_R["Users Routes"]:::api
                click PL_USER_R "https://github.com/PEBpung/fastapi-tutorial/blob/main/planner/routes/users.py"
            end
            
            PL_DOCKER["Planner Docker"]:::infra
            click PL_DOCKER "https://github.com/PEBpung/fastapi-tutorial/tree/main/planner/Dockerfile"
        end

        subgraph NiceGUITemplate
            NG_MAIN["Main App"]:::app
            click NG_MAIN "https://github.com/PEBpung/fastapi-tutorial/blob/main/NiceGUI-Template/WebApp/main.py"
            NG_AUTH["Authentication"]:::security
            click NG_AUTH "https://github.com/PEBpung/fastapi-tutorial/blob/main/NiceGUI-Template/WebApp/Auth/auth.py"
            NG_PAGES["Page Components"]:::ui
            click NG_PAGES "https://github.com/PEBpung/fastapi-tutorial/blob/main/NiceGUI-Template/WebApp/Pages/home.py"
            NG_TEMPL["Base Templates"]:::ui
            click NG_TEMPL "https://github.com/PEBpung/fastapi-tutorial/blob/main/NiceGUI-Template/WebApp/Templates/base.py"
            NG_DB["Database Utils"]:::db
            click NG_DB "https://github.com/PEBpung/fastapi-tutorial/blob/main/NiceGUI-Template/WebApp/Utils/db_utils.py"
            NG_START["Startup Config"]:::config
            click NG_START "https://github.com/PEBpung/fastapi-tutorial/blob/main/NiceGUI-Template/WebApp/startup.py"
            NG_DOCKER["NiceGUI Docker"]:::infra
            click NG_DOCKER "https://github.com/PEBpung/fastapi-tutorial/tree/main/NiceGUI-Template/web/Dockerfile"
        end
    end

    subgraph Infrastructure
        DOCKER_COMPOSE["Docker Compose"]:::infra
        click DOCKER_COMPOSE "https://github.com/PEBpung/fastapi-tutorial/blob/main/NiceGUI-Template/docker-compose.yml"
        POETRY["Poetry Dependencies"]:::infra
        click POETRY "https://github.com/PEBpung/fastapi-tutorial/blob/main/pyproject.toml"
        DB[(Database Systems)]:::db
    end

    %% Connections
    CL --> LB
    LB --> TD_MAIN & PL_MAIN & NG_MAIN
    
    %% Todo App Connections
    TD_MAIN --> TD_API
    TD_MAIN --> TD_MODEL
    TD_MAIN --> TD_TEMPL
    TD_DOCKER --> TD_MAIN
    
    %% Planner App Connections
    PL_MAIN --> PL_Models
    PL_MAIN --> PL_Routes
    PL_EVENT_R --> PL_EVENT_M
    PL_USER_R --> PL_USER_M
    PL_DOCKER --> PL_MAIN
    
    %% NiceGUI Connections
    NG_MAIN --> NG_AUTH
    NG_MAIN --> NG_PAGES
    NG_MAIN --> NG_TEMPL
    NG_MAIN --> NG_DB
    NG_START --> NG_MAIN
    NG_DOCKER --> NG_MAIN
    
    %% Infrastructure Connections
    DOCKER_COMPOSE --> TD_DOCKER & PL_DOCKER & NG_DOCKER
    POETRY --> TD_MAIN & PL_MAIN & NG_MAIN
    NG_DB --> DB
    TD_MODEL --> DB
    PL_Models --> DB

    %% Styling
    classDef app fill:#90EE90,stroke:#333,stroke-width:2px
    classDef api fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef model fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef ui fill:#E6E6FA,stroke:#333,stroke-width:2px
    classDef db fill:#DEB887,stroke:#333,stroke-width:2px
    classDef security fill:#FFA07A,stroke:#333,stroke-width:2px
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef config fill:#98FB98,stroke:#333,stroke-width:2px
```
