# sleep-revolution/sleepscorerapi architecture

> Architecture diagram of the GitHub repository sleep-revolution/sleepscorerapi, 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/sleep-revolution/sleepscorerapi
- Repository: https://github.com/sleep-revolution/sleepscorerapi

## Overview

##### Main Components

a) Client Layer:
- Web Interface (Templates)
- Static Assets
- Admin Portal

b) Application Layer:
- FastAPI Server
- Routers (Admin Router)
- Middleware Components

c) Business Layer:
- Services Layer
- Repositories Layer
- Infrastructure Layer

d) Data Layer:
- Database (indicated by Models/Database.py)

##### Component Relationships

- Client → FastAPI (HTTP requests)
- FastAPI → Middleware → Services
- Services → Repositories
- Repositories → Database

##### Technical Details

- FastAPI endpoint groups
- Middleware chain order
- Database connections
- Template rendering flow
- Static file serving

##### Additional Elements

- Component types
- Security boundaries

##### Infrastructure Notes

Deployment-related components:
- Docker container boundary (indicated by Dockerfile)
- Jenkins pipeline connection (indicated by Jenkinsfile)

Remember to emphasize the clean architecture pattern evident in the project structure (Services → Repositories → Models), and clearly show how the Infrastructure components support the entire system.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef client fill:#a8d1f0,stroke:#2c3e50
    classDef application fill:#a8e6cf,stroke:#2c3e50
    classDef business fill:#ffd3b6,stroke:#2c3e50
    classDef data fill:#ffaaa5,stroke:#2c3e50
    classDef infrastructure fill:#d4a5a5,stroke:#2c3e50

    %% Client Layer
    subgraph ClientLayer
        AdminUI["Admin Portal"]
        PublicUI["Public Interface"]
        StaticAssets["Static Assets"]
    end
    
    %% Application Layer
    subgraph ApplicationLayer
        FastAPI["FastAPI Server"]
        AdminRouter["Admin Router"]
        ErrorMW["Error Middleware"]
        PreprocessMW["Preprocess Request"]
        JWTAuth["JWT Authentication"]
    end
    
    %% Business Layer
    subgraph BusinessLayer
        AuthService["Authentication Service"]
        UploadService["Upload Service"]
        AnalyticsService["Analytics Service"]
        
        AuthRepo["Authentication Repository"]
        UploadRepo["Upload Repository"]
        AnalyticsRepo["Analytics Repository"]
    end
    
    %% Data Layer
    subgraph DataLayer
        Database["Database"]
        Models["Data Models"]
    end
    
    %% Infrastructure
    subgraph Infrastructure
        Docker["Docker Container"]
        Jenkins["Jenkins Pipeline"]
        Utils["Infrastructure Utilities"]
    end
    
    %% Relationships
    AdminUI --> FastAPI
    PublicUI --> FastAPI
    StaticAssets --> |Serves| PublicUI
    StaticAssets --> |Serves| AdminUI
    
    FastAPI --> ErrorMW
    ErrorMW --> PreprocessMW
    PreprocessMW --> JWTAuth
    
    FastAPI --> AdminRouter
    
    JWTAuth --> AuthService
    FastAPI --> AuthService
    FastAPI --> UploadService
    FastAPI --> AnalyticsService
    
    AuthService --> AuthRepo
    UploadService --> UploadRepo
    AnalyticsService --> AnalyticsRepo
    
    AuthRepo --> Database
    UploadRepo --> Database
    AnalyticsRepo --> Database
    
    Database --> Models
    
    Utils --> BusinessLayer
    Docker --> |Contains| ApplicationLayer
    Jenkins --> |Deploys| Docker
    
    %% Component Styling
    class AdminUI,PublicUI,StaticAssets client
    class FastAPI,AdminRouter,ErrorMW,PreprocessMW,JWTAuth application
    class AuthService,UploadService,AnalyticsService,AuthRepo,UploadRepo,AnalyticsRepo business
    class Database,Models data
    class Docker,Jenkins,Utils infrastructure
    
    %% Click Events
    click FastAPI "https://github.com/sleep-Revolution/sleepscorerapi/blob/main/main.py"
    click AdminRouter "https://github.com/sleep-Revolution/sleepscorerapi/blob/main/AdminRouter.py"
    click AdminUI "https://github.com/sleep-Revolution/sleepscorerapi/tree/main//templates/Admin"
    click StaticAssets "https://github.com/sleep-Revolution/sleepscorerapi/tree/main//static"
    click ErrorMW "https://github.com/sleep-Revolution/sleepscorerapi/blob/main/Src/Infrastructure/ErrorMiddleware.py"
    click PreprocessMW "https://github.com/sleep-Revolution/sleepscorerapi/blob/main/Src/Infrastructure/PreprocessRequest.py"
    click JWTAuth "https://github.com/sleep-Revolution/sleepscorerapi/blob/main/Src/Infrastructure/JWT.py"
    click AuthService "https://github.com/sleep-Revolution/sleepscorerapi/blob/main/Src/Services/AuthenticationService.py"
    click UploadService "https://github.com/sleep-Revolution/sleepscorerapi/blob/main/Src/Services/UploadService.py"
    click AnalyticsService "https://github.com/sleep-Revolution/sleepscorerapi/blob/main/Src/Services/AnalyticsService.py"
    click AuthRepo "https://github.com/sleep-Revolution/sleepscorerapi/blob/main/Src/Repositories/AuthenticationRepository.py"
    click UploadRepo "https://github.com/sleep-Revolution/sleepscorerapi/blob/main/Src/Repositories/UploadsRepository.py"
    click AnalyticsRepo "https://github.com/sleep-Revolution/sleepscorerapi/blob/main/Src/Repositories/AnalyticsRepository.py"
    click Database "https://github.com/sleep-Revolution/sleepscorerapi/blob/main/Src/Models/Database.py"
    click Models "https://github.com/sleep-Revolution/sleepscorerapi/blob/main/Src/Models/Models.py"
    click Utils "https://github.com/sleep-Revolution/sleepscorerapi/blob/main/Src/Infrastructure/Utils.py"
    click Docker "https://github.com/sleep-Revolution/sleepscorerapi/tree/main/Dockerfile"
    click Jenkins "https://github.com/sleep-Revolution/sleepscorerapi/tree/main/Jenkinsfile"
```
