How corebunch/instatic works
1. This is a single-product monorepo centered on one Bun server.
The repo splits into three big runtime surfaces: src/server for backend APIs and publishing, src/admin for the React admin/editor app, and src/core for shared domain logic and schemas. Built-in editor modules live in src/modules, while reusable UI primitives live in src/ui.
2. The main architectural boundary is “admin/editor” vs “public site.”
The admin app is a Vite-built React SPA that talks to the Bun server through typed persistence/API clients. The public site is not served from the editor runtime; it is generated by the publisher into static artifacts and then served by the server/public router with a small dynamic runtime only where needed.
3. src/core is the domain layer and source of truth.
It contains the canonical models and schemas for content, page trees, layouts, forms, fonts, framework tokens, module engine, templates, loops, site runtime, site import, visual components, plugins, and persistence contracts. Most server handlers and admin views depend on these core types rather than duplicating business rules.
4. src/server is a modular backend with a hand-written router.
server/index.ts, server/router.ts, and server/http.ts anchor the request pipeline. Feature-specific handlers live under server/handlers/cms, server/ai/handlers, and other top-level subsystems. The server uses repository modules (server/repositories) to isolate DB access and keep request logic separate from persistence.
5. Persistence flows through a shared DB abstraction with SQLite/Postgres parity.
server/db selects the concrete client and runs dialect-specific migrations, while repositories encapsulate tables like users, sessions, media, plugins, site settings, publish state, and data rows. The repo emphasizes schema validation at boundaries via TypeBox and shared validation helpers in src/core/persistence.
6. The admin app is organized as workspaces, not a generic dashboard.
Major user surfaces are src/admin/pages/site, content, data, media, plugins, users, ai, and dashboard. Each workspace owns its own state slices, hooks, panels, dialogs, and canvas/editor components, with shared chrome in src/admin/shared and routing in src/admin/router.tsx.
7. The site editor is a canvas-driven state machine.
src/admin/pages/site contains the visual canvas, inspector panels, tree explorer, module picker, toolbar, preview, and editor store. The store is split into slices for selection, clipboard, layouts, settings, site data, style rules, visual components, and undo/redo. This is the core editing subsystem for pages, layouts, templates, and reusable components.
8. Built-in modules provide the editor’s composable block system.
src/modules/base defines standard blocks such as text, button, image, link, container, forms, list, video, SVG, outlet, slot instance/outlet, and visual component refs. These modules feed the module engine in src/core/module-engine and the editor canvas in src/admin/pages/site/canvas, so module rendering and editing stay aligned.
9. Publishing is a separate pipeline that converts editor state into clean output.
The publisher in src/core/publisher and server/publish turns site state into semantic HTML, compact CSS, static assets, and route-aware dynamic holes. It includes render caching, loop rendering, CSS collection, CSP planning, asset bundling, and static artifact management. This is the key public-site data flow: content and design state in, files on disk out.
10. Dynamic public requests are minimized and cached aggressively.
server/publish/publicRouter.ts, server/publish/renderCache.ts, and related runtime helpers serve prebuilt pages and only fall back to live rendering for truly dynamic paths. The README’s “static by default” promise is reflected in the architecture: publish invalidates caches, swaps artifacts atomically, and keeps the public runtime small.
11. The plugin system is a sandboxed runtime with explicit host boundaries.
Plugins are packaged and loaded through src/core/plugins and server/plugins, then executed in QuickJS-WASM under server/plugins/quickjs and server/plugins/host. The host/worker split, message protocol, and capability gates keep plugins isolated from filesystem, secrets, and unrestricted network access unless permissions are granted.
12. Plugin capabilities are first-class across the product.
Plugins can contribute admin pages, panels, dashboard widgets, canvas overlays, routes, media storage adapters, schedules, loops, and lifecycle hooks. The plugin SDK in src/core/plugin-sdk defines the manifest/builders/types used by plugin authors, while host registries and event broadcasters wire installed plugins into the rest of the system.
13. AI is a separate subsystem with provider drivers, tool runtime, and persistence.
server/ai includes provider adapters for Anthropic, OpenAI, OpenRouter, and Ollama, plus streaming/tool-loop infrastructure and audit/conversation/credential stores. On the admin side, src/admin/pages/site/agent and src/admin/pages/content/agent expose agent panels and bridges that let the assistant modify real site/content state through controlled tools.
14. Content, data, forms, and loops all share the same underlying row model.
src/core/data, src/core/forms, src/core/loops, and server/handlers/cms/data show a common pattern: structured tables and rows are the canonical content substrate. Pages/posts/custom collections/forms feed the same storage model, and loops render collections back onto pages through defined sources and templates.
15. Media and files are treated as a managed subsystem, not raw uploads.
server/handlers/cms/media*, server/repositories/media*, and src/admin/pages/media cover upload dispatch/execution, folders, variants, storage adapters, replacements, and usage tracking. The design supports local disk by default but leaves a clear adapter boundary for alternate storage backends.
16. Security and operational concerns are built into the architecture.
Authentication includes sessions, MFA/TOTP, lockout, rate limiting, and step-up policies in server/auth. Secrets are encrypted at rest, capabilities gate sensitive routes, and architecture tests in src/__tests__/architecture enforce invariants like sandbox isolation, publish behavior, and dependency boundaries. Deployment is container-friendly via Bun, Docker, Compose, and documented Railway/Caddy/VPS flows.
Main entry points: core Core domain · router.tsx Admin router · components UI kit · router.ts Router
Components 26
Server
Bun backend, routing, persistence, publishing, auth, plugins, AI, and runtime serving.
- Server entry · Bootstraps the Bun process, config, HTTP pipeline, and top-level router.
server/index.ts - Router · Hand-written request router and HTTP dispatch layer for CMS, public, and utility routes.
server/router.ts - CMS handlers · Backend API surface for site, content, media, data, users, publish, forms, and admin operations.
server/handlers/cms/index.ts - DB layer · Database client selection, dialect-specific migrations, and low-level SQL access.
server/db/index.ts - Repositories · Table-oriented persistence modules for users, sessions, media, plugins, publish state, site, and data rows.
server/repositories - Publisher · Converts site state into HTML, CSS, assets, caches, and static artefacts for the public site.
server/publish/publishSite.ts - Public router · Serves published artefacts and performs the small dynamic fallback runtime when needed.
server/publish/publicRouter.ts - Auth · Sessions, MFA, lockout, rate limiting, step-up policies, and security primitives.
server/auth/security.ts - Plugin host · Plugin packaging, host boundary, QuickJS execution, protocol, worker pool, and capability gates.
server/plugins/runtime.ts - AI runtime · Provider adapters, tool loop, streaming transport, conversation/audit stores, and server AI handlers.
server/ai/runtime/index.ts
Core
Shared domain models, schemas, publisher logic, plugin SDK, import/export, and site runtime contracts.
- Core domain · Canonical models and schemas for content, pages, layouts, forms, templates, loops, plugins, and persistence.
src/core - Page tree · Page, layout, selector, condition, mutation, and explorer-path logic for the site document model.
src/core/page-tree/index.ts - Core publisher · Shared rendering, CSS collection, CSP planning, loops, and visual component ref handling.
src/core/publisher/index.ts - Persistence contracts · Shared CMS/auth/data/media/publish/runtime schemas and validation helpers used by server and clients.
src/core/persistence/index.ts - Plugin SDK · Builders, manifest types, permissions, admin/page/panel/resource schemas, and sandbox interfaces.
src/core/plugin-sdk/index.ts - Site import · HTML/CSS/font/media ingestion, plan building, rewrites, and commit logic for importing sites.
src/core/siteImport/index.ts - Site runtime · Runtime config, asset manifest, and import-analysis contracts for the public site runtime.
src/core/site-runtime/index.ts
Admin
React/Vite editor and workspaces for site, content, data, media, plugins, users, dashboard, and AI.
- Admin router · Vite/React app shell, routing, auth gates, and workspace navigation.
src/admin/router.tsx - Site editor · Canvas-driven editor for pages, layouts, templates, and visual components with its own store and panels.
src/admin/pages/site/SitePage.tsx - Content workspace · Content collection and document editor with live canvas, agent bridge, and collection tools.
src/admin/pages/content/ContentPage.tsx - Data workspace · Data-table management UI for schemas, rows, relations, previews, and exports.
src/admin/pages/data/DataPage.tsx - Media workspace · Media library, folders, upload queue, variants, viewers, and replacement flows.
src/admin/pages/media/MediaPage.tsx - Plugins page · Installed plugin management, permissions review, schedules, settings, and embedded plugin UI.
src/admin/pages/plugins/PluginsPage.tsx
Shared UI
Reusable UI primitives and built-in editor modules shared across admin and runtime.
- UI kit · Reusable buttons, dialogs, tables, inputs, widgets, and other shared UI primitives.
src/ui/components - Base modules · Composable editor blocks such as text, button, image, link, container, forms, list, outlet, and visual component refs.
src/modules/base
Public runtime
Generated public-site artifacts and the minimal serving/runtime path.
- Static artifacts · Published HTML, CSS, scripts, and asset bundles served to public visitors.
server/publish/staticArtefact.ts
Connections 37
- Server entry → Router: boots · The server entry initializes and hands requests to the router.
- Router → CMS handlers: dispatches · Router sends authenticated admin/API requests to CMS handlers.
- Router → Public router: serves · Router exposes the public-site serving path.
- Router → Auth: gates · Authentication and step-up policies protect admin routes.
- CMS handlers → Repositories: uses · Feature handlers persist through repository modules.
- Repositories → DB layer: queries · Repositories isolate SQL and dialect details behind the DB layer.
- CMS handlers → Persistence contracts: validates · Handlers rely on shared persistence schemas and validation helpers.
- CMS handlers → Core domain: depends on · Backend logic uses canonical domain models instead of duplicating rules.
- Publisher → Core publisher: renders with · Server publish uses shared rendering and CSS logic.
- Publisher → Repositories: reads · Publishing loads site state, rows, media, and publish records from repositories.
- Publisher → Static artifacts: writes · Publisher emits static artefacts and updated bundles.
- Public router → Static artifacts: serves · Public routing prefers prebuilt artefacts before dynamic fallback.
- Public router → Publisher: falls back to · Dynamic requests can trigger live rendering behavior from the publisher stack.
- Plugin host → Plugin SDK: implements · Plugin host/runtime follows the shared SDK contracts.
- Plugin host → Repositories: stores · Plugin state, secrets, schedules, and records persist via repositories.
- AI runtime → Core domain: uses · AI tools operate on shared content/site schemas and snapshots.
- Admin router → Site editor: routes to · The admin shell routes into the site editor workspace.
- Admin router → Content workspace: routes to · The admin shell routes into content editing.
- Admin router → Data workspace: routes to · The admin shell routes into data management.
- Admin router → Media workspace: routes to · The admin shell routes into media management.
- Admin router → Plugins page: routes to · The admin shell routes into plugin administration.
- Site editor → Core domain: models · The site editor store and panels are driven by core domain types.
- Site editor → Base modules: renders · The canvas editor composes built-in modules.
- Content workspace → Core domain: models · Content workspace uses shared content/data schemas.
- Data workspace → Core domain: models · Data workspace uses shared row and table schemas.
- Media workspace → Core domain: models · Media workspace uses shared media/file contracts.
- Plugins page → Plugin SDK: configures · Plugin admin views are shaped by the plugin SDK and manifest contracts.
- Site editor → UI kit: uses · Editor UI relies on shared primitives and chrome components.
- Content workspace → UI kit: uses · Content workspace uses shared UI primitives.
- Data workspace → UI kit: uses · Data workspace uses shared UI primitives.
- Media workspace → UI kit: uses · Media workspace uses shared UI primitives.
- Plugins page → UI kit: uses · Plugin admin UI uses shared UI primitives.
- Page tree → Core domain: defines · Page-tree structures are part of the canonical domain layer.
- Core publisher → Page tree: renders · Rendering walks the page tree and related selector/mutation state.
- Site import → Core domain: ingests into · Import planning produces canonical site and content structures.
- Site runtime → Core publisher: feeds · Runtime contracts support publication and public rendering.
- Base modules → Core domain: registers · Built-in modules define canonical block behavior and schemas through core.