# geniewizards/zenmo architecture

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

- Interactive diagram: https://gitdiagram.com/geniewizards/zenmo
- Repository: https://github.com/geniewizards/zenmo

## Overview

##### Main Components Identification
- Common Utilities and Middlewares: Identify a shared “common” layer (src/common) that includes helper functions, middlewares (e.g., authentication, error handling, logging), and utility libraries. These act as cross-cutting concerns.
- External Services: Optionally, include components for external integrations like authentication services (using Lucia Auth) or any external API that may interact with the OpenAPI documentation.
- Containerization & Deployment: Highlight Docker and Docker Compose configuration files (Dockerfile, docker-compose.yml, Makefile commands) which manage deployment and environment orchestration.
- Testing Infrastructure: Acknowledge the k6 test configuration and test scripts (inside the k6 directory) for load testing, indicating that tests are routed externally to validate API performance.

##### Relationships/Interactions
- Within the server, routes are directed to specific modules that handle requests, possibly via middleware (authentication, logging, error handling).
- These modules then interact with the database layer, where repositories and database adapters (using Drizzle) manage CRUD operations.
- To include dependency links from the modules and common utilities to shared middleware and helper functions.

##### Architectural Patterns & Design Principles
- Modular Design: The project is organized into modules; represent each module as a self-contained unit.
- Separation of Concerns: Divide the system into API routing, business logic (modules), common services (helpers, middleware), and data persistence.
- Containerization: Include Docker and Docker Compose as part of the deployment process which encapsulates the environment.
- Testing Integration: Show that tests (both unit/integration and performance tests with k6) interact with the system to ensure quality.

##### Relevant Technologies, Frameworks, and Libraries
- Languages & Runtimes: TypeScript, Bun.
- ORM/Database: Drizzle (with PostgreSQL).
- Authentication: Lucia Auth.
- API Documentation: OpenAPI & Scalar.
- Containerization: Docker & Docker Compose.
- Testing: Bun’s built-in testing along with k6 for performance scenarios.

##### Elements
- Clear labels: Ensure every component and module (like “Accounts Module”, “Auth Module”, “Database Adapter”, “Middleware”) is clearly marked.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Level: External Client
    EC["API Client"]:::external

    %% API Gateway Layer
    subgraph "API Gateway"
        APIServer["API Server"]:::server
    end

    %% Modules Layer
    subgraph "Modules Layer"
        MR["Modules Router"]:::module
        AM["Accounts Module"]:::module
        AC["Activities Module"]:::module
        AUTH["Auth Module"]:::module
        CAT["Categories Module"]:::module
        EXP["Expenses Module"]:::module
        GRP["Group Module"]:::module
        HC["Health-check Module"]:::module
        SES["Sessions Module"]:::module
        SET["Settlements Module"]:::module
        SPL["Splits Module"]:::module
        USR["Users Module"]:::module
    end

    %% Common Utilities and Middlewares
    subgraph "Common Utilities"
        CH["Helpers & Utilities"]:::common
        CM["Middlewares"]:::common
        CS["Common Schemas"]:::common
    end

    %% Database Layer
    subgraph "Database Layer"
        DBA["Database Adapter"]:::db
        DBS["Database Schemas"]:::db
        DBM["Migrations"]:::db
        DBScr["Database Scripts"]:::db
    end

    %% External Services
    subgraph "External Services"
        LA["Lucia Authentication"]:::external
        OAPI["OpenAPI/Scalar Docs"]:::external
    end

    %% Deployment & Containerization
    subgraph "Deployment & Containerization"
        DF["Dockerfile"]:::container
        DC["Docker Compose"]:::container
        DCD["Docker Compose (Dev)"]:::container
        MF["Makefile"]:::container
    end

    %% Testing Infrastructure
    subgraph "Testing Suite"
        K6["k6 Testing"]:::testing
    end

    %% Connections
    EC -->|"HTTP_request"| APIServer
    APIServer -->|"Routes_to"| MR

    %% Modules Router to individual Modules
    MR -->|"handles"| AM
    MR -->|"handles"| AC
    MR -->|"handles"| AUTH
    MR -->|"handles"| CAT
    MR -->|"handles"| EXP
    MR -->|"handles"| GRP
    MR -->|"handles"| HC
    MR -->|"handles"| SES
    MR -->|"handles"| SET
    MR -->|"handles"| SPL
    MR -->|"handles"| USR

    %% Modules Layer using Common Utilities
    MR ---|"uses_helpers"| CH
    MR ---|"uses_middleware"| CM
    MR ---|"uses_schema"| CS

    %% Modules Layer interacting with Database Layer
    MR -->|"DB_query"| DBA

    %% API Server interacting with External Services
    APIServer -->|"Auth"| LA
    APIServer -->|"Docs"| OAPI

    %% API Server deployed via Containerization
    APIServer ---|"Containerized"| DF
    APIServer ---|"Containerized"| DC
    APIServer ---|"Containerized"| DCD
    APIServer ---|"Containerized"| MF

    %% Testing flows from Testing Suite to API Server
    K6 -->|"Load_tests"| APIServer

    %% Click Events for API Server Entry Points
    click APIServer "https://github.com/geniewizards/zenmo/blob/main/src/app.ts"
    click APIServer "https://github.com/geniewizards/zenmo/blob/main/src/index.ts"

    %% Click Events for Modules Layer
    click AM "https://github.com/geniewizards/zenmo/tree/main/src/modules/accounts"
    click AC "https://github.com/geniewizards/zenmo/tree/main/src/modules/activities"
    click AUTH "https://github.com/geniewizards/zenmo/tree/main/src/modules/auth"
    click CAT "https://github.com/geniewizards/zenmo/tree/main/src/modules/categories"
    click EXP "https://github.com/geniewizards/zenmo/tree/main/src/modules/expenses"
    click GRP "https://github.com/geniewizards/zenmo/tree/main/src/modules/group"
    click HC "https://github.com/geniewizards/zenmo/tree/main/src/modules/health-check"
    click SES "https://github.com/geniewizards/zenmo/tree/main/src/modules/sessions"
    click SET "https://github.com/geniewizards/zenmo/tree/main/src/modules/settlements"
    click SPL "https://github.com/geniewizards/zenmo/tree/main/src/modules/splits"
    click USR "https://github.com/geniewizards/zenmo/tree/main/src/modules/users"

    %% Click Events for Common Utilities and Middlewares
    click CH "https://github.com/geniewizards/zenmo/tree/main/src/common/helpers"
    click CH "https://github.com/geniewizards/zenmo/tree/main/src/common/lib"
    click CH "https://github.com/geniewizards/zenmo/tree/main/src/common/utils"
    click CM "https://github.com/geniewizards/zenmo/tree/main/src/common/middlewares"
    click CS "https://github.com/geniewizards/zenmo/tree/main/src/common/schema"

    %% Click Events for Database Layer
    click DBA "https://github.com/geniewizards/zenmo/blob/main/src/db/adapter.ts"
    click DBS "https://github.com/geniewizards/zenmo/tree/main/src/db/schemas"
    click DBM "https://github.com/geniewizards/zenmo/tree/main/src/db/migrations"
    click DBScr "https://github.com/geniewizards/zenmo/tree/main/src/db/scripts"

    %% Click Events for External Services
    click LA "https://github.com/geniewizards/zenmo/tree/main/src/modules/auth"
    click OAPI "https://github.com/geniewizards/zenmo/blob/main/src/common/lib/configure-open-api.lib.ts"

    %% Click Events for Deployment & Containerization
    click DF "https://github.com/geniewizards/zenmo/tree/main/Dockerfile"
    click DC "https://github.com/geniewizards/zenmo/blob/main/docker-compose.yml"
    click DCD "https://github.com/geniewizards/zenmo/blob/main/docker-compose.dev.yml"
    click MF "https://github.com/geniewizards/zenmo/tree/main/Makefile"

    %% Click Event for Testing Infrastructure
    click K6 "https://github.com/geniewizards/zenmo/tree/main/k6"

    %% Styles
    classDef external fill:#f9e79f,stroke:#d35400,stroke-width:2px;
    classDef server fill:#aed6f1,stroke:#2874a6,stroke-width:2px;
    classDef module fill:#abebc6,stroke:#229954,stroke-width:2px;
    classDef common fill:#fadbd8,stroke:#c0392b,stroke-width:2px;
    classDef db fill:#f7dc6f,stroke:#b7950b,stroke-width:2px;
    classDef container fill:#d6eaf8,stroke:#2471a3,stroke-width:2px;
    classDef testing fill:#f5b7b1,stroke:#cb4335,stroke-width:2px;
```
