# ceres2808/f1-rag architecture

> Architecture diagram of the GitHub repository ceres2808/f1-rag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ceres2808/f1-rag
- Repository: https://github.com/ceres2808/f1-rag

## Overview

##### Project type and purpose
- From the file tree and README, this is a full-stack RAG (Retrieval-Augmented Generation) web app built with Next.js (App Router) and React + Tailwind. Its purpose is to answer Formula 1 questions by retrieving domain-specific knowledge and augmenting prompts sent to an LLM.

##### File structure
- Top-level:
- f1_rag/app/(preview)/api/chat/route.ts – Next.js API route that handles chat requests
- f1_rag/app/(preview)/page.tsx & layout.tsx – React pages and layouts
- f1_rag/components & components/ui – reusable UI components (chat interface, inputs, buttons, etc.)
- f1_rag/lib/ai/search.ts – core RAG logic: vector search + LLM call
- f1_rag/lib/utils.ts & env.mjs – environment loading and helpers
- Configuration: Dockerfile, .env.example, GitHub Actions workflow, Tailwind & PostCSS, tsconfig, ESLint
- Patterns: clear separation of frontend (React/TSX under app & components) vs backend logic (API routes + lib/ai).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser)"
        direction TB
        Page["page.tsx"]:::client
        Layout["layout.tsx"]:::client
        Globals["globals.css"]:::client
        ChatInterface["chat-interface.tsx"]:::client
        ChatInput["chat-input.tsx"]:::client
        MessageContainer["message-container.tsx"]:::client
        ProjectOverview["project-overview.tsx"]:::client
        subgraph "UI Components (components/ui)"
            Button["button.tsx"]:::client
            Input["input.tsx"]:::client
            Label["label.tsx"]:::client
            Drawer["drawer.tsx"]:::client
            Switch["switch.tsx"]:::client
            Resizable["resizable.tsx"]:::client
        end
    end

    %% Server Layer
    subgraph "Server (Next.js)"
        direction TB
        APIRoute["/api/chat Route"]:::server
    end

    %% AI Services Layer
    subgraph "AI Services"
        direction TB
        RAG["RAG Service (search.ts)"]:::ai
        EnvLoader["env.mjs"]:::ai
        Utils["utils.ts"]:::ai
    end

    %% External Services Layer
    subgraph "External Services"
        direction TB
        Vector["Vector Store"]:::external
        LLM["LLM Provider API"]:::external
    end

    %% Configuration & CI/CD
    subgraph "Configuration & CI/CD"
        direction TB
        Dockerfile["Dockerfile"]:::config
        EnvExample[".env.example"]:::config
        CIWF[".github/workflows/main.yml"]:::config
        Tailwind["tailwind.config.ts"]:::config
        PostCSS["postcss.config.mjs"]:::config
    end

    %% Data Flow
    ChatInterface -->|"user query"| APIRoute
    APIRoute -->|"invoke RAG service"| RAG
    RAG -->|"retrieve docs"| Vector
    Vector -->|"return passages"| RAG
    RAG -->|"call LLM"| LLM
    LLM -->|"response"| RAG
    RAG -->|"answer payload"| APIRoute
    APIRoute -->|"JSON response"| ChatInterface

    %% Click Events - Client
    click Page "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/app/(preview)/page.tsx"
    click Layout "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/app/(preview)/layout.tsx"
    click Globals "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/app/(preview)/globals.css"
    click ChatInterface "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/components/chat-interface.tsx"
    click ChatInput "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/components/chat-input.tsx"
    click MessageContainer "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/components/message-container.tsx"
    click ProjectOverview "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/components/project-overview.tsx"
    click Button "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/components/ui/button.tsx"
    click Input "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/components/ui/input.tsx"
    click Label "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/components/ui/label.tsx"
    click Drawer "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/components/ui/drawer.tsx"
    click Switch "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/components/ui/switch.tsx"
    click Resizable "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/components/ui/resizable.tsx"

    %% Click Events - Server & AI
    click APIRoute "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/app/(preview)/api/chat/route.ts"
    click RAG "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/lib/ai/search.ts"
    click EnvLoader "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/lib/env.mjs"
    click Utils "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/lib/utils.ts"

    %% Click Events - Config & CI/CD
    click Dockerfile "https://github.com/ceres2808/f1-rag/tree/main/f1_rag/Dockerfile"
    click EnvExample "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/.env.example"
    click CIWF "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/.github/workflows/main.yml"
    click Tailwind "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/tailwind.config.ts"
    click PostCSS "https://github.com/ceres2808/f1-rag/blob/main/f1_rag/postcss.config.mjs"

    %% Styles
    classDef client fill:#BBDEFB,stroke:#333,stroke-width:1px
    classDef server fill:#C8E6C9,stroke:#333,stroke-width:1px
    classDef ai fill:#FFE0B2,stroke:#333,stroke-width:1px
    classDef external fill:#EEEEEE,stroke:#333,stroke-width:1px
    classDef config fill:#F8BBD0,stroke:#333,stroke-width:1px
```
