# liveduo/destack architecture

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

- Interactive diagram: https://gitdiagram.com/liveduo/destack
- Repository: https://github.com/liveduo/destack

## Overview

##### Project type and purpose
- Destack is an open-source tool / component library (distributed via NPM) that integrates into React and Next.js apps to provide a visual landing-page builder.
- It bundles a React client (the editor + page renderer), a server component (an API route that persists JSON and uploads), a CLI to wrap host-project build/dev scripts, and dozens of Tailwind-based themes.

##### File structure
- Top-level “lib” directory holds the published package code:
– lib/client → React/Craft.js & GrapesJS editor components and page providers
– lib/server → Node API handler (builder endpoint), file-storage logic, CLI bin shim
– lib/themes → a plugin-style theme collection (Tailblocks, Meraki UI, Hyper UI, Preline, Flowbite, Flowrift, etc.)
– lib/scripts → post-build utilities (patch-version)
– rollup.config.js → bundling config
- “dev” folder contains example host apps: Next.js starter, React starter, custom Next.js app.
- “e2e” folder: end-to-end tests for dev/build scenarios.
- “assets/design/overview.md” contains a higher-level architecture description.
- “scripts” folder holds automation for screenshots and previews.

##### README insights
- Two main run-modes: development (shows editor, writes default.json via API) and production (static HTML generation at build time).
- Integration points:
- Next.js: import ContentProvider & getStaticProps, pages/api/builder/handle.js → server.handleEditor
- React: CLI wraps react-scripts start/build, ContentProviderReact for components.
- Persisted state: default.json in repo (dev writes), public/ in production (static).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer
    Dev(["Developer"]):::actor

    %% Host Projects
    subgraph "Host Projects"
        direction TB
        HostNext(["Next.js Starter App"]):::host
        HostCustom(["Custom Next.js App"]):::host
        HostReact(["React Starter App"]):::host
    end

    %% Destack Package
    subgraph "Destack NPM Package"
        direction TB

        subgraph "Client Library" 
            direction TB
            Client(["destack-client\n(Editor & Renderer)"]):::client
            Craft(["Craft.js Components"]):::client
            Grapes(["GrapesJS Components"]):::client
            Vanilla(["Vanilla JS Integration"]):::client
        end

        subgraph "Server Library"
            direction TB
            Server(["destack-server\n(Builder API)"]):::server
            Handle(["API Route Handler\nhandleEditor"]):::server
            ServerIndex(["Server Entry Point"]):::server
            ReactBin(["CLI Bin Shim"]):::server
            Utils(["Server Utils & Config"]):::server
        end

        CLI(["destack-CLI\n(build/dev)"]):::cli

        subgraph "Themes Module"
            direction TB
            Themes(["Themes Collection"]):::theme
            Flowbite(["Flowbite"]):::theme
            Flowrift(["Flowrift"]):::theme
            HyperUI(["HyperUI"]):::theme
            Meraki(["Meraki Light"]):::theme
            Preline(["Preline"]):::theme
            Tailblocks(["Tailblocks"]):::theme
        end
    end

    %% Storage and Services
    subgraph "Storage & Services"
        direction TB
        FS(["Filesystem / Git Repo"]):::storage
        GitService(["External Git Service"]):::external
    end

    %% Tools & Tests
    subgraph "Tools & Tests"
        direction TB
        E2E(["E2E Test Runner"]):::test
        Screenshots(["Screenshots Automation"]):::script
        Preview(["Preview Automation"]):::script
        Overview(["Architecture Overview Doc"]):::doc
    end

    %% Build & Bundling
    Rollup(["Rollup Config"]):::script
    Patch(["Post-build Utility\npatch-version"]):::script

    %% Relationships
    Dev -->|installs| HostNext
    Dev -->|installs| HostCustom
    Dev -->|installs| HostReact

    HostNext -->|imports Client & API| Client
    HostNext -->|imports API Route| Handle
    HostReact -->|wrapped by| CLI
    HostCustom -->|imports Client & API| Client

    Client -->|calls API| Server
    Server -->|writes JSON & uploads| FS
    Server -->|optional commit| GitService
    CLI -->|copies JSON / renders| HostNext
    CLI -->|builds static HTML| HostReact

    Client -->|loads themes| Themes
    Themes --> Flowbite & Flowrift & HyperUI & Meraki & Preline & Tailblocks

    E2E -->|validates flows| HostNext
    E2E -->|validates flows| HostReact
    E2E -->|validates flows| HostCustom

    Screenshots -->|generates previews| FS
    Preview -->|generates previews| FS

    Overview -->|describes architecture| Dev

    Rollup -->|bundles package| Client & Server & CLI & Themes
    Patch -->|updates versions| Client & Server & Themes

    %% Click Events
    click HostNext "https://github.com/liveduo/destack/tree/main/dev/nextjs-app-project"
    click HostCustom "https://github.com/liveduo/destack/tree/main/dev/nextjs-project"
    click HostReact "https://github.com/liveduo/destack/tree/main/dev/react-project"
    click Client "https://github.com/liveduo/destack/tree/main/lib/client"
    click Craft "https://github.com/liveduo/destack/tree/main/lib/client/craft"
    click Grapes "https://github.com/liveduo/destack/tree/main/lib/client/grapes"
    click Vanilla "https://github.com/liveduo/destack/tree/main/lib/client/vanilla"
    click Server "https://github.com/liveduo/destack/tree/main/lib/server"
    click Handle "https://github.com/liveduo/destack/blob/main/lib/server/api/handle.ts"
    click ServerIndex "https://github.com/liveduo/destack/blob/main/lib/server/index.ts"
    click ReactBin "https://github.com/liveduo/destack/blob/main/lib/server/react.bin.js"
    click Utils "https://github.com/liveduo/destack/tree/main/lib/server/utils"
    click CLI "https://github.com/liveduo/destack/blob/main/lib/server/react.ts"
    click Themes "https://github.com/liveduo/destack/tree/main/lib/themes"
    click Flowbite "https://github.com/liveduo/destack/tree/main/lib/themes/flowbite"
    click Flowrift "https://github.com/liveduo/destack/tree/main/lib/themes/flowrift"
    click HyperUI "https://github.com/liveduo/destack/tree/main/lib/themes/hyperui"
    click Meraki "https://github.com/liveduo/destack/tree/main/lib/themes/meraki-light"
    click Preline "https://github.com/liveduo/destack/tree/main/lib/themes/preline"
    click Tailblocks "https://github.com/liveduo/destack/tree/main/lib/themes/tailblocks"
    click Rollup "https://github.com/liveduo/destack/blob/main/lib/rollup.config.js"
    click Patch "https://github.com/liveduo/destack/blob/main/lib/scripts/patch-version.js"
    click E2E "https://github.com/liveduo/destack/tree/main/e2e"
    click Screenshots "https://github.com/liveduo/destack/blob/main/scripts/screenshots.js"
    click Preview "https://github.com/liveduo/destack/blob/main/scripts/preview.js"
    click Overview "https://github.com/liveduo/destack/blob/main/assets/design/overview.md"

    %% Styles
    classDef actor fill:#f9f,stroke:#333,stroke-width:1px
    classDef host fill:#eef,stroke:#333,stroke-width:1px
    classDef client fill:#cce,stroke:#0366d6,stroke-width:2px
    classDef server fill:#cfc,stroke:#22863a,stroke-width:2px
    classDef cli fill:#fdb,stroke:#d73a49,stroke-width:2px
    classDef theme fill:#fde,stroke:#6f42c1,stroke-width:2px
    classDef storage fill:#ddd,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef external fill:#eee,stroke:#999,stroke-width:1px,stroke-dasharray: 5 5
    classDef test fill:#f4f,stroke:#bd2c00,stroke-width:1px
    classDef script fill:#fcf,stroke:#d73a49,stroke-width:1px
    classDef doc fill:#efe,stroke:#22863a,stroke-width:1px
```
