# nilooy/flowgpt architecture

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

- Interactive diagram: https://gitdiagram.com/nilooy/flowgpt
- Repository: https://github.com/nilooy/flowgpt

## Overview

##### Project type and purpose
- This is a full-stack Next.js web application (“FlowGPT”) that lets users generate AI-driven flowcharts in the browser.
- Key features:
- React/Next.js front-end with Tailwind CSS and DaisyUI
- Serverless API routes (Next.js)

##### Main components
a. Browser / User Interface
– Pages (src/pages/index.tsx)
– React components (src/components/nav.tsx, select-template.tsx)
– Tailwind/DaisyUI styling layer
b. Next.js Server / API Layer
– API route (src/pages/api/ask.ts) serving POST requests
– _app.tsx / _document.tsx for SSR/boilerplate
c. Business Logic / Back-end Modules
– Prompt builder (src/lib/prompt-by-template.ts)
– Generation engine (src/lib/generate.ts)
– Helpers (src/lib/helpers.ts)
– Syntax templates (src/lib/syntax/*.md)
d. External Service
– OpenAI REST API (via Langchain)

##### Relationships and data flow
1. User selects a template & clicks “Generate” in the browser.
2. Browser issues a fetch POST to /api/ask.
3. API handler loads the correct .md syntax template.
4. Prompt-builder composes the user query + template.
5. Generation engine calls OpenAI (via Langchain).
7. API responds with JSON containing the DSL.

##### Architectural patterns & design principles
- Separation of concerns: UI, API routes, business logic, syntax data all in separate folders.
- Modular design: each lib function has a single responsibility (prompt building, AI call, helper utilities).
- Serverless functions (thin API layer).
- Static assets (public/brand, favicon).

##### Technologies & frameworks to annotate
- Next.js (pages folder, API routes, SSR/SSG)
- React + TypeScript (tsx files)
- Tailwind CSS + DaisyUI (tailwind.config.js, globals.css)
- Langchain & OpenAI API
- Vercel (deployment target, implied by Next.js)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Browser / UI"
        Pages["index.tsx"]:::frontend
        Nav["nav.tsx"]:::frontend
        Selector["select-template.tsx"]:::frontend
        MermaidComp["mermaid.tsx"]:::frontend
        Styles["globals.css"]:::frontend
        TailwindConfig["tailwind.config.js"]:::frontend
    end

    subgraph "Next.js API Layer"
        App["_app.tsx"]:::api
        Document["_document.tsx"]:::api
        Ask["ask.ts — API handler"]:::api
    end

    subgraph "Business Logic / Modules"
        Generate["generate.ts — Generation Engine"]:::logic
        Prompt["prompt-by-template.ts — Prompt Builder"]:::logic
        Helpers["helpers.ts — Helper Utilities"]:::logic
        subgraph "Syntax Templates"
            classT["class.md"]:::logic
            entityER["entityrelationship.md"]:::logic
            flowT["flowchart.md"]:::logic
            mindmap["mindmap.md"]:::logic
            sequence["sequence.md"]:::logic
            state["state.md"]:::logic
            timeline["timeline.md"]:::logic
            userjourney["userjourney.md"]:::logic
        end
    end

    OpenAI["OpenAI API (via Langchain)"]:::external

    %% Data flow
    Selector -->|"select template"| Pages
    Pages -->|"POST /api/ask"| Ask
    Ask -->|"load template md"| Prompt
    Prompt -->|"build prompt"| Generate
    Generate -->|"call OpenAI"| OpenAI
    OpenAI -->|"Mermaid DSL text"| Generate
    Generate -->|"return DSL"| Ask
    Ask -->|"200 JSON DSL"| Pages
    Pages -->|"renderMermaid()"| MermaidComp

    %% Click Events
    click Pages "https://github.com/nilooy/flowgpt/blob/main/src/pages/index.tsx"
    click Nav "https://github.com/nilooy/flowgpt/blob/main/src/components/nav.tsx"
    click Selector "https://github.com/nilooy/flowgpt/blob/main/src/components/select-template.tsx"
    click MermaidComp "https://github.com/nilooy/flowgpt/blob/main/src/components/mermaid.tsx"
    click Styles "https://github.com/nilooy/flowgpt/blob/main/src/styles/globals.css"
    click TailwindConfig "https://github.com/nilooy/flowgpt/blob/main/tailwind.config.js"
    click App "https://github.com/nilooy/flowgpt/blob/main/src/pages/_app.tsx"
    click Document "https://github.com/nilooy/flowgpt/blob/main/src/pages/_document.tsx"
    click Ask "https://github.com/nilooy/flowgpt/blob/main/src/pages/api/ask.ts"
    click Generate "https://github.com/nilooy/flowgpt/blob/main/src/lib/generate.ts"
    click Prompt "https://github.com/nilooy/flowgpt/blob/main/src/lib/prompt-by-template.ts"
    click Helpers "https://github.com/nilooy/flowgpt/blob/main/src/lib/helpers.ts"
    click classT "https://github.com/nilooy/flowgpt/blob/main/src/lib/syntax/class.md"
    click entityER "https://github.com/nilooy/flowgpt/blob/main/src/lib/syntax/entityrelationship.md"
    click flowT "https://github.com/nilooy/flowgpt/blob/main/src/lib/syntax/flowchart.md"
    click mindmap "https://github.com/nilooy/flowgpt/blob/main/src/lib/syntax/mindmap.md"
    click sequence "https://github.com/nilooy/flowgpt/blob/main/src/lib/syntax/sequence.md"
    click state "https://github.com/nilooy/flowgpt/blob/main/src/lib/syntax/state.md"
    click timeline "https://github.com/nilooy/flowgpt/blob/main/src/lib/syntax/timeline.md"
    click userjourney "https://github.com/nilooy/flowgpt/blob/main/src/lib/syntax/userjourney.md"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#0288D1,color:#000
    classDef api fill:#E8F5E9,stroke:#43A047,color:#000
    classDef logic fill:#FFFDE7,stroke:#FBC02D,color:#000
    classDef external fill:#ECEFF1,stroke:#B0BEC5,color:#000
```
