# capypara20/sqldev architecture

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

- Interactive diagram: https://gitdiagram.com/capypara20/sqldev
- Repository: https://github.com/capypara20/sqldev

## Overview

##### Project Type and Purpose
- No standalone backend or microservices—everything runs in the user’s browser.

##### High-Level File Structure Analysis
- public/
- Static assets, sample SQL files for examples and tests
- src/
- constants/, types/ – Shared TS constants and types
- App.tsx & main.tsx – Entry point and root React component
- Config files (tsconfig, vite.config.ts, tailwind.config.js) – Build and styling setup

##### Core Architecture Components
a. User Interface Layer
- FileUploadButton (uses useFileUpload hook)
- ColumnEditPanel & EdgeEditPanel (fine-tune schema elements)
- ERDiagram component (wraps React Flow canvas)
b. Parsing & Schema Extraction
- sqlParser.ts: tokenizes and parses SQL to AST
- exportTableSchema.ts: transforms AST into JSON table/column/relationship model
- App state holds parsed schema model
d. Export Engine
- useDiagramExport hook + exportDiagram.ts
- html-to-image produces PNG/SVG from the React Flow DOM
e. Styling & Theming
- Tailwind CSS classes throughout components
- Dynamic style props driven by StylePanel

##### Component Interactions and Data Flow
- User clicks “Open SQL” → FileUploadButton → useFileUpload reads file
- SQL content passed to sqlParser → AST → exportTableSchema → schema JSON
- App state updated → ERDiagram re-renders via React Flow
- User interacts (drag/drop, zoom, panels adjust style props)
- On “Export” → useDiagramExport captures React Flow container → html-to-image → downloads file

##### Architectural Patterns and Principles
- Component-based UI: each panel/node/edge is a self-contained React component
- Separation of concerns: parsing logic in utils, UI in components, state via hooks
- Declarative rendering: React Flow’s nodes/edges configuration reflects schema model

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry
    subgraph "Bootstrap"
        Main["main.tsx"]:::core
        App["App.tsx"]:::core
    end
    Main -->|"renders"| App

    %% UI Layer
    subgraph "UI Layer" 
        Header["Header Component"]:::ui
        EmptyState["EmptyState Component"]:::ui
        FileUpload["FileUploadButton"]:::ui
        ColumnEdit["ColumnEditPanel"]:::ui
        EdgeEdit["EdgeEditPanel"]:::ui
        StyleP["StylePanel"]:::ui
        TableStyleP["TableStylePanel"]:::ui
    end
    App --> Header
    App --> EmptyState
    App --> FileUpload
    App --> ColumnEdit
    App --> EdgeEdit
    App --> StyleP
    App --> TableStyleP

    FileUpload -->|"useFileUpload"| UseUpload
    click FileUpload "https://github.com/capypara20/sqldev/blob/main/src/components/FileUploadButton.tsx"

    %% Input Module
    UseUpload["useFileUpload"]:::core
    click UseUpload "https://github.com/capypara20/sqldev/blob/main/src/hooks/useFileUpload.ts"

    %% Parsing & Schema Extraction
    subgraph "Parsing & Schema Extraction"
        Parser["sqlParser.ts"]:::core
        Transformer["exportTableSchema.ts"]:::core
    end
    UseUpload -->|"sqlParser.ts"| Parser
    Parser -->|"exportTableSchema.ts"| Transformer

    click Parser "https://github.com/capypara20/sqldev/blob/main/src/utils/sqlParser.ts"
    click Transformer "https://github.com/capypara20/sqldev/blob/main/src/utils/exportTableSchema.ts"

    %% Core Model
    SchemaModel["Schema JSON Model"]:::model
    Transformer -->|"schema model"| SchemaModel

    %% Render Engine
    subgraph "Render Engine"
        ERDiag["ERDiagram"]:::render
        TableNode["TableNode"]:::render
        DrEdge["DraggableEdge"]:::render
        RF["React Flow"]:::external
    end
    SchemaModel -->|"nodes/edges config"| ERDiag
    ERDiag --> RF
    ERDiag --> TableNode
    ERDiag --> DrEdge

    click ERDiag "https://github.com/capypara20/sqldev/blob/main/src/components/ERDiagram.tsx"
    click TableNode "https://github.com/capypara20/sqldev/blob/main/src/components/TableNode.tsx"
    click DrEdge "https://github.com/capypara20/sqldev/blob/main/src/components/DraggableEdge.tsx"

    %% Styling/Theming Module
    subgraph "Styling/Theming Module"
        StyleP
        TableStyleP
        Consts["diagram.ts"]:::core
        Types["index.ts"]:::core
    end
    StyleP -->|"style props"| ERDiag
    TableStyleP -->|"style props"| ERDiag

    click StyleP "https://github.com/capypara20/sqldev/blob/main/src/components/StylePanel.tsx"
    click TableStyleP "https://github.com/capypara20/sqldev/blob/main/src/components/TableStylePanel.tsx"
    click Consts "https://github.com/capypara20/sqldev/blob/main/src/constants/diagram.ts"
    click Types "https://github.com/capypara20/sqldev/blob/main/src/types/index.ts"

    %% Export Engine
    subgraph "Export Engine"
        UseExport["useDiagramExport"]:::core
        ExportUtil["exportDiagram.ts"]:::core
        HTI["html-to-image"]:::external
    end
    ERDiag -->|"DOM ref"| UseExport
    UseExport -->|"exportDiagram.ts"| ExportUtil
    ExportUtil -->|"html-to-image"| HTI
    HTI -->|"file download"| User["User Browser"]:::external

    click UseExport "https://github.com/capypara20/sqldev/blob/main/src/hooks/useDiagramExport.ts"
    click ExportUtil "https://github.com/capypara20/sqldev/blob/main/src/utils/exportDiagram.ts"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#02457A,stroke-width:1px
    classDef core fill:#E6F8E6,stroke:#2E7D32,stroke-width:1px
    classDef render fill:#FFF4E5,stroke:#F57C00,stroke-width:1px
    classDef model fill:#E8EAF6,stroke:#303F9F,stroke-width:1px
    classDef external fill:#F3E5F5,stroke:#6A1B9A,stroke-width:1px
```
