# tomayac/svgcode architecture

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

- Interactive diagram: https://gitdiagram.com/tomayac/svgcode
- Repository: https://github.com/tomayac/svgcode

## Overview

##### Main Components

a) Frontend Components:
- User Interface Layer
- Main application interface
- Window controls overlay
- Language selection interface (i18n support)
- File Handling System
- File System Access API integration
- Async Clipboard API integration
- Image Processing Pipeline
- Preprocessing module
- Monochrome conversion module
- SVG optimization module

b) Web Workers:
- Monochrome Worker
- Preprocess Worker
- SVGO Worker

c) Core Services:
- File System Service
- Image Processing Service
- Internationalization Service
- Share Service
- Installation Service

**┌─ User Interface Layer ─────────────────────────┐**

- Window Controls  │  Main UI  │  i18n UI      │

- Application Logic Layer ────────────────────┐ │

- File Handling  │  Image Processing  │ Share │ │

- Web Workers Layer ──────────────────────────┤ │

- Core Services Layer ────────────────────────┤ │

- FileSystem │ Processing │ i18n │ Install   │ │

- ┴─┘

##### Key Relationships to Highlight

- Bidirectional data flow between UI and Application Logic
- Parallel processing with Web Workers
- Demonstrate file handling pipeline from input to output
- Integration with browser APIs (File System, Clipboard)

##### Technical Details

- File format support (input: JPG, PNG, GIF, WebP, AVIF; output: SVG)
- Integration with browser APIs
- Worker thread communication paths
- Internationalization system structure

##### Implementation Notes

Remember to include annotations explaining key architectural decisions, such as:
- Why Web Workers are used for heavy processing
- How the file handling pipeline is structured
- The role of service workers in PWA functionality
- The integration of the Potrace WASM module

This will create a comprehensive visualization that accurately represents SVGcode's architecture while maintaining clarity and usefulness for development and documentation purposes.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        MainUI["Main UI"]:::ui
        WinCtrl["Window Controls"]:::ui
        I18NUI["i18n Interface"]:::ui
    end

    subgraph AppLogic["Application Logic Layer"]
        FileHandler["File Handling System"]:::logic
        ImgProc["Image Processing"]:::logic
        ShareLogic["Share Logic"]:::logic
        InstallLogic["Install Logic"]:::logic
    end

    subgraph Workers["Web Workers Layer"]
        ColorW["Color Worker"]:::worker
        MonoW["Monochrome Worker"]:::worker
        PreProcW["Preprocess Worker"]:::worker
        SVGOW["SVGO Worker"]:::worker
    end

    subgraph Core["Core Services Layer"]
        FSService["File System Service"]:::service
        ProcService["Processing Service"]:::service
        I18NService["i18n Service"]:::service
        InstallService["Install Service"]:::service
        ShareService["Share Service"]:::service
        Orchestrator["Orchestrator"]:::service
    end

    subgraph PWA["PWA Components"]
        SW["Service Worker"]:::pwa
        ShareSW["Share Target SW"]:::pwa
        Manifest["PWA Manifest"]:::pwa
    end

    %% Relationships
    MainUI --> FileHandler
    MainUI --> ImgProc
    WinCtrl --> MainUI
    I18NUI --> I18NService

    FileHandler --> FSService
    ImgProc --> ColorW
    ImgProc --> MonoW
    ImgProc --> PreProcW
    ImgProc --> SVGOW

    ShareLogic --> ShareService
    InstallLogic --> InstallService

    Orchestrator --> ImgProc
    Orchestrator --> FileHandler
    
    SW --> FSService
    ShareSW --> ShareService

    %% Styling
    classDef ui fill:#3498db
    classDef logic fill:#2ecc71
    classDef worker fill:#e67e22
    classDef service fill:#9b59b6
    classDef pwa fill:#95a5a6

    %% Click Events
    click MainUI "https://github.com/tomayac/SVGcode/blob/main/src/js/ui.js"
    click WinCtrl "https://github.com/tomayac/SVGcode/blob/main/src/js/windowcontrols.js"
    click I18NUI "https://github.com/tomayac/SVGcode/tree/main/src/i18n/"
    click FileHandler "https://github.com/tomayac/SVGcode/blob/main/src/js/filehandling.js"
    click ColorW "https://github.com/tomayac/SVGcode/blob/main/src/js/colorworker.js"
    click MonoW "https://github.com/tomayac/SVGcode/blob/main/src/js/monochromeworker.js"
    click PreProcW "https://github.com/tomayac/SVGcode/blob/main/src/js/preprocessworker.js"
    click SVGOW "https://github.com/tomayac/SVGcode/blob/main/src/js/svgoworker.js"
    click FSService "https://github.com/tomayac/SVGcode/blob/main/src/js/filesystem.js"
    click I18NService "https://github.com/tomayac/SVGcode/blob/main/src/js/i18n.js"
    click InstallService "https://github.com/tomayac/SVGcode/blob/main/src/js/install.js"
    click ShareService "https://github.com/tomayac/SVGcode/blob/main/src/js/share.js"
    click Orchestrator "https://github.com/tomayac/SVGcode/blob/main/src/js/orchestrate.js"
    click SW "https://github.com/tomayac/SVGcode/blob/main/docs/sw.js"
    click ShareSW "https://github.com/tomayac/SVGcode/blob/main/docs/sharetargetsw.js"
    click Manifest "https://github.com/tomayac/SVGcode/blob/main/src/manifest.json"
```
