# copilotkit/demo-presentation architecture

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

- Interactive diagram: https://gitdiagram.com/copilotkit/demo-presentation
- Repository: https://github.com/copilotkit/demo-presentation

## Overview

##### Project type and purpose
- This is a full-stack, server-rendered web application built on Next.js 13 (app router) that lets users build and navigate PowerPoint-like presentations in the browser.
- It leverages CopilotKit (LangChain + LangGraph) for AI-driven slide generation and research, Tavily for web research, OpenAI for text-to-speech, and a transcription endpoint for audio input.

##### File structure
- Top level
- next.config.mjs, tsconfig.json, Tailwind & PostCSS configs, package.json → standard Next.js/TypeScript setup.
- src/app/
- layout.tsx, page.tsx → Next.js layout + main entry point.
- components/
– buttons/ → UI controls (add, delete, generate slide, speak, research toggle).
– main/ → core presentation components (Header, Presentation container, Slide).
– misc/ → slide preview, number indicator.
- actions/ → React Server Actions or client hooks (useAppendSlide, useUpdateSlide) that mutate slide state.
- api/
– /copilotkit/research.ts & route.ts → serverless endpoint that invokes the CopilotKit researchAction using LangChain/Tavily.
– /tts/route.ts → serverless endpoint to generate speech via OpenAI TTS.
– /transcribe/route.ts → endpoint to transcribe audio inputs.
- utils/globalAudio.tsx → client audio playback manager.
- types.ts → shared TypeScript interfaces.

##### Extract architecture cues from the README
- Deploys on Vercel as serverless functions (Next.js API routes).
- Requires environment variables: NEXT_PUBLIC_COPILOT_CLOUD_API_KEY, TAVILY_API_KEY, OPENAI_API_KEY.
- Frontend makes calls to backend routes; backend routes proxy to external services (CopilotKit Cloud, Tavily, OpenAI).

- Client (Browser): Next.js/React UI, Tailwind styling
- CDN / Static Assets: public/ folder
- State & Hooks: useAppendSlide, useUpdateSlide, useMakeCopilotReadable (in components)
- Next.js Server (Vercel)
- App Server (SSR/SSG)
- API Routes
 /api/copilotkit/research
 /api/tts
 /api/transcribe
- External Services
- CopilotKit Cloud API (LangChain + LangGraph)
- Tavily Research API
- OpenAI API (TTS)
- UI → (user action) → client hooks → Next.js API route → external service → JSON response → next.js server → client UI updates state
- UI “Speak” button → /api/tts → audio blob → globalAudio.play()
- Optional: audio capture → /api/transcribe → plain text → injected into slide content
c. Architectural patterns & principles
- Full-stack separation: React on client vs serverless API endpoints
- Server Actions / React Hooks to encapsulate side effects
- Micro-service style API routes in Next.js
- No persistent database: state lives in client memory; persistence can be added with a DB later
d. Key technologies/frameworks
- Next.js 13 (app directory, Server Components, API routes)
- React + TypeScript + Tailwind CSS
- CopilotKit (LangChain + LangGraph)
- Tavily API for web research
- OpenAI for TTS
- Vercel for hosting (serverless functions)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend" 
        direction TB
        Browser["Client (Browser)\nNext.js/React UI\nTailwind CSS"]:::frontend

        subgraph "Layout & Entry"
            direction TB
            Layout["layout.tsx"]:::frontend
            Page["page.tsx"]:::frontend
        end

        subgraph "UI Components"
            direction TB
            subgraph Buttons
                direction TB
                AB["AddSlideButton"]:::frontend
                DB["DeleteSlideButton"]:::frontend
                GB["GenerateSlideButton"]:::frontend
                SB["SpeakCurrentSlideButton"]:::frontend
                PRS["PerformResearchSwitch"]:::frontend
                NB["NavButton"]:::frontend
                EB["ActionButton"]:::frontend
            end
            subgraph Main
                direction TB
                HDR["Header"]:::frontend
                PRES["Presentation"]:::frontend
                SL["Slide"]:::frontend
            end
            subgraph Misc
                direction TB
                SNI["SlideNumberIndicator"]:::frontend
                SPV["SlidePreview"]:::frontend
            end
        end

        subgraph "State & Hooks"
            direction TB
            APL["useAppendSlide"]:::frontend
            UPD["useUpdateSlide"]:::frontend
        end

        UTIL["globalAudio.tsx"]:::frontend
        TYPES["types.ts"]:::frontend
        CDN["Static Assets\n(public/)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Next.js Server/API)"
        direction TB
        subgraph "API Routes"
            direction TB
            RSR["/api/copilotkit/research"]:::backend
            TTS["/api/tts"]:::backend
            TRC["/api/transcribe"]:::backend
        end
    end

    %% External Services
    subgraph "External Services"
        direction TB
        CK["CopilotKit Cloud API"]:::external
        TV["Tavily Research API"]:::external
        OA["OpenAI API (TTS)"]:::external
    end

    %% Connections
    Browser --> Layout
    Browser --> Page
    Browser --> CDN

    AB --> APL
    DB --> UPD
    GB -->|"POST slide content → researchAction"| RSR
    SB -->|"POST text → generate speech"| TTS
    SPV -->|"upload audio → transcribe"| TRC

    APL --> Page
    UPD --> Page

    RSR -->|"requests research"| CK
    RSR -->|"requests web research"| TV
    RSR --> Page

    TTS -->|"requests TTS"| OA
    TTS --> UTIL
    UTIL --> Page

    TRC --> Page

    %% Click Events
    click Layout "https://github.com/copilotkit/demo-presentation/blob/main/src/app/layout.tsx"
    click Page "https://github.com/copilotkit/demo-presentation/blob/main/src/app/page.tsx"
    click AB "https://github.com/copilotkit/demo-presentation/blob/main/src/app/components/buttons/AddSlideButton.tsx"
    click DB "https://github.com/copilotkit/demo-presentation/blob/main/src/app/components/buttons/DeleteSlideButton.tsx"
    click GB "https://github.com/copilotkit/demo-presentation/blob/main/src/app/components/buttons/GenerateSlideButton.tsx"
    click SB "https://github.com/copilotkit/demo-presentation/blob/main/src/app/components/buttons/SpeakCurrentSlideButton.tsx"
    click PRS "https://github.com/copilotkit/demo-presentation/blob/main/src/app/components/buttons/PerformResearchSwitch.tsx"
    click NB "https://github.com/copilotkit/demo-presentation/blob/main/src/app/components/buttons/NavButton.tsx"
    click EB "https://github.com/copilotkit/demo-presentation/blob/main/src/app/components/buttons/ActionButton.tsx"
    click HDR "https://github.com/copilotkit/demo-presentation/blob/main/src/app/components/main/Header.tsx"
    click PRES "https://github.com/copilotkit/demo-presentation/blob/main/src/app/components/main/Presentation.tsx"
    click SL "https://github.com/copilotkit/demo-presentation/blob/main/src/app/components/main/Slide.tsx"
    click SNI "https://github.com/copilotkit/demo-presentation/blob/main/src/app/components/misc/SlideNumberIndicator.tsx"
    click SPV "https://github.com/copilotkit/demo-presentation/blob/main/src/app/components/misc/SlidePreview.tsx"
    click APL "https://github.com/copilotkit/demo-presentation/blob/main/src/app/actions/useAppendSlide.tsx"
    click UPD "https://github.com/copilotkit/demo-presentation/blob/main/src/app/actions/useUpdateSlide.tsx"
    click RSR "https://github.com/copilotkit/demo-presentation/blob/main/src/app/api/copilotkit/research.ts"
    click TTS "https://github.com/copilotkit/demo-presentation/blob/main/src/app/api/tts/route.ts"
    click TRC "https://github.com/copilotkit/demo-presentation/blob/main/src/app/api/transcribe/route.ts"
    click UTIL "https://github.com/copilotkit/demo-presentation/blob/main/src/app/utils/globalAudio.tsx"
    click TYPES "https://github.com/copilotkit/demo-presentation/blob/main/src/app/types.ts"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#1f77b4,color:#0b3d91
    classDef backend fill:#d4edda,stroke:#2e7d32,color:#1b5e20
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#343a40
```
