# floguo/mind-map architecture

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

- Interactive diagram: https://gitdiagram.com/floguo/mind-map
- Repository: https://github.com/floguo/mind-map

## Overview

##### Project type and purpose
- This is a full-stack web application (“PDF Mind Map Maker”) built on Next.js 14 with the App Router.
- It enables users to upload a PDF, sends it through a Google Gemini Pro AI pipeline (via Vercel’s AI SDK) to extract key points, and visualizes the result as an interactive mind map using React Flow.

##### File structure
- Top-level files: configuration (.eslintrc.json, tsconfig.json, next.config.mjs, tailwind.config.ts, postcss.config.js), package.json, README.
- app/(preview): all UI pages & layouts under Next.js App Router; includes globals.css, layout.tsx, page.tsx, actions.ts, theme CSS.
- app/api: Next.js API routes for chat and generate-quiz (server-side endpoints).
- app/types/types.ts: shared TypeScript types for data transfer.
- components/: reusable React components (MindMap, PDFExtractor, UI primitives in components/ui).
- lib/: shared utilities and schema definitions (schemas.ts, utils.ts).
- terminal: (likely local scripts or snapshots, can be omitted if unused).
- components.json: metadata for UI components (for design system?).

##### README for additional insights
- Confirms Next.js + React Flow on the front end.
- AI integration via Google Generative AI and Vercel’s AI SDK.
- Tailwind CSS for styling.
- Key features: drag & drop PDF upload, AI-powered analysis, interactive draggable/collapsible mind maps.

##### Main components and their interactions
a. Frontend (Browser)
- Next.js App Router pages in app/(preview)
- PDFExtractor component: drag & drop or file picker UI
- MindMap component: renders nodes/edges via React Flow
- Other UI primitives: buttons, inputs, badges, cards (components/ui)
b. Backend (Next.js Serverless)
- API route “/api/generate-quiz” (app/api/generate-quiz/route.ts):
- Receives PDF binary or text
- Calls Vercel AI SDK PDF support
- Sends request to Google Gemini Pro
- Receives structured key-point output
- Returns JSON to frontend
- API route “/api/chat”: optional chat interface
c. Data definitions
- app/types/types.ts: request/response schemas
- lib/schemas.ts: Zod or JSON schema validation
d. External services
- Google Generative AI API (Gemini Pro)
- Vercel AI SDK (manages file upload, rate-limiting, streaming)
e. Styling & build
- Tailwind CSS configuration (tailwind.config.ts)
- PostCSS (postcss.config.js)

##### Architectural patterns & design principles
- Separation of concerns: UI components vs API routes vs shared utils/schemas
- Serverless functions: each API endpoint is isolated
- Client-driven interactivity: heavy use of client-side React Flow for rendering
- Schema validation: ensure data contracts between front end, back end, and AI service

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser)" 
        direction TB
        UI_Pages["UI Pages & Layout<br/>(Next.js 14, TS, Tailwind)"]:::frontend
        PDFExt["PDFExtractor<br/>(React, Drag&Drop)"]:::frontend
        MindMap["MindMap<br/>(React Flow)"]:::frontend
        subgraph "UI Primitives" 
            direction TB
            Btn["button.tsx"]:::frontend
            Input["input.tsx"]:::frontend
            Card["card.tsx"]:::frontend
            Badge["badge.tsx"]:::frontend
            Label["label.tsx"]:::frontend
            Link["link.tsx"]:::frontend
            Progress["progress.tsx"]:::frontend
            Radio["radio-group.tsx"]:::frontend
            Scroll["scroll-area.tsx"]:::frontend
        end
    end

    %% Next.js Application Layer
    subgraph "Next.js Application" 
        direction TB
        subgraph "API Layer" 
            direction TB
            GenQuiz["/api/generate-quiz"]:::api
            ChatAPI["/api/chat"]:::api
        end
        subgraph "Shared Libraries" 
            direction TB
            Types["types.ts<br/>(app/types)"]:::shared
            Schemas["schemas.ts<br/>(lib)"]:::shared
            Utils["utils.ts<br/>(lib)"]:::shared
        end
    end

    %% External AI Service
    subgraph "External AI Service" 
        direction TB
        VercelAI["Vercel AI SDK"]:::external
        Gemini["Google Gemini Pro"]:::external
    end

    %% Build & Styling Tools
    subgraph "Build & Styling" 
        direction TB
        NC["next.config.mjs"]:::tools
        TW["tailwind.config.ts"]:::tools
        PC["postcss.config.js"]:::tools
    end

    %% User interaction
    User["User"]:::external -->|"interacts with"| UI_Pages
    UI_Pages -->|"upload PDF"| PDFExt
    PDFExt -->|"PDF binary"| GenQuiz
    GenQuiz -->|"PDF payload"| VercelAI
    VercelAI -->|"call API"| Gemini
    Gemini -->|"key-points JSON"| VercelAI
    VercelAI -->|"streamed JSON"| GenQuiz
    GenQuiz -->|"key-points JSON"| MindMap

    %% Shared libs usage
    UI_Pages --> Types
    MindMap --> Schemas
    MindMap --> Utils
    GenQuiz --> Schemas
    GenQuiz --> Utils

    %% Click Events for component mappings
    click UI_Pages "https://github.com/floguo/mind-map/tree/main/app/(preview)"
    click PDFExt "https://github.com/floguo/mind-map/blob/main/components/PDFExtractor.tsx"
    click MindMap "https://github.com/floguo/mind-map/blob/main/components/MindMap.tsx"
    click Btn "https://github.com/floguo/mind-map/blob/main/components/ui/button.tsx"
    click Input "https://github.com/floguo/mind-map/blob/main/components/ui/input.tsx"
    click Card "https://github.com/floguo/mind-map/blob/main/components/ui/card.tsx"
    click Badge "https://github.com/floguo/mind-map/blob/main/components/ui/badge.tsx"
    click Label "https://github.com/floguo/mind-map/blob/main/components/ui/label.tsx"
    click Link "https://github.com/floguo/mind-map/blob/main/components/ui/link.tsx"
    click Progress "https://github.com/floguo/mind-map/blob/main/components/ui/progress.tsx"
    click Radio "https://github.com/floguo/mind-map/blob/main/components/ui/radio-group.tsx"
    click Scroll "https://github.com/floguo/mind-map/blob/main/components/ui/scroll-area.tsx"
    click Types "https://github.com/floguo/mind-map/blob/main/app/types/types.ts"
    click Schemas "https://github.com/floguo/mind-map/blob/main/lib/schemas.ts"
    click Utils "https://github.com/floguo/mind-map/blob/main/lib/utils.ts"
    click GenQuiz "https://github.com/floguo/mind-map/blob/main/app/api/generate-quiz/route.ts"
    click ChatAPI "https://github.com/floguo/mind-map/blob/main/app/api/chat/route.ts"
    click NC "https://github.com/floguo/mind-map/blob/main/next.config.mjs"
    click TW "https://github.com/floguo/mind-map/blob/main/tailwind.config.ts"
    click PC "https://github.com/floguo/mind-map/blob/main/postcss.config.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#000
    classDef api fill:#C8FEE7,stroke:#028a0f,color:#000
    classDef shared fill:#F0E68C,stroke:#a27b00,color:#000
    classDef external fill:#FFEDCC,stroke:#d97706,color:#000
    classDef tools fill:#E8E8E8,stroke:#6b7280,color:#000
```
