# mrother/drawdb architecture

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

- Interactive diagram: https://gitdiagram.com/mrother/drawdb
- Repository: https://github.com/mrother/drawdb

## Overview

##### Main Components

A. Frontend Architecture (React-based SPA):
- Editor Core Components
- Canvas System
- Side Panel System
- Header Controls
- Modal System
- Context Management
- Internationalization (i18n)

B. Core Features:
- SQL Export/Import System
- Layout Engine
- Undo/Redo System
- State Management

##### A high-level view
- Use clear hierarchical layout

##### Break down the components as follows

**[User Interface Layer]**
- Editor Canvas System
- Table Components
- Relationship Components
- Area Components
- Note Components

- Control Systems
- Editor Header
- Side Panel
- Floating Controls

- Modal System
- Import/Export
- Settings
- Sharing

**[Core Logic Layer]**
- Context Providers
- Canvas Context
- Layout Context
- Other Contexts...

**[Feature Services Layer]**
- SQL Generation
- Multiple DB Support
- Export Formats

- Import Services
- SQL Parsing

- Utility Services
- Layout Engine
- Path Calculation
- Schema Validation

##### Important Implementation Details to Highlight
- Relationship between contexts and their consumers
- Data flow for import/export operations
- Demonstrate the interaction between the canvas and control systems
- How the i18n system integrates with components

##### Technical Stack Indicators
- React
- Vite
- Tailwind CSS
- Lexical Editor Integration
- Docker support

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        direction TB
        Canvas["Editor Canvas System"]
        Controls["Control Systems"]
        Modals["Modal System"]
        
        subgraph CanvasComponents["Canvas Components"]
            direction TB
            Table["Table Component"]
            Rel["Relationship Component"]
            Area["Area Component"]
            Note["Note Component"]
        end
        
        subgraph ControlComponents["Control Components"]
            direction TB
            Header["Editor Header"]
            SidePanel["Side Panel"]
            FloatingCtrl["Floating Controls"]
        end
        
        subgraph ModalComponents["Modal Components"]
            direction TB
            ImportExport["Import/Export Modal"]
            Share["Share Modal"]
        end
        
        Canvas --> CanvasComponents
        Controls --> ControlComponents
        Modals --> ModalComponents
    end
    
    subgraph Core["Core Logic Layer"]
        direction TB
        subgraph Contexts["Context Providers"]
            direction TB
            DiagramCtx["Diagram Context"]
            CanvasCtx["Canvas Context"]
            LayoutCtx["Layout Context"]
            UndoRedoCtx["Undo/Redo Context"]
        end
    end
    
    subgraph Services["Feature Services Layer"]
        direction TB
        subgraph SQLServices["SQL Services"]
            direction TB
            SQLExport["SQL Export System"]
            SQLImport["SQL Import System"]
        end
        
        subgraph Utils["Utility Services"]
            direction TB
            LayoutEngine["Layout Engine"]
            PathCalc["Path Calculation"]
            SchemaValid["Schema Validation"]
        end
        
        subgraph I18N["Internationalization"]
            direction TB
            I18NCore["i18n Core"]
            Locales["Locales"]
        end
    end
    
    Canvas --> DiagramCtx
    Canvas --> CanvasCtx
    Controls --> DiagramCtx
    Modals --> DiagramCtx
    LayoutEngine --> LayoutCtx
    
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:1px
    classDef ui fill:#dae8fc,stroke:#6c8ebf
    classDef core fill:#d5e8d4,stroke:#82b366
    classDef service fill:#ffe6cc,stroke:#d79b00
    
    class Canvas,Controls,Modals ui
    class DiagramCtx,CanvasCtx,LayoutCtx,UndoRedoCtx core
    class SQLExport,SQLImport,LayoutEngine,PathCalc,SchemaValid,I18NCore service
    
    click Canvas "https://github.com/mrother/drawdb/tree/main/src/components/EditorCanvas"
    click Table "https://github.com/mrother/drawdb/blob/main/src/components/EditorCanvas/Table.jsx"
    click Rel "https://github.com/mrother/drawdb/blob/main/src/components/EditorCanvas/Relationship.jsx"
    click Area "https://github.com/mrother/drawdb/blob/main/src/components/EditorCanvas/Area.jsx"
    click Note "https://github.com/mrother/drawdb/blob/main/src/components/EditorCanvas/Note.jsx"
    click Header "https://github.com/mrother/drawdb/tree/main/src/components/EditorHeader"
    click SidePanel "https://github.com/mrother/drawdb/tree/main/src/components/EditorSidePanel"
    click FloatingCtrl "https://github.com/mrother/drawdb/blob/main/src/components/FloatingControls.jsx"
    click ImportExport "https://github.com/mrother/drawdb/blob/main/src/components/EditorHeader/Modal/ImportDiagram.jsx"
    click Share "https://github.com/mrother/drawdb/blob/main/src/components/EditorHeader/Modal/Share.jsx"
    click DiagramCtx "https://github.com/mrother/drawdb/blob/main/src/context/DiagramContext.jsx"
    click CanvasCtx "https://github.com/mrother/drawdb/blob/main/src/context/CanvasContext.jsx"
    click LayoutCtx "https://github.com/mrother/drawdb/blob/main/src/context/LayoutContext.jsx"
    click UndoRedoCtx "https://github.com/mrother/drawdb/blob/main/src/context/UndoRedoContext.jsx"
    click SQLExport "https://github.com/mrother/drawdb/tree/main/src/utils/exportSQL"
    click SQLImport "https://github.com/mrother/drawdb/tree/main/src/utils/importSQL"
    click LayoutEngine "https://github.com/mrother/drawdb/blob/main/src/hooks/useLayout.js"
    click PathCalc "https://github.com/mrother/drawdb/blob/main/src/utils/calcPath.js"
    click SchemaValid "https://github.com/mrother/drawdb/blob/main/src/utils/validateSchema.js"
    click I18NCore "https://github.com/mrother/drawdb/blob/main/src/i18n/i18n.js"
    click Locales "https://github.com/mrother/drawdb/tree/main/src/i18n/locales"
```
