# bhaskatripathi/text2diagram architecture

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

- Interactive diagram: https://gitdiagram.com/bhaskatripathi/text2diagram
- Repository: https://github.com/bhaskatripathi/text2diagram

## Overview

##### Project type and purpose
- This is a full-stack web application built with Next.js (app directory) and TypeScript.

##### File structure
- Top-level folders:
- app/ – Next.js 13 “App Router” pages, layout, CSS, and an API route at app/api/openai/route.ts
- pages/ – legacy Next.js pages and an API endpoint at pages/api/chat.ts (likely for backward compatibility)
- components/ui/ – low-level UI primitives (button, input, label, popover, etc.)
- lib/ – state management (atom.ts) and utility functions (utils.ts)
- config/ and types/ – site configuration and TypeScript type definitions
- public/ – static assets; README, video demo, prompts file at root
- tailwind.config.js, postcss.config.js – style tooling
- next.config.js, tsconfig.json – Next.js and TypeScript config
- The core architectural choice is a single monolithic Next.js serverless application with clear separation between frontend (React) and backend (serverless API routes).

##### README for additional insights
- No database or long-term storage; state is ephemeral, kept in React/Jotai atoms.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client (Browser)"
        AppLayout["App Layout"]:::client
        Page["Client Browser UI"]:::client
        GlobalCSS["Global Stylesheet"]:::client
        SiteHeader["Site Header"]:::client
        MainNav["Main Navigation"]:::client
        subgraph "UI Primitives"
            Button["Button"]:::client
            Input["Input"]:::client
            Label["Label"]:::client
            Popover["Popover"]:::client
            Select["Select"]:::client
            Textarea["Textarea"]:::client
            HoverCard["HoverCard"]:::client
        end
        PromptInput["Prompt Input"]:::client
        APIKeyInput["API Key Input"]:::client
        ChatMessage["Chat Message Display"]:::client
        CodeBlock["Code Block"]:::client
        Mermaids["Diagram Renderer"]:::client
    end

    subgraph "Server (Next.js API)"
        OpenAIRoute["OpenAI API Route"]:::server
        LegacyChat["Legacy Chat Endpoint"]:::server
    end

    subgraph "Lib / Data"
        Atom["State Management (Jotai Atoms)"]:::util
        Utils["Utility Functions"]:::util
    end

    subgraph "Config & Types"
        SiteConfig["Site Configuration"]:::config
        NavTypes["Navigation Types"]:::type
        OtherTypes["Type Definitions"]:::type
    end

    subgraph "Dev Config"
        Tailwind["tailwind.config.js"]:::config
        PostCSS["postcss.config.js"]:::config
        NextConfig["next.config.js"]:::config
        TSConfig["tsconfig.json"]:::config
    end

    subgraph "Public Assets"
        PublicDir["public/"]:::config
        Readme["README.md"]:::config
        PromptsFile["Prompts.md"]:::config
        Video["Text2Diagram.mp4"]:::config
    end

    External["OpenAI Service"]:::external

    AppLayout --> SiteHeader
    AppLayout --> MainNav
    AppLayout --> Page
    SiteHeader --> MainNav

    Page --> PromptInput
    Page --> APIKeyInput
    PromptInput -->|"POST prompt"| OpenAIRoute
    APIKeyInput --> OpenAIRoute

    OpenAIRoute -->|"forward request"| External
    External -->|"return script"| OpenAIRoute

    OpenAIRoute -->|"return script"| CodeBlock
    OpenAIRoute --> Mermaids

    CodeBlock -->|"display script"| Page
    Mermaids -->|"render diagram"| Page

    Atom --> Page
    Utils --> OpenAIRoute
    SiteConfig --> Page
    NavTypes --> MainNav
    OtherTypes --> ChatMessage

    classDef client fill:#cfe2ff,stroke:#000
    classDef server fill:#d1e7dd,stroke:#000
    classDef external fill:#ffe599,stroke:#000
    classDef util fill:#f4cccc,stroke:#000
    classDef config fill:#d9d2e9,stroke:#000
    classDef type fill:#9fc5e8,stroke:#000

    click Page "https://github.com/bhaskatripathi/text2diagram/blob/main/app/page.tsx"
    click AppLayout "https://github.com/bhaskatripathi/text2diagram/blob/main/app/layout.tsx"
    click GlobalCSS "https://github.com/bhaskatripathi/text2diagram/blob/main/app/globals.css"
    click OpenAIRoute "https://github.com/bhaskatripathi/text2diagram/blob/main/app/api/openai/route.ts"
    click LegacyChat "https://github.com/bhaskatripathi/text2diagram/blob/main/pages/api/chat.ts"
    click PromptInput "https://github.com/bhaskatripathi/text2diagram/blob/main/components/ChatInput.tsx"
    click APIKeyInput "https://github.com/bhaskatripathi/text2diagram/blob/main/components/APIKeyInput.tsx"
    click Mermaids "https://github.com/bhaskatripathi/text2diagram/blob/main/components/Mermaids.tsx"
    click ChatMessage "https://github.com/bhaskatripathi/text2diagram/blob/main/components/ChatMessage.tsx"
    click CodeBlock "https://github.com/bhaskatripathi/text2diagram/blob/main/components/CodeBlock.tsx"
    click SiteHeader "https://github.com/bhaskatripathi/text2diagram/blob/main/components/SiteHeader.tsx"
    click MainNav "https://github.com/bhaskatripathi/text2diagram/blob/main/components/MainNav.tsx"
    click Button "https://github.com/bhaskatripathi/text2diagram/blob/main/components/ui/button.tsx"
    click Input "https://github.com/bhaskatripathi/text2diagram/blob/main/components/ui/input.tsx"
    click Label "https://github.com/bhaskatripathi/text2diagram/blob/main/components/ui/label.tsx"
    click Popover "https://github.com/bhaskatripathi/text2diagram/blob/main/components/ui/popover.tsx"
    click Select "https://github.com/bhaskatripathi/text2diagram/blob/main/components/ui/select.tsx"
    click Textarea "https://github.com/bhaskatripathi/text2diagram/blob/main/components/ui/textarea.tsx"
    click HoverCard "https://github.com/bhaskatripathi/text2diagram/blob/main/components/ui/hover-card.tsx"
    click Atom "https://github.com/bhaskatripathi/text2diagram/blob/main/lib/atom.ts"
    click Utils "https://github.com/bhaskatripathi/text2diagram/blob/main/lib/utils.ts"
    click SiteConfig "https://github.com/bhaskatripathi/text2diagram/blob/main/config/site.ts"
    click NavTypes "https://github.com/bhaskatripathi/text2diagram/blob/main/types/nav.ts"
    click OtherTypes "https://github.com/bhaskatripathi/text2diagram/blob/main/types/type.ts"
    click Tailwind "https://github.com/bhaskatripathi/text2diagram/blob/main/tailwind.config.js"
    click PostCSS "https://github.com/bhaskatripathi/text2diagram/blob/main/postcss.config.js"
    click NextConfig "https://github.com/bhaskatripathi/text2diagram/blob/main/next.config.js"
    click TSConfig "https://github.com/bhaskatripathi/text2diagram/blob/main/tsconfig.json"
    click PublicDir "https://github.com/bhaskatripathi/text2diagram/tree/main/public/"
    click Readme "https://github.com/bhaskatripathi/text2diagram/blob/main/README.md"
    click PromptsFile "https://github.com/bhaskatripathi/text2diagram/blob/main/Prompts.md"
    click Video "https://github.com/bhaskatripathi/text2diagram/blob/main/Text2Diagram.mp4"
```
