# trendy-design/llmchat architecture

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

- Interactive diagram: https://gitdiagram.com/trendy-design/llmchat
- Repository: https://github.com/trendy-design/llmchat

## Overview

##### Project Type and Purpose
- This is a full-stack, privacy-focused AI-powered chatbot platform built as a Turborepo monorepo.
- The “apps/web” directory holds a Next.js 14 application exposing both UI and serverless API routes.
- Shared libraries under “packages/” implement AI models/workflows, UI components, orchestration logic, local storage, and utility code.
- Primary goal: let users run advanced research and conversational workflows entirely in-browser (using IndexedDB) while orchestrating LLM calls to multiple external AI providers.

##### File Structure
- apps/web
– Next.js “app/” directory with pages (chat, sign-in/up, feedback, privacy, etc.)
– API routes under app/api (completion, feedback, mcp, messages) that call into shared AI and orchestrator packages.
– Configuration (Tailwind, Drizzle, Sentry) and a local Dexie.js (IndexedDB) setup for chat storage.
- packages/ai
– AI providers, tools, models, workflow definitions, and a web-worker setup for running orchestrated tasks client-side.
- packages/orchestrator
– A generic event-driven workflow engine with builders, context, and task lifecycle.
- packages/common & packages/shared
– React hooks, Zustand stores, types, context providers, utility functions, and environment/config.
- packages/ui
– A library of reusable design system components (buttons, dialogs, inputs, etc.).
- packages/prisma
– Prisma schema and migrations (used by desktop or any potential server component, even though apps/web persists chat locally).
- Other tooling
– Turborepo config, Bun, Husky, ESLint/Prettier, TypeScript configs, Tailwind config.

##### Key Architecture Insights from README
- Monorepo with clear separation: “apps” vs. “packages.”
- Frontend uses Next.js Server & Client Components, Framer Motion, Shadcn UI, Tiptap editor.
- Data persistence: all chat/history stored locally via Dexie.js (IndexedDB).
- AI integration: modular providers (OpenAI, Anthropic, etc.) behind a unified SDK.
- Workflow orchestration: event-emitter driven tasks (planning → gathering → analysis → reporting).
- No server-side chat storage; serverless functions only relay LLM calls and handle feedback, credit checks, or proxy needs.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Side"
        NextJS["Next.js Frontend\n(UI & Pages)"]:::frontend
        Worker["AI Workflow Worker\n(Web Worker)"]:::browser
        DBsync["DB Sync Worker\n(IndexedDB Sync)"]:::browser
        IndexedDB["IndexedDB (Dexie.js)"]:::browser
    end

    subgraph "Serverless/API Layer"
        API["API Routes\n(Completion, Feedback, MCP, Messages)"]:::api
    end

    subgraph "Shared Packages"
        AIpkg["AI Package\n(Providers, Models, Workflows)"]:::shared
        Orch["Orchestrator Engine"]:::shared
        UIlib["Design System Components"]:::shared
        CommonHooks["Common React Hooks & Zustand Stores"]:::shared
        SharedUtil["Shared Utilities & Config"]:::shared
        Prisma["Prisma Schema & Migrations"]:::shared
        TailwindCfg["Tailwind Configurations"]:::shared
    end

    subgraph "External Systems"
        LLM["LLM Providers\n(OpenAI, Anthropic, etc.)"]:::external
        Search["Web Search & Data Sources"]:::external
        Analytics["Analytics & Telemetry"]:::external
    end

    NextJS -->|"enqueues tasks"| Worker
    NextJS -->|"persists chat"| IndexedDB
    NextJS -->|"calls"| API
    NextJS -->|"uses hooks, stores"| CommonHooks
    NextJS -->|"uses UI lib"| UIlib
    NextJS -->|"uses shared utils"| SharedUtil
    NextJS -->|"uses tailwind config"| TailwindCfg
    NextJS -->|"sends analytics"| Analytics

    Worker -->|"orchestrates via"| Orch
    Worker -->|"calls ai sdk"| AIpkg
    Worker -->|"syncs data"| DBsync
    DBsync -->|"writes to"| IndexedDB
    AIpkg -->|"calls"| LLM
    AIpkg -->|"fetches data"| Search

    API -->|"uses ai sdk"| AIpkg
    API -->|"uses orchestrator"| Orch
    API -->|"uses shared utils"| SharedUtil
    API -->|"logs/analytics"| Analytics
    API -->|"credit checks/proxy"| LLM

    Analytics --> NextJS

    TailwindCfg --> UIlib

    subgraph "Optional Desktop/Server DB"
        Prisma
    end

    classDef frontend fill:#D0E6FF,stroke:#333,stroke-width:1px;
    classDef browser fill:#D0FFD6,stroke:#333,stroke-width:1px;
    classDef api fill:#FFE1B6,stroke:#333,stroke-width:1px;
    classDef shared fill:#E0E0E0,stroke:#333,stroke-width:1px;
    classDef external fill:#F3E6FF,stroke:#333,stroke-width:1px;

    click NextJS "https://github.com/trendy-design/llmchat/tree/main/apps/web/app"
    click API "https://github.com/trendy-design/llmchat/tree/main/apps/web/app/api"
    click AIpkg "https://github.com/trendy-design/llmchat/tree/main/packages/ai"
    click Orch "https://github.com/trendy-design/llmchat/tree/main/packages/orchestrator"
    click UIlib "https://github.com/trendy-design/llmchat/tree/main/packages/ui"
    click CommonHooks "https://github.com/trendy-design/llmchat/tree/main/packages/common"
    click SharedUtil "https://github.com/trendy-design/llmchat/tree/main/packages/shared"
    click DBsync "https://github.com/trendy-design/llmchat/blob/main/packages/common/store/db-sync.worker.ts"
    click Prisma "https://github.com/trendy-design/llmchat/tree/main/packages/prisma"
    click TailwindCfg "https://github.com/trendy-design/llmchat/tree/main/packages/tailwind-config"
```
