# davidn22/ai-data-model-tool architecture

> Architecture diagram of the GitHub repository davidn22/ai-data-model-tool, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/davidn22/ai-data-model-tool
- Repository: https://github.com/davidn22/ai-data-model-tool

## Overview

##### Component Details

a. Client Layer (Frontend):
- Sub-components:
- UI Components (Chat, SchemaEditor, FlowChart)
- Data Visualization (AIDataModelVisualizer, CustomNode)
- Service Layer (handling state and business logic)

b. Server Layer (Backend):
- Include:
- API Routes container (highlighting aiRoute)
- Server configuration
- API key management

c. External Services:
- OpenAI API integration
- Connection to OpenAI's GPT model

##### Interaction Flows

- Frontend to Backend communication (REST API calls)
- Backend to OpenAI API communication
- Data flow for model generation
- State management flow

##### Technical Details

Annotations for:
- React Flow implementation
- TypeScript types
- API endpoints
- State management
- Data persistence

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Layer"]
        direction TB
        FE["Frontend (React + TypeScript + Vite)"]
        
        subgraph UI["UI Components"]
            direction TB
            Chat["Chat Component"]:::frontend
            SchemaEd["Schema Editor"]:::frontend
            Flow["Flow Chart"]:::frontend
            AIDM["AI Data Model Visualizer"]:::frontend
            CNode["Custom Node"]:::frontend
        end

        subgraph SL["Service Layer"]
            direction TB
            Services["Services Implementation"]:::frontend
            InitNodes["Initial Nodes Service"]:::frontend
        end

        App["Application Entry"]:::frontend
        Main["Main Entry Point"]:::frontend
        Config["Configuration Files"]:::config
    end

    subgraph Server["Server Layer"]
        direction TB
        BE["Backend (Node.js)"]:::backend
        
        subgraph API["API Components"]
            direction TB
            AIRoute["AI Route Handler"]:::api
            KeyMgmt["API Key Management"]:::backend
            ServerConfig["Server Configuration"]:::backend
        end
    end

    subgraph External["External Services"]
        direction TB
        OpenAI["OpenAI API"]:::external
        GPT["GPT Model"]:::external
    end

    %% Connections
    UI --> SL
    SL --> App
    App --> Main
    Main --> BE
    BE --> API
    API --> OpenAI
    OpenAI --> GPT

    %% Future Features (dotted lines)
    SQLGen["SQL Generation"]:::future
    LocalStore["Local Storage"]:::future
    BE -.-> SQLGen
    BE -.-> LocalStore

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef api fill:#e74c3c,stroke:#c0392b,color:white
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white
    classDef config fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef future fill:none,stroke:#34495e,stroke-dasharray: 5 5

    %% Click Events
    click Chat "https://github.com/DavidN22/AI-Data-Model-Tool/blob/main/frontend/src/components/Chat.tsx"
    click SchemaEd "https://github.com/DavidN22/AI-Data-Model-Tool/blob/main/frontend/src/components/SchemaEditor.tsx"
    click Flow "https://github.com/DavidN22/AI-Data-Model-Tool/blob/main/frontend/src/components/FlowChart.tsx"
    click AIDM "https://github.com/DavidN22/AI-Data-Model-Tool/blob/main/frontend/src/components/AIDataModelVisualizer.tsx"
    click CNode "https://github.com/DavidN22/AI-Data-Model-Tool/blob/main/frontend/src/components/CustomNode.tsx"
    click Services "https://github.com/DavidN22/AI-Data-Model-Tool/blob/main/frontend/src/components/Services/Services.tsx"
    click InitNodes "https://github.com/DavidN22/AI-Data-Model-Tool/blob/main/frontend/src/components/Services/InitialNodes.tsx"
    click ServerConfig "https://github.com/DavidN22/AI-Data-Model-Tool/blob/main/backend/server.js"
    click KeyMgmt "https://github.com/DavidN22/AI-Data-Model-Tool/blob/main/backend/api-key.js"
    click AIRoute "https://github.com/DavidN22/AI-Data-Model-Tool/blob/main/backend/routes/aiRoute.js"
    click App "https://github.com/DavidN22/AI-Data-Model-Tool/blob/main/frontend/src/App.tsx"
    click Main "https://github.com/DavidN22/AI-Data-Model-Tool/blob/main/frontend/src/main.tsx"
```
