# bocovo/db-schema-visualizer architecture

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

- Interactive diagram: https://gitdiagram.com/bocovo/db-schema-visualizer
- Repository: https://github.com/bocovo/db-schema-visualizer

## Overview

##### Main Components Structure

a. Extension Layer:
- Two separate VS Code extensions (DBML and Prisma)
- Shared extension infrastructure
- Webview panel implementation

b. Parser Layer:
- DBML-to-JSON Schema converter
- Prisma-to-JSON Schema converter
- Shared schema types and utilities

c. Visualization Layer:
- JSON Table Schema Visualizer
- Component rendering system
- Theme management
- Layout engine

##### Component Relationships

a. Input Flow:
- DBML/Prisma file → Parser Layer → JSON Table Schema
- JSON Table Schema → Visualization Layer → ERD Display

b. Extension Communication:
- VS Code Extension → Webview Bridge → Visualization Components

##### Specific Implementation Details

- Blue rectangles: Core packages (dbml-to-json-table-schema, prisma-to-json-table-schema)
- Green rectangles: VS Code extensions
- Purple rectangles: Visualization components
- Yellow rectangles: Shared utilities and types

##### Key Technical Elements

a. Extension Components:
- Extension activation handlers
- Webview panel management
- Configuration handling

b. Parser Components:
- Schema transformation pipeline
- Validation system
- Type definitions

c. Visualizer Components:
- Table rendering system
- Layout management
- Theme switching
- Auto-arrangement functionality

##### Integration Points
Highlight:
- VS Code Extension API integration
- Inter-package communication
- Shared type systems
- Theme system integration

##### Technical Stack Indicators
Technology badges for:
- TypeScript
- React
- VS Code Extension API
- Konva (for visualization)
- Lerna (for monorepo management)

- Extension logic
- Schema parsing
- Visualization rendering
- Shared utilities

Remember to emphasize the monorepo structure and how the packages interact with each other, as this is crucial for understanding the system's architecture.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Extension Layer"
        DBML["DBML VS Code Extension"]
        Prisma["Prisma VS Code Extension"]
        SharedExt["Shared Extension Infrastructure"]
        WebView["Webview Panel Implementation"]
    end

    subgraph "Parser Layer"
        DBMLParser["DBML Parser"]
        PrismaParser["Prisma Parser"]
        SharedTypes["Shared Schema Types"]
    end

    subgraph "Visualization Layer"
        VisCore["JSON Table Schema Visualizer"]
        CompRender["Component Rendering System"]
        ThemeMgmt["Theme Management"]
        LayoutEng["Layout Engine"]
        TableRender["Table Rendering System"]
        RelVis["Relationship Visualization"]
        AutoArrange["Auto-arrangement Functionality"]
    end

    %% Extension Layer Relationships
    DBML --> SharedExt
    Prisma --> SharedExt
    SharedExt --> WebView
    WebView --> VisCore

    %% Parser Layer Relationships
    DBML --> DBMLParser
    Prisma --> PrismaParser
    DBMLParser --> SharedTypes
    PrismaParser --> SharedTypes
    SharedTypes --> VisCore

    %% Visualization Layer Relationships
    VisCore --> CompRender
    VisCore --> ThemeMgmt
    VisCore --> LayoutEng
    CompRender --> TableRender
    CompRender --> RelVis
    LayoutEng --> AutoArrange

    %% Styling
    classDef extension fill:#90EE90,stroke:#333,stroke-width:2px
    classDef parser fill:#87CEEB,stroke:#333,stroke-width:2px
    classDef visualizer fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef shared fill:#FFE4B5,stroke:#333,stroke-width:2px

    class DBML,Prisma extension
    class DBMLParser,PrismaParser parser
    class VisCore,CompRender,ThemeMgmt,LayoutEng,TableRender,RelVis,AutoArrange visualizer
    class SharedExt,WebView,SharedTypes shared

    %% Click Events
    click DBML "https://github.com/BOCOVO/db-schema-visualizer/tree/main/packages/dbml-vs-code-extension"
    click Prisma "https://github.com/BOCOVO/db-schema-visualizer/tree/main/packages/prisma-vs-code-extension"
    click SharedExt "https://github.com/BOCOVO/db-schema-visualizer/tree/main/packages/extension-shared"
    click DBMLParser "https://github.com/BOCOVO/db-schema-visualizer/tree/main/packages/dbml-to-json-table-schema"
    click PrismaParser "https://github.com/BOCOVO/db-schema-visualizer/tree/main/packages/prisma-to-json-table-schema"
    click VisCore "https://github.com/BOCOVO/db-schema-visualizer/tree/main/packages/json-table-schema-visualizer"
    click ThemeMgmt "https://github.com/BOCOVO/db-schema-visualizer/blob/main/packages/json-table-schema-visualizer/src/providers/ThemeProvider.tsx"
    click LayoutEng "https://github.com/BOCOVO/db-schema-visualizer/tree/main/packages/json-table-schema-visualizer/src/utils/tablePositioning"
    click CompRender "https://github.com/BOCOVO/db-schema-visualizer/tree/main/packages/json-table-schema-visualizer/src/components"
    click SharedTypes "https://github.com/BOCOVO/db-schema-visualizer/blob/main/packages/shared/types/tableSchema.ts"
    click WebView "https://github.com/BOCOVO/db-schema-visualizer/blob/main/packages/extension-shared/extension/views/panel.ts"
    click TableRender "https://github.com/BOCOVO/db-schema-visualizer/blob/main/packages/json-table-schema-visualizer/src/components/Table.tsx"
    click RelVis "https://github.com/BOCOVO/db-schema-visualizer/tree/main/packages/json-table-schema-visualizer/src/components/RelationConnection"
    click AutoArrange "https://github.com/BOCOVO/db-schema-visualizer/blob/main/packages/json-table-schema-visualizer/src/components/Toolbar/AutoArrage/AutoArrangeTables.tsx"
```
