# cloud-native-group-1/leave-n-attendance-system-backend architecture

> Architecture diagram of the GitHub repository cloud-native-group-1/leave-n-attendance-system-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cloud-native-group-1/leave-n-attendance-system-backend
- Repository: https://github.com/cloud-native-group-1/leave-n-attendance-system-backend

## Overview

##### Project type and purpose
- This is a backend-only service for a Leave and Attendance Management System.
- Built as a modular, containerized, API-centric microservice using FastAPI, it exposes REST endpoints for a frontend or other clients.

##### File structure
- Top-level artifacts:
- Dockerfile, docker-compose.yaml → containerization setup for the FastAPI app and PostgreSQL.
- alembic.ini and migrations/ → database migration management.
- app/ → the FastAPI application code.
- Inside app/:
- config.py, database.py, t_db.py → configuration and database connection setup.
- models/ → SQLAlchemy ORM models representing DB tables.
- schemas/ → Pydantic models for request/response validation.
- crud/ → data-access layer functions that encapsulate SQLAlchemy queries.
- routes/ → API routers mapping HTTP endpoints to CRUD operations.
- utils/ → shared helpers (authentication, dependency injection).
- tests/ → unit tests for core functionality.

##### README insights
- Confirms FastAPI + Uvicorn ASGI stack, SQLAlchemy ORM with PostgreSQL, Pydantic schemas, Docker for containerization, Alembic for migrations, and GCP App Engine for deployment.
- Emphasizes clean architecture: separation of concerns across routes, schemas, CRUD, and models.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client["External Client"]:::external

    %% Load Balancer
    LB["HTTP(S) Load Balancer"]:::compute

    Client -->|HTTPS Request| LB

    %% Docker Containers Boundary
    subgraph "Docker Containers" 
        direction TB
        style DockerContainers stroke-dasharray: 5 5
        %% FastAPI Container
        subgraph "FastAPI Container" 
            direction TB
            style FastAPIContainer stroke-dasharray: 5 5
            Uvicorn["Uvicorn ASGI Server"]:::compute
            Main["app/main.py<br/>(Entrypoint)"]:::compute
            Config["app/config.py<br/>(Config Module)"]:::compute
            DatabaseConn["app/database.py<br/>&<br/>app/t_db.py"]:::compute
            Routers["app/routes/"]:::compute
            Schemas["app/schemas/"]:::compute
            CRUD["app/crud/"]:::compute
            Models["app/models/"]:::compute
            UtilsAuth["app/utils/auth.py"]:::compute
            UtilsDeps["app/utils/dependencies.py"]:::compute
            Tests["app/tests/"]:::compute

            LB -->|Forwards to| Uvicorn
            Uvicorn -->|calls| Main
            Main -->|loads| Config
            Main -->|depends on| DatabaseConn
            Main -->|includes| Routers
            Routers -->|validate via| Schemas
            Routers -->|invoke| CRUD
            CRUD -->|operate on| Models
            CRUD -->|use| DatabaseConn
            Routers -->|use| UtilsAuth
            Routers -->|use| UtilsDeps
            Tests -->|cover| Routers
        end

        %% PostgreSQL Container
        subgraph "PostgreSQL Container"
            direction TB
            style PostgresContainer stroke-dasharray: 5 5
            DB["PostgreSQL Database"]:::db
        end

        DatabaseConn -->|connects to| DB
        CRUD -->|queries| DB
    end

    %% Alembic Migration Service
    Alembic["Alembic Migration Service"]:::pipeline
    Alembic -->|migrate| DB

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline" 
        direction TB
        style CICD stroke-dasharray: 5 5
        GH_Test[".github/workflows/test.yaml"]:::pipeline
        GH_Deploy1[".github/workflows/deploy-to-cloud-run.yaml"]:::pipeline
        GH_Deploy2[".github/workflows/deploy-to-cloud-run.test.yaml"]:::pipeline
        GH_Test -->|run tests| Tests
        GH_Test -->|invoke| Alembic
        GH_Deploy1 -->|build Docker image| Dockerfile
        GH_Deploy1 -->|use| docker-compose.yaml
        GH_Deploy1 -->|deploy to| GoogleAppEngine["GCP App Engine"]:::external
        GH_Deploy2 -->|build & test| Dockerfile
    end

    %% Relations
    Dockerfile["Dockerfile"]:::pipeline
    Compose["docker-compose.yaml"]:::pipeline

    %% Click Events
    click Dockerfile "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/tree/main/Dockerfile"
    click Compose "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/blob/main/docker-compose.yaml"
    click Alembic "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/blob/main/alembic.ini"
    click Migrations "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/tree/main/migrations/versions/"
    click Main "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/blob/main/app/main.py"
    click Config "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/blob/main/app/config.py"
    click DatabaseConn "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/blob/main/app/database.py"
    click DatabaseConn "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/blob/main/app/t_db.py"
    click Models "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/tree/main/app/models/"
    click Schemas "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/tree/main/app/schemas/"
    click CRUD "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/tree/main/app/crud/"
    click Routers "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/tree/main/app/routes/"
    click UtilsAuth "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/blob/main/app/utils/auth.py"
    click UtilsDeps "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/blob/main/app/utils/dependencies.py"
    click Tests "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/tree/main/app/tests/"
    click GH_Test "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/blob/main/.github/workflows/test.yaml"
    click GH_Deploy1 "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/blob/main/.github/workflows/deploy-to-cloud-run.yaml"
    click GH_Deploy2 "https://github.com/cloud-native-group-1/leave-n-attendance-system-backend/blob/main/.github/workflows/deploy-to-cloud-run.test.yaml"

    %% Styles
    classDef compute fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef db fill:#F4C542,stroke:#333,stroke-width:1px
    classDef pipeline fill:#E6E6FA,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px

    class Dockerfile,Compose pipeline
    class Client external
    class LB compute
    class Uvicorn,Main,Config,DatabaseConn,Routers,Schemas,CRUD,Models,UtilsAuth,UtilsDeps,Tests compute
    class DB db
    class Alembic,GH_Test,GH_Deploy1,GH_Deploy2 pipeline
```
