# alandonohoe/usage_service architecture

> Architecture diagram of the GitHub repository alandonohoe/usage_service, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alandonohoe/usage_service
- Repository: https://github.com/alandonohoe/usage_service

## Overview

##### Main Components

a) Web Layer:
- FastAPI Application (Primary HTTP Server)
- API Routes Structure (v1 endpoints and health monitoring)
- Swagger Documentation endpoint

b) Service Layer:
- Usage Service
- Usage Calculator
- Message and Report Services

c) Infrastructure Layer:
- Message API Infrastructure
- Reports API Infrastructure

d) Data Models:
- Message Model
- Report Model
- Usage Model

**┌─────────────────────────────────────────────────────┐**
- Client Requests                     │
- ┘
- ↓
**┌─────────────────────────────────────────────────────┐**
- Web Layer                        │
- ┌─────────────┐  ┌─────────────┐  ┌────────────┐  │
- FastAPI   │  │    Router   │  │   Health   │  │
- Application │  │   (v1 API)  │  │  Endpoint  │  │
- ┘  └─────────────┘  └────────────┘  │
- ┘
- ↓
**┌─────────────────────────────────────────────────────┐**
- Service Layer                      │
- ┌─────────────┐  ┌─────────────┐  ┌────────────┐  │
- Usage    │  │    Usage    │  │  External  │  │
- Service   │←→│ Calculator  │  │  Services  │  │
- ┘  └─────────────┘  └────────────┘  │
- ┘
- ↓
**┌─────────────────────────────────────────────────────┐**
- Infrastructure Layer                  │
- ┌─────────────┐  ┌─────────────┐                  │
- Messages   │  │   Reports   │                  │
- API     │  │     API     │                  │
- ┘  └─────────────┘                  │
- ┘

##### Important Details

a) Configuration Management:
- Environment variables configuration
- Settings management through pydantic

b) Deployment Options:
- Docker container
- Development environment
- Production environment

c) Testing Infrastructure:
- Unit tests
- Integration tests
- Test fixtures

##### Specific Implementation Notes

- The separation between API versions (v1)
- The monitoring/health check system
- The usage calculation flow
- The interaction between services and infrastructure
- The model relationships

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        CR[Client Requests]
    end

    subgraph WebLayer[Web Layer]
        FA["FastAPI Application"]
        MR["Main Router"]
        V1["API Routes (v1)"]
        HE["Health Endpoint"]
        AL["Application Lifecycle"]
    end

    subgraph ServiceLayer[Service Layer]
        US["Usage Service"]
        UC["Usage Calculator"]
        ES["External Services"]
    end

    subgraph InfraLayer[Infrastructure Layer]
        MA["Message API"]
        RA["Reports API"]
    end

    subgraph DataModels[Data Models]
        MM["Message Model"]
        RM["Report Model"]
        UM["Usage Model"]
        ARM["API Response Models"]
    end

    subgraph Config[Configuration]
        SM["Settings Management"]
    end

    subgraph Testing[Testing Infrastructure]
        IT["Integration Tests"]
        UT["Unit Tests"]
        TC["Test Configuration"]
    end

    subgraph Deployment[Deployment]
        DC["Docker Configuration"]
        DE["Development Environment"]
        PE["Production Environment"]
    end

    %% Relationships
    CR --> FA
    FA --> MR
    MR --> V1
    MR --> HE
    FA --> AL
    V1 --> US
    US --> UC
    US --> ES
    ES --> MA
    ES --> RA
    US --> MM
    US --> RM
    US --> UM
    V1 --> ARM
    FA --> SM

    %% Click Events
    click FA "https://github.com/AlanDonohoe/usage_service/blob/main/usage_service/web/application.py"
    click MR "https://github.com/AlanDonohoe/usage_service/blob/main/usage_service/web/api/router.py"
    click V1 "https://github.com/AlanDonohoe/usage_service/tree/main/usage_service/web/api/v1/routers/"
    click HE "https://github.com/AlanDonohoe/usage_service/blob/main/usage_service/web/api/monitoring/health.py"
    click AL "https://github.com/AlanDonohoe/usage_service/blob/main/usage_service/web/lifespan.py"
    click US "https://github.com/AlanDonohoe/usage_service/blob/main/usage_service/services/usage_service.py"
    click UC "https://github.com/AlanDonohoe/usage_service/blob/main/usage_service/services/usage/calculator.py"
    click MA "https://github.com/AlanDonohoe/usage_service/tree/main/usage_service/infra/apis/messages/"
    click RA "https://github.com/AlanDonohoe/usage_service/tree/main/usage_service/infra/apis/reports/"
    click MM "https://github.com/AlanDonohoe/usage_service/blob/main/usage_service/models/message.py"
    click RM "https://github.com/AlanDonohoe/usage_service/blob/main/usage_service/models/report.py"
    click UM "https://github.com/AlanDonohoe/usage_service/blob/main/usage_service/models/usage.py"
    click ARM "https://github.com/AlanDonohoe/usage_service/tree/main/usage_service/web/api/v1/models/responses/"
    click SM "https://github.com/AlanDonohoe/usage_service/blob/main/usage_service/settings.py"
    click IT "https://github.com/AlanDonohoe/usage_service/tree/main/tests/integration/"
    click UT "https://github.com/AlanDonohoe/usage_service/tree/main/tests/unit/"
    click TC "https://github.com/AlanDonohoe/usage_service/blob/main/tests/conftest.py"
    click DC "https://github.com/AlanDonohoe/usage_service/tree/main/Dockerfile"
    click DE "https://github.com/AlanDonohoe/usage_service/blob/main/deploy/docker-compose.dev.yml"
    click PE "https://github.com/AlanDonohoe/usage_service/blob/main/docker-compose.yml"

    %% Styling
    classDef web fill:#2374ab
    classDef service fill:#48a9a6
    classDef infra fill:#e4572e
    classDef model fill:#17bebb
    classDef config fill:#ffc914
    classDef test fill:#c17767
    classDef deploy fill:#533a71
    classDef client fill:#f5f5f5

    class FA,MR,V1,HE,AL web
    class US,UC,ES service
    class MA,RA infra
    class MM,RM,UM,ARM model
    class SM config
    class IT,UT,TC test
    class DC,DE,PE deploy
    class CR client
```
