# libqwerty/auth-server architecture

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

- Interactive diagram: https://gitdiagram.com/libqwerty/auth-server
- Repository: https://github.com/libqwerty/auth-server

## Overview

##### Component Relationships

- External requests → Controllers
- Controllers → Use Cases
- Use Cases → Repositories
- Repositories → Database
- All layers → Domain (dependencies point inward)

##### Key Technical Elements

Infrastructure:
- PostgreSQL Database
- Prisma ORM
- FastAPI/Flask (based on app.py structure)
- Docker container

Security Components:
- Token Management
- Session Handling
- Password Encryption (utils/crypto.py)
- Access Logging

##### Additional Elements

Include:
- Configuration components (config/policy.py)
- Error handling paths
- External service integrations (if any)

##### Specific Implementation Details

Highlight:
- Database migrations (prisma/migrations)
- Policy configurations
- Docker deployment
- GitHub Actions workflow

- Component types
- Important symbols or patterns used

Level of Detail:
- Keep high-level architectural patterns visible
- Enough detail to understand the authentication flows
- Clear boundaries between layers
- Security-critical paths

1. This is a security-critical service, so emphasize the isolation and protection of sensitive components

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef controller fill:#2196F3,stroke:#1565C0,color:white
    classDef usecase fill:#4CAF50,stroke:#2E7D32,color:white
    classDef domain fill:#FFC107,stroke:#FFA000,color:black
    classDef repository fill:#FF9800,stroke:#F57C00,color:white
    classDef database fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef infrastructure fill:#757575,stroke:#424242,color:white
    classDef dto fill:#03A9F4,stroke:#0288D1,color:white
    classDef security fill:#F44336,stroke:#D32F2F,color:white

    %% External Layer
    subgraph External
        HTTP["HTTP Controllers"]:::controller
        DTO["DTO Layer"]:::dto
        click HTTP "https://github.com/libqwerty/auth-server/blob/main/auth/controllers/auth.py"
        click DTO "https://github.com/libqwerty/auth-server/tree/main/auth/controllers/dto/"
    end

    %% Domain Layer
    subgraph Domain
        Entities["Domain Entities"]:::domain
        Models["Domain Models"]:::domain
        DomainErrors["Domain Errors"]:::domain
        click Entities "https://github.com/libqwerty/auth-server/blob/main/auth/domain/entities.py"
        click Models "https://github.com/libqwerty/auth-server/blob/main/auth/domain/models.py"
        click DomainErrors "https://github.com/libqwerty/auth-server/blob/main/auth/domain/errors.py"
    end

    %% Use Cases Layer
    subgraph UseCases
        SignIn["Sign In"]:::usecase
        SignUp["Sign Up"]:::usecase
        SignOut["Sign Out"]:::usecase
        RefreshToken["Refresh Token"]:::usecase
        VerifySession["Verify Session"]:::usecase
        VerifyToken["Verify Token"]:::usecase
        ChangePassword["Change Password"]:::usecase
        click SignIn "https://github.com/libqwerty/auth-server/blob/main/auth/usecase/auth/signin.py"
        click SignUp "https://github.com/libqwerty/auth-server/blob/main/auth/usecase/auth/signup.py"
        click SignOut "https://github.com/libqwerty/auth-server/blob/main/auth/usecase/auth/signout.py"
        click RefreshToken "https://github.com/libqwerty/auth-server/blob/main/auth/usecase/auth/refresh.py"
        click VerifySession "https://github.com/libqwerty/auth-server/blob/main/auth/usecase/auth/verify_session.py"
        click VerifyToken "https://github.com/libqwerty/auth-server/blob/main/auth/usecase/auth/verify_token.py"
        click ChangePassword "https://github.com/libqwerty/auth-server/blob/main/auth/usecase/auth/change_password.py"
    end

    %% Repository Layer
    subgraph Repositories
        AuthRepo["Auth Repository"]:::repository
        AccessRepo["Access Repository"]:::repository
        TokenRepo["Token Repository"]:::repository
        SessionRepo["Session Repository"]:::repository
        ORM["ORM"]:::repository
        click AuthRepo "https://github.com/libqwerty/auth-server/blob/main/auth/repository/auth.py"
        click AccessRepo "https://github.com/libqwerty/auth-server/blob/main/auth/repository/access.py"
        click TokenRepo "https://github.com/libqwerty/auth-server/blob/main/auth/repository/token.py"
        click SessionRepo "https://github.com/libqwerty/auth-server/blob/main/auth/repository/session.py"
        click ORM "https://github.com/libqwerty/auth-server/blob/main/auth/repository/orm.py"
    end

    %% Security Components
    subgraph Security
        Crypto["Crypto Utils"]:::security
        Policy["Policy Configuration"]:::security
        click Crypto "https://github.com/libqwerty/auth-server/blob/main/auth/utils/crypto.py"
        click Policy "https://github.com/libqwerty/auth-server/blob/main/auth/config/policy.py"
    end

    %% Infrastructure Layer
    subgraph Infrastructure
        DB[(PostgreSQL)]:::database
        Migrations["Database Migrations"]:::infrastructure
        DockerConfig["Docker Config"]:::infrastructure
        CICD["CI/CD Pipeline"]:::infrastructure
        App["Main App"]:::infrastructure
        click Migrations "https://github.com/libqwerty/auth-server/tree/main/prisma/migrations/"
        click DockerConfig "https://github.com/libqwerty/auth-server/tree/main/docker/Dockerfile"
        click CICD "https://github.com/libqwerty/auth-server/blob/main/.github/workflows/release.yaml"
        click App "https://github.com/libqwerty/auth-server/blob/main/auth/app.py"
    end

    %% Relationships
    HTTP --> DTO
    DTO --> UseCases
    UseCases --> Domain
    UseCases --> Repositories
    Repositories --> ORM
    ORM --> DB
    Security --> UseCases
    Security --> Repositories
    Infrastructure --> DB

    %% Legend
    subgraph Legend
        L1["Controller"]:::controller
        L2["Use Case"]:::usecase
        L3["Domain"]:::domain
        L4["Repository"]:::repository
        L5["Database"]:::database
        L6["Infrastructure"]:::infrastructure
        L7["Security"]:::security
    end
```
