# markkitz/notion-htmx architecture

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

- Interactive diagram: https://gitdiagram.com/markkitz/notion-htmx
- Repository: https://github.com/markkitz/notion-htmx

## Overview

##### Project’s Purpose and Type
- From the README and file tree, this is a tutorial/demo full-stack data-table web app.
- Tech stack: Bun (server runtime), ElysiaJS (HTTP framework), HTMX + Hyperscript (front-end interaction), UnoCSS/Tailwind (styling).

##### File Structure to Extract Layers
- Top-level “public/” → static files (index.html, CSS/JS bundles).
- Entry point “main.tsx” → bootstraps the ElysiaJS server, sets up routes.
- “src/components/” + “src/context/” → UI component library and front-end state.
- “src/controllers/” → HTTP handlers (e.g. tableController.tsx).
- “src/database/” → database connection and persistence logic.
- “src/schema/” → data models/schema definitions.
- Build/config: package.json, tsconfig.json, Dockerfile, bun scripts.

##### Sketch the Main System Components
a. Client Browser
- Renders HTML (public/index.html)
- Loads HTMX and Hyperscript for dynamic requests and client-side behaviors
- Applies CSS from UnoCSS/Tailwind
- Uses the generated bundle (public/dist/scripts.js, unocss.css)
b. HTTP Server (Bun + ElysiaJS)
- main.tsx – sets up routes & middleware
- Controllers (tableController) expose endpoints for CRUD operations
- Injects rendered TSX components if partial-HTML responses are used
c. Database Layer
- src/database/index.ts – initializes the DB (could be SQLite or in-memory)
- src/schema/dataTable.ts – defines the table schema and validations
d. External/Build Tools
- Bun – package manager + runtime
- UnoCSS/Tailwind – styling engine
- Dockerfile/.dockerignore – containerization

##### Component Relationships & Data Flows
- User Action (click, form edit) → HTMX triggers an HTTP request (GET/POST)
- ElysiaJS Router → dispatches to tableController
- Controller → reads/writes via database module (using schema definitions)
- Controller → returns HTML fragments or JSON
- HTMX → swaps in the returned HTML fragment into the DOM
- Hyperscript → binds inline client-side logic (event handlers, UI updates)

##### Architectural Patterns
- Server-Driven UI: HTMX replaces typical SPA, fetching HTML snippets from the server.
- MVC-style separation:
- View = TSX components + HTMX templates
- Controller = tableController.tsx
- Model = schema + database module
- Layered architecture: Static assets | Presentation (TSX + HTMX) | API/Controllers | Persistence

##### Final Checklist
- Callouts for key technologies (Bun, ElysiaJS, HTMX, UnoCSS)
- Annotations describing the MVC-style flow and server-driven UI
- Optional: include Docker build and runtime on the side if deployment context is needed

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Browser Layer
    subgraph "Browser (Client)"
        direction TB
        User["User Interaction"]:::client
        StaticAssets["Static Assets (public/)"]:::client
        Scripts["HTMX & Hyperscript Bundle\n(public/dist/scripts.js)"]:::client
        Styles["UnoCSS/Tailwind Styles\n(public/dist/unocss.css)"]:::client
        HTMX["HTMX + Hyperscript"]:::client
    end

    %% Server Layer
    subgraph "Server (API)"
        direction TB
        ServerBootstrap["ElysiaJS App & Routes\n(main.tsx)"]:::server
        TableController["HTTP Controllers\n(src/controllers/tableController.tsx)"]:::server
        UIComponents["UI Components\n(src/components/)"]:::server
        Context["Front-end State & Context\n(src/context/index.ts)"]:::server
    end

    %% Database Layer
    subgraph "Database (Persistence)"
        direction TB
        DBInit["Database Initialization\n(src/database/index.ts)"]:::db
        Schema["Data Model & Schema Definitions\n(src/schema/dataTable.ts)"]:::db
    end

    %% Build & Deployment Layer
    subgraph "Build & Deployment"
        direction TB
        Package["package.json"]:::build
        TSConfig["tsconfig.json"]:::build
        UnoConfig["uno.config.ts"]:::build
        DockerfileNode["Dockerfile"]:::build
        DockerIgnore[".dockerignore"]:::build
    end

    %% Connections
    User -->|"click/interaction"| HTMX
    HTMX -->|"GET /table"| ServerBootstrap
    ServerBootstrap -->|"dispatch"| TableController
    TableController -->|"reads/writes"| DBInit
    DBInit -->|uses schema| Schema
    TableController -->|"returns HTML fragment"| HTMX
    HTMX -->|"swaps in DOM snippet"| User

    %% Click Events
    click StaticAssets "https://github.com/markkitz/notion-htmx/tree/main/public/"
    click Scripts "https://github.com/markkitz/notion-htmx/blob/main/public/dist/scripts.js"
    click Styles "https://github.com/markkitz/notion-htmx/blob/main/public/dist/unocss.css"
    click ServerBootstrap "https://github.com/markkitz/notion-htmx/blob/main/main.tsx"
    click TableController "https://github.com/markkitz/notion-htmx/blob/main/src/controllers/tableController.tsx"
    click UIComponents "https://github.com/markkitz/notion-htmx/tree/main/src/components/"
    click Context "https://github.com/markkitz/notion-htmx/blob/main/src/context/index.ts"
    click DBInit "https://github.com/markkitz/notion-htmx/blob/main/src/database/index.ts"
    click Schema "https://github.com/markkitz/notion-htmx/blob/main/src/schema/dataTable.ts"
    click Package "https://github.com/markkitz/notion-htmx/blob/main/package.json"
    click TSConfig "https://github.com/markkitz/notion-htmx/blob/main/tsconfig.json"
    click UnoConfig "https://github.com/markkitz/notion-htmx/blob/main/uno.config.ts"
    click DockerfileNode "https://github.com/markkitz/notion-htmx/tree/main/Dockerfile"
    click DockerIgnore "https://github.com/markkitz/notion-htmx/blob/main/.dockerignore"

    %% Styles
    classDef client fill:#b3d4fc,stroke:#023e8a,color:#000
    classDef server fill:#c3f9c3,stroke:#2d6a4f,color:#000
    classDef db fill:#f9d1b3,stroke:#b45309,color:#000
    classDef build fill:#e0e0e0,stroke:#6c757d,color:#000
```
