# vkatvell/general-ledger architecture

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

- Interactive diagram: https://gitdiagram.com/vkatvell/general-ledger
- Repository: https://github.com/vkatvell/general-ledger

## Overview

##### Project Overview & Main Components
- This is a containerized full-stack ledger system with a FastAPI backend and a Next.js frontend. It uses PostgreSQL as its database, managed by Alembic migrations. Development and container orchestration are handled via Docker Compose.
- Key components to include:
- Frontend (Next.js application)
- Backend (FastAPI application)
- Database (PostgreSQL)
- Database migration tool (Alembic)
- Development/CI tools (Docker Compose, Dockerfiles, and test suites)

##### Analyzing the File Structure for Architectural Clues
- Backend:
- The “app” directory contains subdirectories for core configuration, database models, API routes, schemas, services, and utility functions. This indicates a layered design where routes handle HTTP requests, services include business logic, and models represent the DB structure.
- The “alembic” folder along with its migration scripts shows that there is a defined process for managing database schema changes.
- Frontend:
- The “frontend” directory is organized with pages (typically under “app”) and reusable components. There are dedicated areas for pages (pages and sections like accounts, entries, summary) and shared UI components built with TailwindCSS and ShadCN UI.
- Common configuration & tools:
- There are Dockerfiles at both the project root (backend) and inside the “frontend” directory, along with a docker-compose.yml file that orchestrates the containers and likely includes the PostgreSQL service.
- Test directories (“tests”, with integration and unit tests) and seed scripts hint at support for automated testing and data initialization during development.

a. Main Components:
- API Routes (endpoints for accounts, entries, summary)
- Business logic (services)
- Data validation/schemas
- DB models and session handling
- Core configuration settings and utility functions.
- Database: Represent PostgreSQL with its connection to the backend and noted usage of async SQLAlchemy.
- Migrations: A component representing the Alembic migration process that synchronizes with the database.

b. Relationships & Data Flow:
- Optionally, show the testing suite and development scripts interacting with the backend and database layers.
- If desired, add notes on seed data (from scripts/seed.py) that prepare initial database state.

c. Architectural Patterns & Design Principles:
- For the backend, note the layered architecture (routes → services → database/models) that enhances separation of concerns.
- Mention the containerization strategy where each major component (frontend, backend, database) runs isolated in its own Docker container.
- Use of asynchronous programming (FastAPI with async SQLAlchemy) for performance.

d. Relevant Technologies:
- Also mention development tools like Docker Compose, pre-commit hooks, and pytest for test automation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Frontend (Next.js)"]:::frontend
        FE_P["Pages"]:::frontend
        FE_C["UI Components"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE["Backend (FastAPI)"]:::backend
        BE_R["API Routes"]:::backend
        BE_S["Business Logic (Services)"]:::backend
        BE_V["Data Validation (Schemas)"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        DBI["DB Integration (async SQLAlchemy)"]:::db
        DB["Database (PostgreSQL)"]:::db
        MIG["Migration (Alembic)"]:::db
    end

    %% Development Tools
    subgraph "Development Tools"
        DT1["Docker Compose"]:::dev
        DT2["Backend Dockerfile"]:::dev
        DT3["Frontend Dockerfile"]:::dev
        DT4["Tests & Seed Scripts"]:::dev
    end

    %% Relationships between Frontend nodes
    FE --> FE_P
    FE --> FE_C

    %% Relationships in Backend layer
    BE --> BE_R
    BE_R --> BE_S
    BE_S --> BE_V

    %% Inter-layer communications
    FE -->|"HTTP_calls"| BE
    BE -->|"DB_query"| DBI
    DBI -->|"persists_data"| DB
    MIG -->|"updates_schema"| DB

    %% Development Tools interactions
    DT1 --- FE
    DT1 --- BE
    DT1 --- DB

    %% Click Events
    click FE "https://github.com/vkatvell/general-ledger/tree/main/frontend/"
    click FE_P "https://github.com/vkatvell/general-ledger/tree/main/frontend/app"
    click FE_C "https://github.com/vkatvell/general-ledger/tree/main/frontend/components"
    click BE "https://github.com/vkatvell/general-ledger/tree/main/app/"
    click BE_R "https://github.com/vkatvell/general-ledger/tree/main/app/routes"
    click BE_S "https://github.com/vkatvell/general-ledger/tree/main/app/services"
    click BE_V "https://github.com/vkatvell/general-ledger/tree/main/app/schemas"
    click DBI "https://github.com/vkatvell/general-ledger/tree/main/app/db/"
    click MIG "https://github.com/vkatvell/general-ledger/tree/main/alembic/"
    click DT1 "https://github.com/vkatvell/general-ledger/blob/main/docker-compose.yml"
    click DT2 "https://github.com/vkatvell/general-ledger/tree/main/Dockerfile"
    click DT3 "https://github.com/vkatvell/general-ledger/blob/main/frontend/frontend.Dockerfile"

    %% Styles
    classDef frontend fill:#AEDFF7,stroke:#000,stroke-width:2px;
    classDef backend fill:#F7D6AE,stroke:#000,stroke-width:2px;
    classDef db fill:#C8E6C9,stroke:#000,stroke-width:2px;
    classDef dev fill:#FFCDD2,stroke:#000,stroke-width:2px;
```
