# leomcelroy/svg-pcb architecture

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

- Interactive diagram: https://gitdiagram.com/leomcelroy/svg-pcb
- Repository: https://github.com/leomcelroy/svg-pcb

## Overview

##### Main System Components

The system architecture should be divided into these key components:

a) Frontend Interface Layer
- Browser-based editor
- CodeMirror integration for code editing
- SVG rendering system
- Interactive manipulation tools

b) Core Processing Layer
- JavaScript Hardware Description Language (HDL) parser
- PCB design engine
- Component management system
- Wire routing system

c) Export/Import Layer
- File format converters (Gerber, SVG, JavaScript)
- Component library management
- File I/O handlers

##### Key Relationships to Highlight

- Bidirectional flow between code editor and visual interface
- Data flow from component libraries to the design engine
- Export pathways to different file formats
- Event handling between user interactions and design updates

##### Specific Implementation Details

- Blue: Core PCB design functionality (/js/pcb.js, /js/pcb_helpers.js)
- Green: User interface components (/js/components/*)
- Yellow: File handling and export systems (/js/events/download*.js)
- Red: Component library system (/components/*)

##### Architecture Pattern

- Event-driven architecture for real-time updates
- Component-based structure for modularity
- Pipeline processing for design generation
- Plugin system for component libraries

##### Detailed Component Breakdown

a) Editor Components:
- Code editor (CodeMirror)
- Visual editor
- Component picker
- Layer manager

b) Processing Pipeline:
- AST analysis
- Component placement
- Wire routing
- Design validation

c) Export Pipeline:
- Gerber generation
- KiCad export
- SVG rendering
- JavaScript serialization

##### Integration Points

Interfaces between:
- Code and visual editors
- Component library and design engine
- Export modules and core system
- Event system and UI updates

##### Technical Stack Elements

Technology indicators for:
- Browser runtime environment
- JavaScript/HTML5 platform
- SVG rendering engine
- File processing systems

Remember to maintain an appropriate level of abstraction - focus on the major system components and their interactions rather than implementation details, while still providing enough technical depth to understand the system's architecture.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend["Frontend Interface Layer"]
        Browser["Browser Editor Interface"]
        CodeMirror["CodeMirror Integration"]
        SVGRender["View Rendering System"]
        Tools["Interactive Tools"]
        WireEdit["Wire Editing System"]
        FPEdit["Footprint Editor"]
    end

    subgraph Core["Core Processing Layer"]
        HDL["Hardware Description Parser"]
        PCBEngine["PCB Design Engine"]
        PCBHelpers["PCB Helper Functions"]
        State["Core State Management"]
    end

    subgraph Export["Export/Import Layer"]
        Formats["Format Converters"]
        CompLib["Component Library"]
        FileIO["File I/O Handlers"]
        
        subgraph Exporters["Export Systems"]
            Gerber["Gerber Export"]
            KiCad["KiCad Export"]
        end
    end

    %% Relationships
    Browser --> CodeMirror
    Browser --> SVGRender
    WireEdit --> PCBEngine
    FPEdit --> PCBEngine
    Tools --> PCBEngine
    HDL --> PCBEngine
    PCBEngine --> PCBHelpers
    PCBEngine --> State
    CompLib --> PCBEngine
    PCBEngine --> Formats
    Formats --> Gerber
    Formats --> KiCad
    FileIO --> State

    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef frontend fill:#e1f5fe,stroke:#0288d1
    classDef core fill:#e8f5e9,stroke:#388e3c
    classDef export fill:#fff3e0,stroke:#f57c00
    
    class Frontend frontend
    class Core core
    class Export export

    %% Click events
    click Browser "https://github.com/leomcelroy/svg-pcb/blob/main/js/components/cm-editor.js"
    click WireEdit "https://github.com/leomcelroy/svg-pcb/blob/main/js/components/wire-editor.js"
    click FPEdit "https://github.com/leomcelroy/svg-pcb/blob/main/js/components/footprint-editor/footprint-editor.js"
    click PCBEngine "https://github.com/leomcelroy/svg-pcb/blob/main/js/pcb.js"
    click PCBHelpers "https://github.com/leomcelroy/svg-pcb/blob/main/js/pcb_helpers.js"
    click HDL "https://github.com/leomcelroy/svg-pcb/blob/main/js/astAnalysis.js"
    click CompLib "https://github.com/leomcelroy/svg-pcb/tree/main/components/"
    click Gerber "https://github.com/leomcelroy/svg-pcb/blob/main/js/events/downloadGerber.js"
    click KiCad "https://github.com/leomcelroy/svg-pcb/blob/main/js/events/downloadKiCad.js"
    click Tools "https://github.com/leomcelroy/svg-pcb/blob/main/js/events/addPathManipulation.js"
    click FileIO "https://github.com/leomcelroy/svg-pcb/blob/main/js/events/addDropUpload.js"
    click State "https://github.com/leomcelroy/svg-pcb/blob/main/js/global_state.js"
    click SVGRender "https://github.com/leomcelroy/svg-pcb/tree/main/js/views/"

    %% Legend
    subgraph Legend
        Frontend_L["Frontend Components"]:::frontend
        Core_L["Core Components"]:::core
        Export_L["Export Components"]:::export
    end
```
