# futurpanda/capsule architecture

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

- Interactive diagram: https://gitdiagram.com/futurpanda/capsule
- Repository: https://github.com/futurpanda/capsule

## Overview

##### Main Components
- Backend Server: Represent the “packages/server” as the central API/backend component. This part includes numerous modules (authentication, dynamic queries, events, migrations, databases, tasks, users, etc.) and supports features like OAuth and dynamic SQL generation. Indicate its NestJS architecture, integration of controllers, services, repositories, and decorators.
- Client Libraries & UI Components: Show the “packages/capsule-client” (a client library that handles API calls) and “packages/capsule-kit” (a UI/React-based kit with extensive UI components, hooks, and state management, including routes, layouts, and widgets). These provide the front-end framework.
- Demo Applications: Illustrate “packages/demo1” and “packages/demo2” as example implementations or sample applications that use the capsule-client and capsule-kit.
- Public Website: Include “packages/www” where the public-facing website (using Svelte and related UI components) lives, as an independent front-end application.
- Shared Types: Represent “packages/shared-types” as a core module holding common type definitions and interfaces shared between the client and server.
- Documentation: Represent “packages/docs” as the documentation site built (likely with Astro judging by the astro.config.mjs) that details usage, architecture, and guides.
- Open API Definitions: Include the “.open-api” folder as a source for API schema definitions, which can be used for API consumers and auto-generation of docs.
- Infrastructure & Deployment: Note the presence of Dockerfiles, GitHub workflow definitions (.github/workflows), and changesets that help manage deployment, versioning, and continuous integration. These components underpin how the system is built and deployed rather than being runtime components.

##### Relationships and Data Flow
- Backend Server to the Database (even if the actual database isn’t in the source tree, the server’s migration files, changelogs, and “databases” modules imply a relational or similar persistent storage system).
- A two-way dependency between Shared Types and both the client components and the server to emphasize type safety and shared interfaces.

##### Important Architectural Patterns
- Modular Architecture: The backend clearly uses a modular design (several modules with controllers, services, repositories, and utility folders for decorators, pipes, etc.). Represent each major module as a sub-component of the “Backend Server.”
- Component-Based Frontend: With capsule-kit and www relying on modern UI frameworks (React/TSX for capsule-kit and Svelte for www), the client side should reflect a clear component hierarchy.
- Shared Contract: The shared-types module underlines a commitment to strong typing and shared contracts between services and clients.
- Versioning & Deployment: Changesets, Dockerfiles, and CI/CD workflows point to modern DevOps practices.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Components
    subgraph "Frontend Components"
        CL["Capsule Client"]:::frontend
        CK["Capsule Kit"]:::frontend
        D1["Demo Application 1"]:::frontend
        D2["Demo Application 2"]:::frontend
        WWW["Public Website"]:::frontend
    end

    %% Shared Types (used by both frontend and backend)
    ST["Shared Types"]:::shared

    %% Backend Server and its Modules
    subgraph "Backend Server"
        BE["Backend API (NestJS)"]:::backend
        subgraph "Backend Modules"
            AUTH["Authentication Module"]:::backend
            DYN["Dynamic Queries Module"]:::backend
            EVT["Events Module"]:::backend
            MIG["Migrations Module"]:::backend
            DB["Database Integration"]:::database
            TSK["Tasks Module"]:::backend
            USR["Users Module"]:::backend
        end
    end

    %% Documentation and Open API Definitions
    DOC["Documentation"]:::docs
    OAPI["Open API Definitions"]:::docs

    %% Infrastructure & Deployment
    subgraph "Infrastructure & Deployment"
        DOCKER["Dockerfile"]:::infra
        GH["GitHub Workflows"]:::infra
        CHNG["Changesets"]:::infra
        INFRA["Infra Folder"]:::infra
        FLY["fly.toml"]:::infra
    end

    %% Connections between Frontend and Backend
    CL -->|"HTTP_requests"| BE
    CK -->|"HTTP_requests"| BE
    D1 -->|"HTTP_requests"| BE
    D2 -->|"HTTP_requests"| BE
    WWW -->|"HTTP_requests"| BE

    %% Connection: Shared Types used by both Backend and Frontend
    ST ---|"shared_contract"| BE
    ST ---|"shared_contract"| CL
    ST ---|"shared_contract"| CK
    ST ---|"shared_contract"| D1
    ST ---|"shared_contract"| D2
    ST ---|"shared_contract"| WWW

    %% Connection inside Backend: Backend API includes modules
    BE --> AUTH
    BE --> DYN
    BE --> EVT
    BE --> MIG
    BE --> DB
    BE --> TSK
    BE --> USR

    %% Connection: Backend API uses Open API Definitions
    OAPI ---|"API_contract"| BE
    OAPI ---|"API_contract"| DOC

    %% Connection: Documentation details the system architecture
    DOC ---|"docs_about"| BE

    %% Infrastructure supports Backend deployment
    DOCKER ---|"deploys"| BE
    GH ---|"CI/CD"| BE
    CHNG ---|"versioning"| BE
    INFRA ---|"provisions"| BE
    FLY ---|"orchestrates"| BE

    %% Styling Classes
    classDef backend fill:#ffcccc,stroke:#ff0000,stroke-width:2px;
    classDef frontend fill:#ccffcc,stroke:#00aa00,stroke-width:2px;
    classDef database fill:#ffffcc,stroke:#ffaa00,stroke-width:2px;
    classDef shared fill:#ccccff,stroke:#0000ff,stroke-width:2px;
    classDef docs fill:#e0ccff,stroke:#aa00aa,stroke-width:2px;
    classDef infra fill:#ffe6cc,stroke:#ff6600,stroke-width:2px;

    %% Click Events
    click BE "https://github.com/futurpanda/capsule/tree/dev/packages/server"
    click CL "https://github.com/futurpanda/capsule/tree/dev/packages/capsule-client"
    click CK "https://github.com/futurpanda/capsule/tree/dev/packages/capsule-kit"
    click D1 "https://github.com/futurpanda/capsule/tree/dev/packages/demo1"
    click D2 "https://github.com/futurpanda/capsule/tree/dev/packages/demo2"
    click WWW "https://github.com/futurpanda/capsule/tree/dev/packages/www"
    click ST "https://github.com/futurpanda/capsule/tree/dev/packages/shared-types"
    click DOC "https://github.com/futurpanda/capsule/tree/dev/packages/docs"
    click OAPI "https://github.com/futurpanda/capsule/blob/dev/.open-api"
    click DOCKER "https://github.com/futurpanda/capsule/tree/dev/Dockerfile"
    click GH "https://github.com/futurpanda/capsule/tree/dev/.github/workflows"
    click CHNG "https://github.com/futurpanda/capsule/blob/dev/.changeset"
    click INFRA "https://github.com/futurpanda/capsule/blob/dev/packages/.infra"
    click FLY "https://github.com/futurpanda/capsule/blob/dev/fly.toml"
```
