# olwooz/schnode architecture

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

- Interactive diagram: https://gitdiagram.com/olwooz/schnode
- Repository: https://github.com/olwooz/schnode

## Overview

##### Project Type and Purpose
- Schnode is a full-stack web application (front-end heavy) built with Next.js and TypeScript.
- Its purpose is to let end users visually construct UIs by dragging and dropping prebuilt components, configure them, preview the result, and export/import designs as JSON.

##### Main Components
a. Next.js Application
- Next.js server & router (SSR/SSG/endpoints)
- App directory (src/app/*) with layout.tsx, page.tsx
b. React Client Providers
- DeviceProvider & ClientDeviceProvider (device detection)
- DndProvider (react-dnd context)
- ThemeProvider (light/dark mode via Tailwind & shadcn/ui)
c. Component Library & Renderer
- UI Primitives (components/ui/*) – alert, button, table, etc.
- Motion Primitives (components/motion-primitives/*) – animations
- Renderer (components/renderer/*) – renders dropped components on canvas
d. Layout & Canvas
- AppDock (toolbar for export, import, preview, theme toggle)
- Canvas (drop zone, responsive, mobile notice)
- ConfigPanel (controls for style, binding, property panels)
e. State Management
- Jotai atoms (src/atoms/*) – global state for mode, tutorial, bindings, isMobile, etc.
- Custom hooks (src/hooks/*) – useBindings, useDraggable, useTogglePreviewMode, useLoadTableData, etc.
f. Data Integration
- API calls (via useLoadTableData hook) to external endpoints for table data
- Export/import JSON (components/layout/AppDock/Export.tsx & Import.tsx)
g. Utilities & Constants
- Constants (src/constants/*) – component types, binding events, canvas sizes
- Utils (src/utils & src/lib/utils.ts) – layout-io, canvas math, object/string helpers, table validation
h. Testing & CI/CD
- Playwright tests (tests/*) for e2e coverage
- Lighthouse CI (GitHub Actions workflows: .github/workflows/lighthouse.yml)

##### Relationships & Data Flows
- User → Drag-and-drop → DndProvider → Atom state → Canvas Renderer → UI update
- ConfigPanel → Atom state → Renderer reconfiguration
- API endpoint → useLoadTableData → Atom/Local state → Table component
- AppDock Export → Serialize atom state → Download JSON
- AppDock Import → Parse JSON → Populate atom state → Re-render Canvas
- Next.js server feeding the initial HTML/JS bundle to the browser, then React hydration and client-side routing.

##### Architectural Patterns
- Provider Pattern: multiple React context providers wrap the app (Device, Dnd, Theme).
- Atomic Design / Domain-Driven Segmentation:
- atoms/hook layers for state
- components organized by feature (ui primitives, renderer, draggable, layout, motion)
- Separation of Concerns:
- Presentation components vs. domain logic (hooks, utils) vs. configuration (constants, types)

##### Relevant Technologies
- Next.js (App Router, SSR/SSG)
- React & ReactDOM (client rendering)
- Jotai (state management)
- react-dnd (drag & drop)
- Tailwind CSS + shadcn/ui (styling & UI primitives)
- motion-primitives (animations)
- Playwright (end-to-end testing)
- Lighthouse CI & GitHub Actions (performance monitoring)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Layer 1: Browser & User Interaction"
        direction TB
        User["User"]:::external
        Browser["Browser"]:::external
    end

    subgraph "Layer 2: Next.js Server & Routing"
        direction TB
        NextServer["Next.js Server (SSR/SSG)"]:::server
        Layout["Layout (src/app/layout.tsx)"]:::frontend
        Page["Page (src/app/page.tsx)"]:::frontend
        Config["next.config.ts"]:::server
    end

    subgraph "Layer 3: React App & Providers"
        direction TB
        subgraph "Providers"
            direction TB
            DeviceProv["DeviceProvider"]:::frontend
            ClientDeviceProv["ClientDeviceProvider"]:::frontend
            DndProv["DndProvider"]:::frontend
            ThemeProv["ThemeProvider"]:::frontend
        end
        subgraph "State Management"
            direction TB
            Atoms["Jotai Atoms (src/atoms/*)"]:::state
            Hooks["Custom Hooks (src/hooks/*)"]:::state
        end
        subgraph "UI Components & Renderer"
            direction TB
            UIP["UI Primitives (src/components/ui/)"]:::component
            MotionP["Motion Primitives (src/components/motion-primitives/)"]:::component
            Renderer["Renderer (src/components/renderer/)"]:::component
        end
        subgraph "Layout & Canvas"
            direction TB
            AppDock["AppDock (src/components/layout/AppDock/)"]:::component
            Canvas["Canvas (src/components/layout/Canvas/)"]:::component
            Library["ComponentLibrary (src/components/layout/ComponentLibrary.tsx)"]:::component
            ConfigPanel["ConfigPanel (src/components/layout/ConfigPanel/)"]:::component
        end
    end

    subgraph "Layer 4: Data & IO"
        direction TB
        API["External API"]:::data
        ExportImport["Export/Import JSON"]:::data
        Constants["Constants (src/constants/)"]:::util
        Utils["Utils (src/utils & src/lib/utils.ts)"]:::util
    end

    subgraph "Layer 5: Testing & CI/CD"
        direction TB
        PlaywrightTests["Playwright E2E Tests (tests/)"]:::ci
        PlaywrightConfig["playwright.config.ts"]:::ci
        LighthouseCI[".github/workflows/lighthouse.yml"]:::ci
        PlaywrightCI[".github/workflows/playwright.yml"]:::ci
    end

    User -->|"interacts via UI"| Browser
    Browser -->|"requests page"| NextServer
    NextServer -->|"serves HTML/JS"| Layout
    Layout --> Page
    Page --> DeviceProv
    DeviceProv --> ClientDeviceProv
    ClientDeviceProv --> DndProv
    DndProv --> ThemeProv
    ThemeProv --> Atoms
    Atoms --> Hooks
    Hooks --> Renderer
    UIP --> Renderer
    MotionP --> Renderer
    Renderer --> Canvas
    Canvas --> Browser
    Library --> DndProv
    ConfigPanel --> Atoms
    ConfigPanel --> Renderer
    AppDock --> Atoms
    AppDock --> ExportImport
    ExportImport --> Atoms
    API --> Hooks
    Hooks --> Renderer
    Atoms --> Utils
    Atoms --> Constants

    PlaywrightTests --> PlaywrightConfig
    PlaywrightCI --> PlaywrightTests
    LighthouseCI --> PlaywrightCI

    click Layout "https://github.com/olwooz/schnode/blob/main/src/app/layout.tsx"
    click Page "https://github.com/olwooz/schnode/blob/main/src/app/page.tsx"
    click Config "https://github.com/olwooz/schnode/blob/main/next.config.ts"
    click DeviceProv "https://github.com/olwooz/schnode/blob/main/src/components/DeviceProvider.tsx"
    click ClientDeviceProv "https://github.com/olwooz/schnode/blob/main/src/components/ClientDeviceProvider.tsx"
    click DndProv "https://github.com/olwooz/schnode/blob/main/src/components/DndProvider.tsx"
    click ThemeProv "https://github.com/olwooz/schnode/blob/main/src/components/ThemeProvider.tsx"
    click UIP "https://github.com/olwooz/schnode/blob/main/src/components/ui/alert-dialog.tsx"
    click MotionP "https://github.com/olwooz/schnode/blob/main/src/components/motion-primitives/border-trail.tsx"
    click Renderer "https://github.com/olwooz/schnode/blob/main/src/components/renderer/index.ts"
    click AppDock "https://github.com/olwooz/schnode/blob/main/src/components/layout/AppDock/index.tsx"
    click Canvas "https://github.com/olwooz/schnode/blob/main/src/components/layout/Canvas/index.tsx"
    click Library "https://github.com/olwooz/schnode/blob/main/src/components/layout/ComponentLibrary.tsx"
    click ConfigPanel "https://github.com/olwooz/schnode/blob/main/src/components/layout/ConfigPanel/index.tsx"
    click Atoms "https://github.com/olwooz/schnode/blob/main/src/atoms/binding.ts"
    click Hooks "https://github.com/olwooz/schnode/blob/main/src/hooks/useBindings.ts"
    click Constants "https://github.com/olwooz/schnode/tree/main/src/constants/"
    click Utils "https://github.com/olwooz/schnode/blob/main/src/utils/layout-io.ts"
    click PlaywrightTests "https://github.com/olwooz/schnode/blob/main/tests/drag-and-drop.spec.ts"
    click PlaywrightConfig "https://github.com/olwooz/schnode/blob/main/playwright.config.ts"
    click LighthouseCI "https://github.com/olwooz/schnode/blob/main/.github/workflows/lighthouse.yml"
    click PlaywrightCI "https://github.com/olwooz/schnode/blob/main/.github/workflows/playwright.yml"

    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef server fill:#ccf,stroke:#333,stroke-width:1px
    classDef frontend fill:#cfc,stroke:#333,stroke-width:1px
    classDef state fill:#fcf,stroke:#333,stroke-width:1px
    classDef component fill:#ffc,stroke:#333,stroke-width:1px
    classDef data fill:#cff,stroke:#333,stroke-width:1px
    classDef util fill:#eef,stroke:#333,stroke-width:1px
    classDef ci fill:#fdd,stroke:#333,stroke-width:1px
```
