# m-damien/directgpt architecture

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

- Interactive diagram: https://gitdiagram.com/m-damien/directgpt
- Repository: https://github.com/m-damien/directgpt

## Overview

##### Project type and purpose
- This is a client-side, single-page application (SPA) built with React and TypeScript.
- Its purpose is to provide a direct-manipulation UI on top of the OpenAI ChatGPT API, featuring reusable prompt tooling, manipulable outputs, and a built-in study runner with tutorial videos.

##### High-level architecture and key directories
- public/          → static assets (index.html, robots.txt, tutorial videos)
- src/
- model/         → data structures and prompt generators (Element, Model, ChatPrompt, CodePrompt, etc.)
- view/          → React UI components and interfaces (Launcher, ChatInterface, DirectInterface, StudyInterface, plus reusable widgets and entity renderers)
- package.json & tsconfig.json → build tooling and compile configuration
- .github/workflows → CI/CD pipeline (deploy.yml)

##### Main components
A. Browser/Client (React SPA)
1. Launcher
- Entry point where user enters API key and chooses mode
2. Interfaces
- ChatInterface & DirectInterface for interactive prompting
- StudyInterface for guided tasks with embedded videos
3. Shared UI Components
- PromptBuilder, PromptHistory, ReusablePromptButton, Drag’n’Drop, CustomCursor, OverlappingMarkup
4. Entity Renderers
- CodeEntity, SVGEntity, TextualEntity, UnknownEntity
B. Model Layer (in-app data & prompt generation)
- Model.tsx & Element.tsx hold the in-memory representation of outputs
- prompts/*.tsx generate structured prompt payloads for various content types
C. External Services
- OpenAI Chat API (HTTPS calls from the client)
D. Static Asset Server
- public/index.html serves the SPA shell
- public/study/tuto/*.mp4 tutorial videos loaded during study mode
E. Deployment Pipeline
- GitHub Actions (deploy.yml) builds and publishes the site (e.g., to GitHub Pages or another host)

##### Relationships and data flows
- User action in a View component → calls a Model prompt generator → sends JSON payload via fetch/XHR to OpenAI API → receives response → Model updates its Element tree → View re-renders Entities.
- Study mode fetches static videos from the asset server and sequences tasks via StudyTaskGenerator.
- Launcher stores API key in memory (never persisted) and passes it into every API request.

##### Architectural patterns and design principles
- Component-based UI (React) separating view logic (src/view) from data/prompt logic (src/model)
- MVC-style separation:
- Model layer for state & prompt assembly
- View layer for rendering & interaction
- Reusability and extensibility via a toolbar of prompt templates and entity components
- Single source of truth: central Model.tsx representing the current generative output

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend SPA
    subgraph "Frontend SPA"
        direction TB
        subgraph "Launcher & Interfaces"
            direction TB
            Launcher["Launcher"]:::react
            ChatInterface["ChatInterface"]:::react
            DirectInterface["DirectInterface"]:::react
            StudyInterface["StudyInterface"]:::react
        end
        subgraph "UI Widgets"
            direction TB
            PromptBuilder["PromptBuilder"]:::react
            PromptHistory["PromptHistory"]:::react
            PromptReuseToolbar["PromptReuseToolbar"]:::react
            ReusablePromptButton["ReusablePromptButton"]:::react
            DragnDrop["Drag'n'Drop"]:::react
            CustomCursor["CustomCursor"]:::react
            OverlappingMarkup["OverlappingMarkup"]:::react
        end
        subgraph "Entity Renderers"
            direction TB
            CodeEntity["CodeEntity"]:::react
            SVGEntity["SVGEntity"]:::react
            TextualEntity["TextualEntity"]:::react
            UnknownEntity["UnknownEntity"]:::react
        end
        subgraph "Model Layer"
            direction TB
            Element["Element"]:::model
            Model["Model"]:::model
            subgraph "Prompts"
                direction TB
                ChatPrompt["ChatPrompt"]:::model
                CodePrompt["CodePrompt"]:::model
                ComplexPrompt["ComplexPrompt"]:::model
                SVGPrompt["SVGPrompt"]:::model
                TextPrompt["TextPrompt"]:::model
                UnknownPrompt["UnknownPrompt"]:::model
            end
        end
        subgraph "Study Mode Components"
            direction TB
            StudyTaskGenerator["StudyTaskGenerator"]:::react
            StudyModel["StudyModel"]:::react
            StudyMessage["StudyMessage"]:::react
            StudyVideo["StudyVideo"]:::react
            TaskPanel["TaskPanel"]:::react
        end
    end

    %% External Services and Assets
    OpenAIAPI["OpenAI API"]:::external
    subgraph "Static Asset Server"
        direction TB
        index[(index.html)]:::assets
        videos[(Tutorial Videos)]:::assets
    end
    subgraph "CI/CD Pipeline"
        direction TB
        GHAction["deploy.yml"]:::ci
    end

    %% Data Flows
    User(("User"))-->Launcher
    Launcher-->ChatInterface
    Launcher-->DirectInterface
    Launcher-->StudyInterface
    ChatInterface-->ChatPrompt
    DirectInterface-->ComplexPrompt
    StudyInterface-->StudyTaskGenerator
    ChatPrompt-->|"POST /chat/completions"|OpenAIAPI
    CodePrompt-->|"POST /chat/completions"|OpenAIAPI
    ComplexPrompt-->|"POST /chat/completions"|OpenAIAPI
    SVGPrompt-->|"POST /chat/completions"|OpenAIAPI
    TextPrompt-->|"POST /chat/completions"|OpenAIAPI
    UnknownPrompt-->|"POST /chat/completions"|OpenAIAPI
    OpenAIAPI-->|"200 OK + content"|Model
    Model-->Element
    Element-->CodeEntity
    Element-->SVGEntity
    Element-->TextualEntity
    Element-->UnknownEntity
    StudyInterface-->StudyVideo
    StudyVideo-->|"fetch mp4"|videos
    GHAction---index

    %% Click Events
    click Launcher "https://github.com/m-damien/directgpt/blob/main/src/view/Launcher.tsx"
    click ChatInterface "https://github.com/m-damien/directgpt/blob/main/src/view/ChatInterface.tsx"
    click DirectInterface "https://github.com/m-damien/directgpt/blob/main/src/view/DirectInterface.tsx"
    click StudyInterface "https://github.com/m-damien/directgpt/blob/main/src/view/study/StudyInterface.tsx"
    click PromptBuilder "https://github.com/m-damien/directgpt/blob/main/src/view/components/PromptBuilder.tsx"
    click PromptHistory "https://github.com/m-damien/directgpt/blob/main/src/view/components/PromptHistory.tsx"
    click PromptReuseToolbar "https://github.com/m-damien/directgpt/blob/main/src/view/components/PromptReuseToolbar.tsx"
    click ReusablePromptButton "https://github.com/m-damien/directgpt/blob/main/src/view/components/ReusablePromptButton.tsx"
    click DragnDrop "https://github.com/m-damien/directgpt/blob/main/src/view/components/DragnDrop.tsx"
    click CustomCursor "https://github.com/m-damien/directgpt/blob/main/src/view/components/CustomCursor.tsx"
    click OverlappingMarkup "https://github.com/m-damien/directgpt/blob/main/src/view/components/OverlappingMarkup.jsx"
    click CodeEntity "https://github.com/m-damien/directgpt/blob/main/src/view/entities/CodeEntity.tsx"
    click SVGEntity "https://github.com/m-damien/directgpt/blob/main/src/view/entities/SVGEntity.tsx"
    click TextualEntity "https://github.com/m-damien/directgpt/blob/main/src/view/entities/TextualEntity.tsx"
    click UnknownEntity "https://github.com/m-damien/directgpt/blob/main/src/view/entities/UnknownEntity.tsx"
    click Element "https://github.com/m-damien/directgpt/blob/main/src/model/Element.tsx"
    click Model "https://github.com/m-damien/directgpt/blob/main/src/model/Model.tsx"
    click ChatPrompt "https://github.com/m-damien/directgpt/blob/main/src/model/prompts/ChatPrompt.tsx"
    click CodePrompt "https://github.com/m-damien/directgpt/blob/main/src/model/prompts/CodePrompt.tsx"
    click ComplexPrompt "https://github.com/m-damien/directgpt/blob/main/src/model/prompts/ComplexPrompt.tsx"
    click SVGPrompt "https://github.com/m-damien/directgpt/blob/main/src/model/prompts/SVGPrompt.tsx"
    click TextPrompt "https://github.com/m-damien/directgpt/blob/main/src/model/prompts/TextPrompt.tsx"
    click UnknownPrompt "https://github.com/m-damien/directgpt/blob/main/src/model/prompts/UnknownPrompt.tsx"
    click StudyTaskGenerator "https://github.com/m-damien/directgpt/blob/main/src/view/study/StudyTaskGenerator.tsx"
    click StudyModel "https://github.com/m-damien/directgpt/blob/main/src/view/study/StudyModel.tsx"
    click StudyMessage "https://github.com/m-damien/directgpt/blob/main/src/view/study/StudyMessage.tsx"
    click StudyVideo "https://github.com/m-damien/directgpt/blob/main/src/view/study/StudyVideo.tsx"
    click TaskPanel "https://github.com/m-damien/directgpt/blob/main/src/view/study/TaskPanel.tsx"
    click index "https://github.com/m-damien/directgpt/blob/main/public/index.html"

    %% Styles
    classDef react fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef model fill:#DFFFD0,stroke:#333,stroke-width:1px
    classDef assets fill:#FFE0B2,stroke:#333,stroke-width:1px
    classDef external fill:#EEEEEE,stroke:#333,stroke-width:1px,stroke-dasharray: 2 2
    classDef ci fill:#E1D5E7,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
```
