# vert-sh/vert architecture

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

- Interactive diagram: https://gitdiagram.com/vert-sh/vert
- Repository: https://github.com/vert-sh/vert
- Video tour (about a minute): https://gitdiagram.com/vert-sh/vert/video

## Overview

##### Project type and purpose
- This is primarily a full-stack single-page application (SPA) built with SvelteKit and TypeScript.
- It runs entirely in the user’s browser for local (WebAssembly) conversions, but can optionally call an external “vertd” daemon (HTTP API) for non-local, heavier conversions.
- Static assets (including WASM modules) are served from a static web server (e.g., Nginx in Docker).

##### Main architectural components
a. Client Browser Layer
– SvelteKit UI (src/routes, src/lib/components)
– Web Workers (src/lib/workers/*.ts) that load & execute WASM modules (pandoc.wasm, etc.)
– Local state management (Svelte stores) and UI logic
b. Static Hosting Layer
– Vite dev server (bun dev) in development
– Built static site → Nginx (Docker container) serving HTML, JS/CSS, WASM, manifest.json
c. Optional Backend Service
– vertd daemon (external HTTP service) for video conversions
d. Third-Party Integrations
– Plausible Analytics (via PUB_PLAUSIBLE_URL)
– Optional CDN or custom domain (PUB_HOSTNAME)

##### Key relationships and data flows
1. User opens browser → requests HTML/CSS/JS from Nginx (or Vite in dev).
2. SvelteKit hydrates UI, user selects a file.
3. File is sent to either:
- Web Worker → loads appropriate WASM converter (e.g., pandoc.wasm) → returns converted data to UI
- OR forwarded via HTTP → vertd backend → streamed back to browser
4. UI displays progress via Toasts/ProgressBar components.
5. Analytics events are sent to Plausible.

##### Architectural patterns & design principles
- Component-based UI (Svelte components split between functional, layout, visual).
- Separation of concerns: UI vs. conversion logic vs. state store vs. workers.
- Use of WebWorker pattern to offload CPU-heavy WASM tasks.
- Environment-driven configuration (PUB_ENV, PUB_VERTD_URL).
- Containerized static hosting (Docker + Nginx) and local dev with Bun.

##### Technologies & frameworks
- Frontend: SvelteKit, TypeScript, Vite, Tailwind, PostCSS, Sass
- WASM converters: pandoc.wasm, other wasm modules via Web Workers
- Build & runtime: Bun (dev/install), Docker, nginx.conf
- State & logging: Svelte stores, custom logger
- CI/CD: GitHub Actions (docker.yml)
- Linting & formatting: ESLint, Prettier

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Browser Layer
    subgraph "Client Browser" 
        direction TB
        UIComponents["SvelteKit UI Components"]:::client
        PageRoutes["Page Routes"]:::client
        subgraph "Components" 
            direction TB
            Functional["UI Functional Components"]:::client
            Layout["UI Layout Components"]:::client
            Visual["UI Visual Components"]:::client
        end
        subgraph "Logic & State"
            direction TB
            ConversionLogic["Conversion Logic Modules"]:::client
            StateStores["State Management Stores"]:::client
            ConstsTypes["App Constants & Types"]:::client
        end
        subgraph "Workers & WASM"
            direction TB
            PandocWorker["Pandoc Worker"]:::client
            VipsWorker["VIPS Worker"]:::client
            WASM["WASM Modules"]:::client
        end
        HTTPModule["HTTP Converter Module"]:::client
        Analytics["Analytics Module"]:::client
    end

    %% Static Hosting Layer
    subgraph "Static Hosting (Docker + Nginx)" 
        direction TB
        DockerfileNode["Dockerfile & Configs"]:::host
        Nginx["Nginx / Static Host"]:::host
        Assets["Static Assets (HTML, JS, CSS, WASM, manifest)"]:::host
        CI["CI/CD Workflow"]:::host
        EnvConfigs["Env & Package Config"]:::host
    end

    %% External Services
    subgraph "External Services" 
        direction TB
        Vertd["vertd Conversion Daemon"]:::backend
        Plausible["Plausible Analytics"]:::external
        DevServer["Vite Dev Server (dev)"]:::host
    end

    %% Flows
    Nginx -->|"serves HTML/CSS/JS"| UIComponents
    UIComponents -->|hydrates| Functional
    Functional -->|renders| Layout
    Layout -->|renders| Visual
    Functional -->|uses stores| StateStores
    UIComponents -->|imports| ConstsTypes
    Functional -->|"selects file"| PandocWorker
    Functional -->|"selects file"| VipsWorker
    PandocWorker -->|loads| WASM
    VipsWorker -->|loads| WASM
    PandocWorker -->|returns data| Functional
    VipsWorker -->|returns data| Functional
    Functional -->|on large jobs| HTTPModule
    HTTPModule -->|POST file| Vertd
    Vertd -->|streams back| HTTPModule
    HTTPModule -->|returns data| Functional
    Functional -->|emits events| Analytics
    Analytics -->|sends| Plausible
    DevServer -->|"dev serve"| UIComponents

    CI -->|build & deploy| DockerfileNode
    DockerfileNode -->|build image| Nginx
    Assets -->|contains| WASM
    Assets -->|contains| manifest.json

    %% Click Events
    click UIComponents "https://github.com/vert-sh/vert/tree/main/src/lib/components"
    click Functional "https://github.com/vert-sh/vert/tree/main/src/lib/components/functional"
    click Layout "https://github.com/vert-sh/vert/tree/main/src/lib/components/layout"
    click Visual "https://github.com/vert-sh/vert/tree/main/src/lib/components/visual"
    click PageRoutes "https://github.com/vert-sh/vert/tree/main/src/routes"
    click PandocWorker "https://github.com/vert-sh/vert/blob/main/src/lib/workers/pandoc.ts"
    click VipsWorker "https://github.com/vert-sh/vert/blob/main/src/lib/workers/vips.ts"
    click WASM "https://github.com/vert-sh/vert/blob/main/static/pandoc.wasm"
    click ConversionLogic "https://github.com/vert-sh/vert/blob/main/src/lib/converters/index.ts"
    click ConversionLogic "https://github.com/vert-sh/vert/blob/main/src/lib/converters/converter.svelte.ts"
    click ConversionLogic "https://github.com/vert-sh/vert/blob/main/src/lib/converters/pandoc.svelte.ts"
    click ConversionLogic "https://github.com/vert-sh/vert/blob/main/src/lib/converters/vips.svelte.ts"
    click ConversionLogic "https://github.com/vert-sh/vert/blob/main/src/lib/converters/ffmpeg.svelte.ts"
    click ConversionLogic "https://github.com/vert-sh/vert/blob/main/src/lib/converters/vertd.svelte.ts"
    click StateStores "https://github.com/vert-sh/vert/blob/main/src/lib/store/DialogProvider.ts"
    click StateStores "https://github.com/vert-sh/vert/blob/main/src/lib/store/ToastProvider.ts"
    click StateStores "https://github.com/vert-sh/vert/blob/main/src/lib/store/index.svelte.ts"
    click ConstsTypes "https://github.com/vert-sh/vert/blob/main/src/lib/consts.ts"
    click ConstsTypes "https://github.com/vert-sh/vert/tree/main/src/lib/types"
    click EnvConfigs "https://github.com/vert-sh/vert/blob/main/tailwind.config.ts"
    click EnvConfigs "https://github.com/vert-sh/vert/blob/main/postcss.config.js"
    click EnvConfigs "https://github.com/vert-sh/vert/blob/main/src/lib/css/app.scss"
    click EnvConfigs "https://github.com/vert-sh/vert/blob/main/src/app.html"
    click EnvConfigs "https://github.com/vert-sh/vert/blob/main/src/app.d.ts"
    click EnvConfigs "https://github.com/vert-sh/vert/blob/main/svelte.config.js"
    click EnvConfigs "https://github.com/vert-sh/vert/blob/main/vite.config.ts"
    click EnvConfigs "https://github.com/vert-sh/vert/blob/main/tsconfig.json"
    click Assets "https://github.com/vert-sh/vert/blob/main/static/manifest.json"
    click DockerfileNode "https://github.com/vert-sh/vert/tree/main/Dockerfile"
    click DockerfileNode "https://github.com/vert-sh/vert/blob/main/nginx.conf"
    click DockerfileNode "https://github.com/vert-sh/vert/blob/main/docker-compose.yml"
    click DockerfileNode "https://github.com/vert-sh/vert/blob/main/.dockerignore"
    click CI "https://github.com/vert-sh/vert/blob/main/.github/workflows/docker.yml"
    click EnvConfigs "https://github.com/vert-sh/vert/blob/main/.env.example"
    click EnvConfigs "https://github.com/vert-sh/vert/blob/main/package.json"
    click EnvConfigs "https://github.com/vert-sh/vert/blob/main/bun.lock"

    %% Styles
    classDef client fill:#E0F2FF,stroke:#0288D1,stroke-width:1px
    classDef host fill:#E8F5E9,stroke:#2E7D32,stroke-width:1px
    classDef backend fill:#FFF3E0,stroke:#EF6C00,stroke-width:1px
    classDef external fill:#F5F5F5,stroke:#757575,stroke-width:1px
```
