How anentrypoint/thatcher works
Purpose and Entry Points
Thatcher is a configuration-driven framework for data-intensive CRUD applications. YAML defines entities, permissions, workflows, and UI behavior; the runtime generates generic APIs, persistence behavior, and client rendering.
Primary entry points:
• Programmatic factory: src/index.js
• CLI (start, dev, migration, validation, example generation): src/cli.js
• Server bootstrap and HTTP runtime: src/server/server.js, src/lib/server-bootstrap.js
• Example consumer configuration: examples/minimal/thatcher.config.yml, examples/minimal/app.js
Configuration-to-Spec Pipeline
Configuration loading converts the project YAML and environment into normalized application metadata. The spec-generation layer combines entity declarations, defaults, and extensibility metadata into runtime entity specifications.
Key paths:
• src/config/config-loader.js
• src/lib/config-generator-engine.js
• src/lib/domain-loader.js
This is the central boundary: downstream CRUD, permissions, workflow, UI, and routing should consume generated entity specs rather than raw YAML.
Core Engine and Persistence
The main engine exposes programmatic CRUD, search, transactions, workflow transitions, and authorization. Persistence is backed by Busybase/LanceDB-style document storage, with entity tables created or used dynamically from specs.
Key paths:
• src/engine.js
• src/engine.server.js
• src/lib/busybase/store.js
• src/lib/busybase/adapter.js
Control flow is generally: API or SDK call → entity spec lookup → authorization/validation → hooks/workflow checks → Busybase read/write → audit/events/response.
Generic HTTP API Surface
Next-style route modules provide generic entity CRUD plus dedicated operational APIs. The catch-all entity endpoint is the principal externally generated REST boundary; specialized routes cover auth, files, email, domains, audit, metrics, and cron actions.
Key paths:
• src/app/api/[entity]/[[...path]]/route.js
• src/lib/crud-factory.js
• src/lib/crud-handlers.js
Request orchestration and method dispatch are centralized in:
• src/lib/universal-handler.js
• src/lib/route-resolver.js
• src/lib/http-methods-factory.js
Policy, Validation, and Lifecycle
Authorization is role/template-based with row-access constraints. CRUD inputs pass through validation and CSRF/security middleware. Entity lifecycle extensions run through hooks; stateful entities use a workflow engine to validate transitions, stage locks, and role requirements.
Key paths:
• src/services/permission.service.js
• src/lib/auth-middleware.js
• src/lib/validation-middleware.js
• src/lib/hook-engine.js
• src/lib/workflow-engine.js
Audit logging wraps material actions and feeds dedicated audit APIs:
• src/lib/with-audit-logging.js
• src/lib/audit-logger-enhanced.js
UI, State Transport, and Realtime
The repository includes a browser UI renderer rather than relying on an external frontend. UI modules render entity pages, dashboards, dialogs, and auth screens, then call framework APIs. State transport and realtime-server modules support synchronized/reconnecting client-server state.
Key paths:
• src/ui/client.js
• src/ui/renderer.js
• src/ui/entity-renderer.js
• src/lib/state-transport-server.js
• src/lib/realtime-server.js
Operations, Extensions, and Runtime
Bun is the primary CLI runtime, though most ES modules can run under Node; Busybase is the material storage dependency. Development hot reload watches configuration and safely invalidates/rebuilds runtime state.
Key paths:
• src/lib/hot-reload/index.js
• src/lib/hot-reload/directory-watcher.js
• src/plugins/index.js
External service boundaries include Google OAuth/Drive/Gmail and SMTP email:
• src/adapters/google-auth.js
• src/adapters/google-drive.js
• src/adapters/google-gmail.js
• src/services/email-sender.js
Observability is exposed through metrics, monitoring, health, debug, and audit API routes.
Main entry points: engine.js Application Engine · server.js Server Bootstrap · config-loader.js Config Loader · config-generator-engine.js Spec Generator
Components 21
Entry & Runtime
- Programmatic Factory
src/index.js - CLI · Starts development, migrations, validation, and example generation.
src/cli.js - Server Bootstrap
src/server/server.js
Configuration & Specs
- Config Loader · Normalizes project configuration and environment.
src/config/config-loader.js - Spec Generator · Produces runtime entity specifications from declarations and defaults.
src/lib/config-generator-engine.js - Domain Loader
src/lib/domain-loader.js
HTTP API
- Entity REST Route · Catch-all external CRUD endpoint.
src/app/api/[entity]/[[...path]]/route.js - Request Orchestration · Centralizes route resolution and method dispatch.
src/lib/universal-handler.js - CRUD Factory
src/lib/crud-factory.js
Core Execution
- Application Engine · Executes CRUD, search, transactions, authorization, and transitions from entity specs.
src/engine.js - Policy & Validation · Applies role and row access, input validation, and CSRF protection.
src/services/permission.service.js - Hooks & Workflows · Runs extensions and enforces state transitions, locks, and role requirements.
src/lib/workflow-engine.js - Audit Logging · Records material actions for audit APIs.
src/lib/audit-logger-enhanced.js - Busybase Store · Dynamically uses entity tables derived from specs.
src/lib/busybase/store.js
Browser & Realtime
- UI Client
src/ui/client.js - Entity Renderer · Renders entity pages and framework screens.
src/ui/entity-renderer.js - State Transport · Supports synchronized and reconnecting client state.
src/lib/state-transport-server.js
Extensions & Operations
- Hot Reload · Watches configuration and rebuilds runtime state safely.
src/lib/hot-reload/index.js - Plugins
src/plugins/index.js - Google Services · OAuth, Drive, and Gmail adapters.
src/adapters/google-auth.js - Email Sender · SMTP email delivery.
src/services/email-sender.js
Connections 22
- Programmatic Factory → Application Engine: creates
- CLI → Server Bootstrap: starts
- Server Bootstrap → Config Loader: loads configuration
- Config Loader → Spec Generator: normalized YAML
- Domain Loader → Spec Generator: domain metadata
- Spec Generator → Application Engine: entity specs
- Server Bootstrap → Entity REST Route: serves
- Entity REST Route → Request Orchestration: requests
- Request Orchestration → CRUD Factory: dispatches
- CRUD Factory → Application Engine: CRUD operations
- Application Engine → Policy & Validation: authorizes and validates
- Policy & Validation → Hooks & Workflows: approved operations
- Hooks & Workflows → Busybase Store: reads and writes
- Application Engine → Audit Logging: material actions
- UI Client → Entity Renderer: renders with
- Entity Renderer → Entity REST Route: framework API calls
- UI Client → State Transport: synchronizes state
- State Transport → Application Engine: state operations
- Hot Reload → Config Loader: reloads configuration
- Plugins → Application Engine: extends
- Application Engine → Google Services: external actions
- Application Engine → Email Sender: email delivery