# enricoros/big-agi architecture

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

- Interactive diagram: https://gitdiagram.com/enricoros/big-agi
- Repository: https://github.com/enricoros/big-agi

## Overview

##### Main Components
- Backend API & Server Layer: Shown in the “app/api”, “src/server”, and “src/server/trpc” directories. These include REST‑like endpoints integrated with TRPC routers, environment configurations, and Prisma (database) configurations.
- Core Modules and Business Logic: The “src/modules” directory indicates a significant amount of business logic split into sub-modules (for LLM integration, beam processing, synchronization, file handling, external vendor integrations such as localAI, Ollama, and many others).
- Data & Database Layer: The “src/server/prisma” folder (including schema.prisma) suggests a relational database managed via Prisma.
- Providers & Shared Utilities: The “src/common” directory holds shared configuration, theming, state management (various “stores”), loggers, hooks, and utility functions which tie together frontend and backend functionality.
- Infrastructure & Deployment: With files like Dockerfile, docker-compose.yaml, and the “docs” folder that contains deployment and configuration guides (for Kubernetes, Cloudflare, Docker, etc.), infrastructure elements are clearly defined.

##### Relationships and Interactions
- Shared utilities and providers (in “src/common”) are used throughout the system (both client and server). Mark these as common libraries that “inject” functionality into various components.

##### Architectural Patterns and Design Principles
- Component-Based UI: The frontend is built using React with a folder structure that groups components, hooks, and layouts.
- API Gateway/Router Pattern: TRPC routers consolidate API calls and manage data transformation, acting as a gateway between user requests and business logic.
- Containerization and Deployment: Clearly note Docker, docker-compose, and assorted docs for deployment strategies (Kubernetes, Cloudflare, etc.), indicating that the system is built with cloud and edge deployment in mind.

##### Relevant Technologies, Frameworks, and Libraries
- Frontend: Next.js, React, various React hooks and state management solutions.
- API/Backend: TRPC, Node.js, Next.js API routes.
- Database: Prisma with a relational database.
- Deployment: Docker, Kubernetes (via provided YAML files), Cloudflare.
- Integrations: Multiple AI model vendors (OpenAI, Anthropic, Gemini, etc.), external integrations (Browserless, Google CSE, CodePen, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD

  subgraph "Frontend Layer"
    FP["Pages"]:::frontend
    FA["App"]:::frontend
    FPub["Public"]:::frontend
    FApps["Apps"]:::frontend
  end

  subgraph "Backend/API Layer"
    BA["API Routes"]:::backend
    BS["Server"]:::backend
    BT["tRPC Endpoints"]:::backend
  end

  subgraph "Business Logic Layer"
    CM["Core Modules"]:::modules
    MA["Middleware AUTH"]:::modules
    AIX["AIX Integration"]:::modules
    LL["LLMs Vendors"]:::modules
  end

  subgraph "Database Layer"
    DB["Prisma DB"]:::db
  end

  subgraph "Providers/Utilities"
    SU["Shared Utilities"]:::providers
  end

  subgraph "Infrastructure/Deployment"
    DF["Dockerfile"]:::infra
    DC["Docker Compose"]:::infra
    DOC["Documentation"]:::infra
  end

  subgraph "External Integrations"
    EX["External AI Vendors"]:::external
  end

  %% Connections from Frontend to Backend
  FP -->|"sends_request"| BA
  FA -->|"sends_request"| BA
  FPub -->|"sends_request"| BA
  FApps -->|"sends_request"| BA

  %% Connections within Backend
  BS --> BT
  BA -->|"calls"| CM
  BT -->|"calls"| CM

  %% Business Logic interactions
  CM -->|"queries"| DB
  DB -->|"responds"| CM
  CM -->|"integrates"| EX
  CM -->|"invokes"| MA
  CM -->|"invokes"| AIX
  CM -->|"invokes"| LL

  %% Providers Injection (dotted lines)
  SU ---|"injects"| FP
  SU ---|"injects"| BA

  %% Infrastructure support connections
  DF --- BA
  DF --- CM
  DF --- DB
  DC --- BA
  DOC --- DF

  %% Click Events for Frontend
  click FP "https://github.com/enricoros/big-agi/tree/v2-dev/pages"
  click FA "https://github.com/enricoros/big-agi/tree/v2-dev/app"
  click FPub "https://github.com/enricoros/big-agi/tree/v2-dev/public"
  click FApps "https://github.com/enricoros/big-agi/tree/v2-dev/src/apps"

  %% Click Events for Backend/API
  click BA "https://github.com/enricoros/big-agi/tree/v2-dev/app/api"
  click BS "https://github.com/enricoros/big-agi/tree/v2-dev/src/server"
  click BT "https://github.com/enricoros/big-agi/tree/v2-dev/src/server/trpc"

  %% Click Events for Business Logic & Middleware
  click CM "https://github.com/enricoros/big-agi/tree/v2-dev/src/modules"
  click MA "https://github.com/enricoros/big-agi/blob/v2-dev/middleware_BASIC_AUTH.ts"
  click AIX "https://github.com/enricoros/big-agi/tree/v2-dev/src/modules/aix"
  click LL "https://github.com/enricoros/big-agi/tree/v2-dev/src/modules/llms/vendors"

  %% Click Event for Database
  click DB "https://github.com/enricoros/big-agi/tree/v2-dev/src/server/prisma"

  %% Click Event for Providers
  click SU "https://github.com/enricoros/big-agi/tree/v2-dev/src/common"

  %% Click Events for Infrastructure
  click DF "https://github.com/enricoros/big-agi/tree/v2-dev/Dockerfile"
  click DC "https://github.com/enricoros/big-agi/blob/v2-dev/docker-compose.yaml"
  click DOC "https://github.com/enricoros/big-agi/tree/v2-dev/docs"

  classDef frontend fill:#AEDFF7,stroke:#000,stroke-width:2px;
  classDef backend fill:#C1E1C1,stroke:#000,stroke-width:2px;
  classDef modules fill:#FFD59E,stroke:#000,stroke-width:2px;
  classDef db fill:#FFF2B2,stroke:#000,stroke-width:2px;
  classDef providers fill:#D3D3D3,stroke:#000,stroke-width:2px;
  classDef infra fill:#F5B7B1,stroke:#000,stroke-width:2px;
  classDef external fill:#F7D6E0,stroke:#000,stroke-width:2px;
```
