# exa-labs/exa-deepseek-chat architecture

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

- Interactive diagram: https://gitdiagram.com/exa-labs/exa-deepseek-chat
- Repository: https://github.com/exa-labs/exa-deepseek-chat

## Overview

Key Components to Include:

##### Client-Side Layer
- Next.js Frontend components (located in app/page.tsx and app/layout.tsx)
- TailwindCSS styling integration

##### Server-Side Layer
- Next.js App Router (represented by the app/ directory structure)
- API Routes (shown in app/api/ directory):
- Chat endpoint (app/api/chat)
- Exawebsearch endpoint (app/api/exawebsearch)

##### External Services Layer
- Exa API for web search
- Fireworks AI API (hosting Deepseek R1 LLM)
- Vercel hosting platform

**┌─────────────────────────────────────────┐**
- Client Browser               │
- ┬───────────────────────┘
- ↓
**┌─────────────────────────────────────────┐**
- Next.js Frontend Layer          │
- ┌─────────────┐    ┌────────────────┐  │
- page.tsx   │    │   layout.tsx   │  │
- ┘    └────────────────┘  │
- ↓              ↓              │
- ┌─────────────────────────────────────┐│
- TailwindCSS Styling         ││
- ┴─────────────────┬───────────────────┘│
- ↓
**┌──────────────────────────────────────────┐**
- Next.js API Routes Layer         │
- ┌─────────────┐    ┌────────────────┐  │
- /api/chat   │    │/api/exawebsearch│  │
- ┬──────┘    └────────┬───────┘  │
- ┼─────────────────────┼─────────┘
- ↓                     ↓
**┌─────────────────┐    ┌────────────────┐**
- Fireworks AI   │    │    Exa API     │
- (Deepseek R1)  │    │  (Web Search)  │
- ┘    └────────────────┘

- Use blue for client-side components
- Use green for server-side components
- Use orange for external services
- Use grey for infrastructure components

Important Elements to Highlight:

##### Data Flow
- How user queries flow from the frontend through the API routes
- Parallel calls to Exa API for web search and Fireworks AI for LLM processing
- How responses are streamed back to the client

##### Integration Points
- Vercel AI SDK integration points
- API key authentication points for both Exa and Fireworks AI
- Where environment variables are used

##### Key Technologies
- Next.js App Router architecture
- TailwindCSS styling system
- TypeScript implementation
- Vercel deployment infrastructure

Additional Notes:
- Version numbers for major dependencies
- Middleware.ts integration point
- Where environment variables (.env) are used
- Error handling and fallback paths

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph NextFrontend["Next.js Frontend Layer"]
        Page["Main Page"]:::frontend
        Layout["Layout"]:::frontend
        Styling["Styling System"]:::frontend
        Utils["Utility Functions"]:::utils
        Fonts["Font Assets"]:::assets
    end

    subgraph APIRoutes["Next.js API Routes Layer"]
        ChatAPI["Chat API"]:::api
        SearchAPI["Web Search API"]:::api
        Middleware["API Middleware"]:::middleware
    end

    subgraph ExternalServices["External Services Layer"]
        FireworksAI["Fireworks AI<br/>(Deepseek R1)"]:::external
        ExaAPI["Exa API<br/>(Web Search)"]:::external
        Vercel["Vercel Platform"]:::infrastructure
    end

    subgraph Config["Configuration"]
        AppConfig["Application Config"]:::config
        TSConfig["TypeScript Config"]:::config
        EnvVars["Environment Variables"]:::config
    end

    %% Connections
    Browser --> Page
    Page --> Layout
    Page --> Styling
    Page --> Utils
    Layout --> Fonts
    Page --> ChatAPI
    Page --> SearchAPI
    ChatAPI --> Middleware
    SearchAPI --> Middleware
    Middleware --> FireworksAI
    Middleware --> ExaAPI
    ChatAPI --> FireworksAI
    SearchAPI --> ExaAPI
    ChatAPI --> EnvVars
    SearchAPI --> EnvVars

    %% Styling
    classDef frontend fill:#3b82f6,color:#fff
    classDef api fill:#22c55e,color:#fff
    classDef external fill:#f97316,color:#fff
    classDef infrastructure fill:#6b7280,color:#fff
    classDef config fill:#a855f7,color:#fff
    classDef middleware fill:#ec4899,color:#fff
    classDef utils fill:#14b8a6,color:#fff
    classDef assets fill:#8b5cf6,color:#fff

    %% Click events
    click Page "https://github.com/exa-labs/exa-deepseek-chat/blob/main/app/page.tsx"
    click Layout "https://github.com/exa-labs/exa-deepseek-chat/blob/main/app/layout.tsx"
    click Styling "https://github.com/exa-labs/exa-deepseek-chat/blob/main/app/globals.css"
    click ChatAPI "https://github.com/exa-labs/exa-deepseek-chat/blob/main/app/api/chat/route.ts"
    click SearchAPI "https://github.com/exa-labs/exa-deepseek-chat/blob/main/app/api/exawebsearch/route.ts"
    click AppConfig "https://github.com/exa-labs/exa-deepseek-chat/blob/main/next.config.mjs"
    click TSConfig "https://github.com/exa-labs/exa-deepseek-chat/blob/main/tsconfig.json"
    click Middleware "https://github.com/exa-labs/exa-deepseek-chat/blob/main/middleware.ts"
    click Utils "https://github.com/exa-labs/exa-deepseek-chat/blob/main/app/utils.ts"
    click Fonts "https://github.com/exa-labs/exa-deepseek-chat/tree/main/app/fonts"
```
