# gwendalbroudin/dbml-flow architecture

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

- Interactive diagram: https://gitdiagram.com/gwendalbroudin/dbml-flow
- Repository: https://github.com/gwendalbroudin/dbml-flow

## Overview

##### Project type and purpose
- This is a client-only, single-page web application (an open-source DBML viewer/editor tool) built with React, TypeScript and Vite.

##### File structure
- Top level:
- index.html, package.json, Vite config → SPA bootstrapping & build
- src/main.tsx → React entry point
- src/routes → route definitions for edit vs view modes
- src/state/store.ts → centralized state (likely Zustand/Redux)
- src/lib → core logic libraries:
– dbml/parser.ts → parse DBML → AST
– layout (dagre.utils.ts, useElk.ts) → compute node/edge positions
– editor.helper.ts, math.helper.ts, utils.ts, url.helpers.ts
– monaco (init DBML support in Monaco Editor)
- src/components → UI layers:
– editor (Monaco editor + controls)
– viewer (canvas/SVG renderer for nodes & edges)
– controls (minimap, rearrange button)
– base-node, base-handle, labeled-handle, hidden-handle → building blocks for graph nodes
– database-schema-node, table-node → specialized node components
– nav (generate-image button)
– ui/table.tsx → helper UI
- config files: tsconfig, .github/workflows, .codesandbox, .gitignore.

##### README for additional insights
- Mentions inspirations and reference implementations.

##### Diagramming recommendations
- Use clear labels: e.g., “Parser Module (dbml/parser.ts)”, “ELK Layout Engine (useElk)”
- Blue for UI components
- Green for core libraries (parser, layout)
- Yellow for external dependencies (Monaco, Dagre, ELK)

## Diagram (Mermaid)

```mermaid
flowchart TB
  Browser["Web Browser"]:::external
  SPA["React SPA"]:::frontend

  Browser -->|"loads via Vite"| SPA

  subgraph "Browser/Client"
    Browser
  end

  subgraph "React SPA"
    direction TB
    Main["Entry Point (src/main.tsx)"]:::frontend
    App["App Root (src/App.tsx)"]:::frontend
    Main --> App
    App --> Store
    App --> ExportBtn

    subgraph "Routing Layer"
      direction TB
      EditRoute["Edit Route (src/routes/edit-route.tsx)"]:::frontend
      ViewRoute["View Route (src/routes/view-route.tsx)"]:::frontend
      App --> EditRoute
      App --> ViewRoute
    end

    Store["State Store (src/state/store.ts)"]:::core

    subgraph "Editor Module"
      direction TB
      EditorUI["Editor UI (src/components/editor/editor.tsx)"]:::frontend
      EditorConst["Editor Constants (src/components/editor/editor.constant.ts)"]:::core
      InitDBML["Monaco Init Feature (src/lib/monaco/init-dbml-feature.ts)"]:::core
      Monarch["Monarch Config (src/lib/monaco/monarch-config.ts)"]:::core
      EditorHelper["Editor Helper (src/lib/editor/editor.helper.ts)"]:::core
      EditRoute --> EditorUI
      EditorUI -->|"uses"| EditorHelper
      EditorUI --> EditorConst
      EditorUI --> InitDBML
      InitDBML --> Monarch
      Store --> EditorUI
    end

    subgraph "Parser Module"
      Parser["Parser (src/lib/dbml/parser.ts)"]:::core
      Store -->|"DBML text"| Parser
      Parser -->|"AST"| Store
    end

    subgraph "Layout Engine"
      direction TB
      Dagre["Dagre Utils (src/lib/layout/dagre.utils.ts)"]:::core
      ELK["ELK Hook (src/lib/layout/useElk.ts)"]:::core
      LayoutHelpers["Layout Helpers (src/lib/layout/layout.helpers.ts)"]:::core
      Store -->|"AST"| Dagre
      Store -->|"AST"| ELK
      Dagre -->|"NodePositions"| Store
      ELK -->|"NodePositions"| Store
      LayoutHelpers --> Dagre
      LayoutHelpers --> ELK
    end

    subgraph "Viewer Module"
      direction TB
      ViewerUI["Viewer UI (src/components/viewer/viewer.tsx)"]:::frontend
      ViewerHelper["Viewer Helper (src/components/viewer/viewer.helper.ts)"]:::core
      ViewRoute --> ViewerUI
      Store --> ViewerUI
      ViewerUI --> ViewerHelper
    end

    subgraph "UI Components"
      BaseNode["Base Node (src/components/base-node.tsx)"]:::frontend
      BaseHandle["Base Handle (src/components/base-handle.tsx)"]:::frontend
      LabeledHandle["Labeled Handle (src/components/labeled-handle.tsx)"]:::frontend
      HiddenHandle["Hidden Handle (src/components/hidden-handle.tsx)"]:::frontend
      DBSchemaNode["Database Schema Node (src/components/database-schema-node.tsx)"]:::frontend
      TableNode["Table Node (src/components/table-node.tsx)"]:::frontend
    end

    subgraph "Controls & Utilities"
      Minimap["Minimap Button (src/components/controls/minimap-button.tsx)"]:::frontend
      Rearrange["Rearrange Button (src/components/controls/rearrange-button.tsx)"]:::frontend
      ExportBtn["Generate Image (src/components/nav/generate-image.tsx)"]:::frontend
      URLHelpers["URL Helpers (src/lib/url.helpers.ts)"]:::core
      Utils["Utils (src/lib/utils.ts)"]:::core
      MathHelper["Math Helper (src/lib/math/math.helper.ts)"]:::core
      UITable["UI Table (src/components/ui/table.tsx)"]:::frontend
      EditRoute --> Minimap
      EditRoute --> Rearrange
      ExportBtn -->|"reads SVG"| Store
    end

  end

  click Main "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/main.tsx"
  click App "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/App.tsx"
  click EditRoute "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/routes/edit-route.tsx"
  click ViewRoute "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/routes/view-route.tsx"
  click Store "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/state/store.ts"
  click Parser "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/lib/dbml/parser.ts"
  click Dagre "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/lib/layout/dagre.utils.ts"
  click ELK "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/lib/layout/useElk.ts"
  click LayoutHelpers "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/lib/layout/layout.helpers.ts"
  click EditorUI "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/components/editor/editor.tsx"
  click EditorConst "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/components/editor/editor.constant.ts"
  click InitDBML "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/lib/monaco/init-dbml-feature.ts"
  click Monarch "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/lib/monaco/monarch-config.ts"
  click EditorHelper "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/lib/editor/editor.helper.ts"
  click ViewerUI "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/components/viewer/viewer.tsx"
  click ViewerHelper "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/components/viewer/viewer.helper.ts"
  click BaseNode "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/components/base-node.tsx"
  click BaseHandle "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/components/base-handle.tsx"
  click LabeledHandle "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/components/labeled-handle.tsx"
  click HiddenHandle "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/components/hidden-handle.tsx"
  click DBSchemaNode "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/components/database-schema-node.tsx"
  click TableNode "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/components/table-node.tsx"
  click Minimap "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/components/controls/minimap-button.tsx"
  click Rearrange "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/components/controls/rearrange-button.tsx"
  click ExportBtn "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/components/nav/generate-image.tsx"
  click URLHelpers "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/lib/url.helpers.ts"
  click Utils "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/lib/utils.ts"
  click MathHelper "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/lib/math/math.helper.ts"
  click UITable "https://github.com/gwendalbroudin/dbml-flow/blob/main/src/components/ui/table.tsx"

  classDef frontend fill:#cce5ff,stroke:#004085
  classDef core fill:#d4edda,stroke:#155724
  classDef external fill:#fff3cd,stroke:#856404
```
