# devbruce/fastapi-di-tpl architecture

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

## Overview

##### Main Components

a. Application Layer
- FastAPI Application (Entry Point)
- Dependency Injection Container System
- Configuration Management

b. Core System Components
- Controllers Layer
- Services Layer
- Schemas Layer
- Interfaces Layer

c. Infrastructure Components
- Environment Configuration
- DI Configurations (dev/local/prd/stg/test)

##### Component Relationships

**┌─────────────────────────────────────────────────────┐**
- FastAPI Application                 │
- (main.py as the application entry point)     │
- ┤
- Dependency Injection Layer             │
- (containers.py managing dependency resolution)    │
- ┬─────────────────┬──────────────┤
- Controllers    │    Services     │   Schemas    │
- (API Routes)    │  (Business Logic)│  (Data Models)│
- ┴─────────────────┴──────────────┤
- Configuration Management               │
- (Environment-specific DI configs)           │
- ┘

##### Important Elements to Highlight

- Blue: FastAPI Application Layer
- Green: Dependency Injection Container
- Yellow: Core Business Logic Components
- Gray: Configuration and Infrastructure

##### Specific Implementation Details

a. The DI Container Structure:
- How src/containers.py acts as the main container
- Relationship with core/system/containers.py
- How di_configs/*.yml files configure the container

b. Core System Organization:
- Relationship between controllers, services, and schemas
- Di_check module's role in dependency validation
- Utility layers (src/utils)

##### Testing Infrastructure

A separate section showing:
- Unit Tests relationship with components
- E2E Tests interaction with the system
- Test configuration management

##### Environment Configuration

How different environments are handled:
- Development (dev.yml)
- Production (prd.yml)
- Staging (stg.yml)
- Local (local.yml)
- Test (test.yml)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Application
        FastAPI["FastAPI Application"]:::app
        click FastAPI "https://github.com/devbruce/fastapi-di-tpl/blob/main/src/main.py"
        Settings["Settings Management"]:::config
        click Settings "https://github.com/devbruce/fastapi-di-tpl/blob/main/src/settings.py"
    end

    subgraph "Dependency Injection"
        MainContainer["Main Container"]:::di
        click MainContainer "https://github.com/devbruce/fastapi-di-tpl/blob/main/src/containers.py"
        SystemContainer["System Container"]:::di
        click SystemContainer "https://github.com/devbruce/fastapi-di-tpl/blob/main/src/core/system/containers.py"
        DICheckContainer["DI Check Container"]:::di
        click DICheckContainer "https://github.com/devbruce/fastapi-di-tpl/blob/main/src/core/system/di_check/containers.py"
    end

    subgraph "Core Components"
        Controllers["Controllers Layer"]:::core
        click Controllers "https://github.com/devbruce/fastapi-di-tpl/blob/main/src/core/system/di_check/controllers.py"
        Services["Services Layer"]:::core
        click Services "https://github.com/devbruce/fastapi-di-tpl/blob/main/src/core/system/di_check/services.py"
        Schemas["Schemas Layer"]:::core
        click Schemas "https://github.com/devbruce/fastapi-di-tpl/blob/main/src/core/system/di_check/schemas.py"
        Interfaces["Interfaces Layer"]:::core
        click Interfaces "https://github.com/devbruce/fastapi-di-tpl/blob/main/src/core/system/di_check/interfaces.py"
        Examples["Example Implementation"]:::core
        click Examples "https://github.com/devbruce/fastapi-di-tpl/blob/main/src/core/system/di_check/examples.py"
    end

    subgraph "Configuration"
        ConfigDir["DI Configs Directory"]:::config
        click ConfigDir "https://github.com/devbruce/fastapi-di-tpl/tree/main/src/di_configs/"
        DevConfig["Development Config"]:::config
        click DevConfig "https://github.com/devbruce/fastapi-di-tpl/blob/main/src/di_configs/dev.yml"
        PrdConfig["Production Config"]:::config
        click PrdConfig "https://github.com/devbruce/fastapi-di-tpl/blob/main/src/di_configs/prd.yml"
        StgConfig["Staging Config"]:::config
        click StgConfig "https://github.com/devbruce/fastapi-di-tpl/blob/main/src/di_configs/stg.yml"
        LocalConfig["Local Config"]:::config
        click LocalConfig "https://github.com/devbruce/fastapi-di-tpl/blob/main/src/di_configs/local.yml"
        TestConfig["Test Config"]:::config
        click TestConfig "https://github.com/devbruce/fastapi-di-tpl/blob/main/src/di_configs/test.yml"
    end

    subgraph "Testing"
        E2ETests["E2E Tests"]:::test
        click E2ETests "https://github.com/devbruce/fastapi-di-tpl/blob/main/tests/e2e/system/test_apis.py"
        UnitTests["Unit Tests"]:::test
        click UnitTests "https://github.com/devbruce/fastapi-di-tpl/tree/main/tests/unit/"
        TestConf["Test Configuration"]:::test
        click TestConf "https://github.com/devbruce/fastapi-di-tpl/blob/main/tests/conftest.py"
    end

    subgraph "Utilities"
        AppInfo["Application Info"]:::util
        click AppInfo "https://github.com/devbruce/fastapi-di-tpl/blob/main/src/utils/app_info.py"
        PathUtils["Path Utilities"]:::util
        click PathUtils "https://github.com/devbruce/fastapi-di-tpl/blob/main/src/utils/paths.py"
    end

    FastAPI --> MainContainer
    MainContainer --> SystemContainer
    SystemContainer --> DICheckContainer
    DICheckContainer --> Controllers
    DICheckContainer --> Services
    DICheckContainer --> Schemas
    DICheckContainer --> Interfaces
    DICheckContainer --> Examples

    Controllers --> Services
    Services --> Schemas
    Services --> Interfaces

    MainContainer --> ConfigDir
    ConfigDir --> DevConfig
    ConfigDir --> PrdConfig
    ConfigDir --> StgConfig
    ConfigDir --> LocalConfig
    ConfigDir --> TestConfig

    FastAPI --> Settings
    Settings --> ConfigDir

    E2ETests -.-> FastAPI
    UnitTests -.-> CoreComponents
    TestConf -.-> E2ETests
    TestConf -.-> UnitTests

    AppInfo -.-> FastAPI
    PathUtils -.-> ConfigDir

    classDef app fill:#2196F3,stroke:#1565C0,color:white
    classDef di fill:#4CAF50,stroke:#388E3C,color:white
    classDef core fill:#FFC107,stroke:#FFA000,color:black
    classDef config fill:#9E9E9E,stroke:#616161,color:white
    classDef test fill:#FF5722,stroke:#E64A19,color:white
    classDef util fill:#673AB7,stroke:#512DA8,color:white
```
