# human-bee/thought-partners architecture

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

- Interactive diagram: https://gitdiagram.com/human-bee/thought-partners
- Repository: https://github.com/human-bee/thought-partners

## Overview

##### Main Components
- Frontend Interface: Represent the Next.js application—the primary user interface. This includes individual pages like the whiteboard (with room-based collaboration), videoconference, transcription board, and debugging/test pages.
- Whiteboard Module: Highlight integration with TLDraw, visible in pages under “/whiteboard” and supporting components such as the “CollaborativeBoard.”
- Video Conferencing Module: Illustrate LiveKit integration, covering both API route endpoints (e.g., /api/livekit, /api/refresh-token) and UI components (such as VideoConference, VideoConferenceContext, and Connection/Device Managers).
- Authentication & Token Management: Capture the API endpoints like create-agent, get-token, and refresh-token which secure room access by issuing and refreshing LiveKit tokens.
- Speech-to-Text Transcription: Include components and contexts for transcription (e.g., TranscriptionBoard, useSpeechRecognition, and TranscriptionContext) that translate audio streams into whiteboard annotations.

##### Relationships and Interactions
- That user actions in the frontend (e.g., joining a room) trigger API calls to authentication endpoints which in turn interface with the LiveKit cloud service.
- Data flow between LiveKit’s real-time video streams and the frontend UI components that render video as well as visual debugging tools (e.g., LiveKitDebugger).

##### Architectural Patterns and Principles
- Modular Design: Identify that the project is partitioned into clearly defined modules (whiteboard, videoconference, transcription) each with their dedicated components, contexts, and utilities.
- Real-Time Communication: Emphasize the bidirectional data flow required for real-time collaboration, including live updates from both TLDraw-drawn content and video/audio streams.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side (Next.js UI)
    subgraph "Client Side (Next.js UI)"
        U1("Frontend Interface (Next.js App)"):::ui
        WBP("Whiteboard Page (/whiteboard/[roomId])"):::ui
        CB("CollaborativeBoard"):::ui
        VCP("Video Conference Page"):::ui
        VC("VideoConference"):::ui
        CM("ConnectionManager"):::ui
        DM("DeviceManager"):::ui
        VCC("VideoConference Context"):::ui
        TBP("Transcription Board Page"):::ui
        TB("TranscriptionBoard"):::ui
        TC("TranscriptionCanvas"):::ui
        TCC("Transcription Context"):::ui
    end

    %% Backend/API Layer
    subgraph "Backend/API"
        CA("Create Agent API"):::api
        GT("Get Token API"):::api
        RT("Refresh Token API"):::api
        LKA("LiveKit API"):::api
        LKDA("LiveKit Diagnostics API"):::api
    end

    %% External Services
    subgraph "External Services"
        LKC("LiveKit Cloud Service"):::external
    end

    %% User Interaction
    User("User"):::ui
    User -->|"interacts"| U1

    %% Frontend Routing & Component Rendering
    U1 -->|"routesTo"| WBP
    WBP -->|"renders"| CB

    U1 -->|"routesTo"| VCP
    VCP -->|"includes"| VC
    VCP -->|"includes"| CM
    VCP -->|"includes"| DM
    VCP -->|"uses"| VCC

    U1 -->|"routesTo"| TBP
    TBP -->|"renders"| TB
    TBP -->|"renders"| TC
    TBP -->|"uses"| TCC
    TB -->|"annotates"| CB

    %% API Calls from Frontend
    U1 -->|"calls"| CA
    U1 -->|"calls"| GT
    U1 -->|"calls"| RT

    %% API and External Service Interaction
    CA -->|"triggers"| LKC
    GT -->|"triggers"| LKC
    RT -->|"triggers"| LKC

    LKA -->|"communicatesWith"| LKC
    LKDA -->|"diagnoses"| LKC

    %% Click Events for Component Mappings
    click U1 "https://github.com/human-bee/thought-partners/tree/main/src/app"
    click WBP "https://github.com/human-bee/thought-partners/blob/main/src/app/whiteboard/[roomId]/page.tsx"
    click CB "https://github.com/human-bee/thought-partners/blob/main/src/components/CollaborativeBoard.tsx"
    click VCP "https://github.com/human-bee/thought-partners/blob/main/src/app/videoconference/page.tsx"
    click VC "https://github.com/human-bee/thought-partners/blob/main/src/components/videoconference/VideoConference.tsx"
    click CM "https://github.com/human-bee/thought-partners/blob/main/src/components/videoconference/ConnectionManager.tsx"
    click DM "https://github.com/human-bee/thought-partners/blob/main/src/components/videoconference/DeviceManager.tsx"
    click VCC "https://github.com/human-bee/thought-partners/blob/main/src/contexts/VideoConferenceContext.tsx"
    click CA "https://github.com/human-bee/thought-partners/blob/main/src/app/api/create-agent/route.ts"
    click GT "https://github.com/human-bee/thought-partners/blob/main/src/app/api/get-token/route.ts"
    click RT "https://github.com/human-bee/thought-partners/blob/main/src/app/api/refresh-token/route.ts"
    click TBP "https://github.com/human-bee/thought-partners/blob/main/src/app/transcription-board/page.tsx"
    click TB "https://github.com/human-bee/thought-partners/blob/main/src/components/TranscriptionBoard.tsx"
    click TC "https://github.com/human-bee/thought-partners/blob/main/src/components/TranscriptionCanvas.tsx"
    click TCC "https://github.com/human-bee/thought-partners/blob/main/src/contexts/TranscriptionContext.tsx"
    click LKA "https://github.com/human-bee/thought-partners/blob/main/src/app/api/livekit/route.ts"
    click LKDA "https://github.com/human-bee/thought-partners/blob/main/src/app/api/livekit-diagnostics/route.ts"

    %% Styling for different layers
    classDef ui fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef api fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef external fill:#ffe0b2,stroke:#e65100,stroke-width:2px;
```
