# anentrypoint/thatcher architecture

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

- Interactive diagram: https://gitdiagram.com/anentrypoint/thatcher
- Repository: https://github.com/anentrypoint/thatcher

## Overview

#### 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: [`src/engine.js`](https://github.com/anentrypoint/thatcher/blob/main/src/engine.js) (Application Engine), [`src/server/server.js`](https://github.com/anentrypoint/thatcher/blob/main/src/server/server.js) (Server Bootstrap), [`src/config/config-loader.js`](https://github.com/anentrypoint/thatcher/blob/main/src/config/config-loader.js) (Config Loader), [`src/lib/config-generator-engine.js`](https://github.com/anentrypoint/thatcher/blob/main/src/lib/config-generator-engine.js) (Spec Generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry &amp; Runtime"]
  node_factory["Programmatic Factory<br/>entry point<br/>[index.js]"]
  node_cli["CLI<br/>command runtime<br/>[cli.js]"]
  node_server["Server Bootstrap<br/>HTTP runtime<br/>[server.js]"]
end

subgraph group_spec["Configuration &amp; Specs"]
  node_config_loader["Config Loader<br/>YAML loader<br/>[config-loader.js]"]
  node_spec_generator["Spec Generator<br/>metadata compiler"]
  node_domain_loader["Domain Loader<br/>domain metadata<br/>[domain-loader.js]"]
end

subgraph group_api["HTTP API"]
  node_entity_api["Entity REST Route<br/>generated API<br/>[route.js]"]
  node_request_router["Request Orchestration<br/>HTTP dispatcher"]
  node_crud_factory["CRUD Factory<br/>handler generator<br/>[crud-factory.js]"]
end

subgraph group_core["Core Execution"]
  node_engine{{"Application Engine<br/>CRUD and workflow engine<br/>[engine.js]"}}
  node_policy_validation["Policy &amp; Validation<br/>security pipeline"]
  node_lifecycle["Hooks &amp; Workflows<br/>lifecycle engine<br/>[workflow-engine.js]"]
  node_audit["Audit Logging<br/>audit trail"]
  node_store[("Busybase Store<br/>document persistence<br/>[store.js]")]
end

subgraph group_client["Browser &amp; Realtime"]
  node_ui_client["UI Client<br/>browser entry<br/>[client.js]"]
  node_entity_renderer["Entity Renderer<br/>UI renderer<br/>[entity-renderer.js]"]
  node_state_transport["State Transport<br/>client sync server"]
end

subgraph group_integrations["Extensions &amp; Operations"]
  node_hot_reload["Hot Reload<br/>development runtime<br/>[index.js]"]
  node_plugins["Plugins<br/>extension registry<br/>[index.js]"]
  node_google["Google Services<br/>external integration<br/>[google-auth.js]"]
  node_email["Email Sender<br/>external integration<br/>[email-sender.js]"]
end

node_factory -->|"creates"| node_engine
node_cli -->|"starts"| node_server
node_server -->|"loads configuration"| node_config_loader
node_config_loader -->|"normalized YAML"| node_spec_generator
node_domain_loader -->|"domain metadata"| node_spec_generator
node_spec_generator -->|"entity specs"| node_engine
node_server -->|"serves"| node_entity_api
node_entity_api -->|"requests"| node_request_router
node_request_router -->|"dispatches"| node_crud_factory
node_crud_factory -->|"CRUD operations"| node_engine
node_engine -->|"authorizes and validates"| node_policy_validation
node_policy_validation -->|"approved operations"| node_lifecycle
node_lifecycle -->|"reads and writes"| node_store
node_engine -->|"material actions"| node_audit
node_ui_client -->|"renders with"| node_entity_renderer
node_entity_renderer -->|"framework API calls"| node_entity_api
node_ui_client -->|"synchronizes state"| node_state_transport
node_state_transport -->|"state operations"| node_engine
node_hot_reload -.->|"reloads configuration"| node_config_loader
node_plugins -.->|"extends"| node_engine
node_engine -->|"external actions"| node_google
node_engine -->|"email delivery"| node_email

click node_factory "https://github.com/anentrypoint/thatcher/blob/main/src/index.js"
click node_cli "https://github.com/anentrypoint/thatcher/blob/main/src/cli.js"
click node_server "https://github.com/anentrypoint/thatcher/blob/main/src/server/server.js"
click node_config_loader "https://github.com/anentrypoint/thatcher/blob/main/src/config/config-loader.js"
click node_spec_generator "https://github.com/anentrypoint/thatcher/blob/main/src/lib/config-generator-engine.js"
click node_domain_loader "https://github.com/anentrypoint/thatcher/blob/main/src/lib/domain-loader.js"
click node_entity_api "https://github.com/anentrypoint/thatcher/blob/main/src/app/api/%5Bentity%5D/%5B%5B...path%5D%5D/route.js"
click node_request_router "https://github.com/anentrypoint/thatcher/blob/main/src/lib/universal-handler.js"
click node_crud_factory "https://github.com/anentrypoint/thatcher/blob/main/src/lib/crud-factory.js"
click node_engine "https://github.com/anentrypoint/thatcher/blob/main/src/engine.js"
click node_policy_validation "https://github.com/anentrypoint/thatcher/blob/main/src/services/permission.service.js"
click node_lifecycle "https://github.com/anentrypoint/thatcher/blob/main/src/lib/workflow-engine.js"
click node_audit "https://github.com/anentrypoint/thatcher/blob/main/src/lib/audit-logger-enhanced.js"
click node_store "https://github.com/anentrypoint/thatcher/blob/main/src/lib/busybase/store.js"
click node_ui_client "https://github.com/anentrypoint/thatcher/blob/main/src/ui/client.js"
click node_entity_renderer "https://github.com/anentrypoint/thatcher/blob/main/src/ui/entity-renderer.js"
click node_state_transport "https://github.com/anentrypoint/thatcher/blob/main/src/lib/state-transport-server.js"
click node_hot_reload "https://github.com/anentrypoint/thatcher/blob/main/src/lib/hot-reload/index.js"
click node_plugins "https://github.com/anentrypoint/thatcher/blob/main/src/plugins/index.js"
click node_google "https://github.com/anentrypoint/thatcher/blob/main/src/adapters/google-auth.js"
click node_email "https://github.com/anentrypoint/thatcher/blob/main/src/services/email-sender.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_factory,node_cli,node_server toneBlue
class node_config_loader,node_spec_generator,node_domain_loader toneAmber
class node_entity_api,node_request_router,node_crud_factory toneMint
class node_engine,node_policy_validation,node_lifecycle,node_audit,node_store toneRose
class node_ui_client,node_entity_renderer,node_state_transport toneIndigo
class node_hot_reload,node_plugins,node_google,node_email toneTeal
```

## Components

### Entry & Runtime

- [Programmatic Factory](https://github.com/anentrypoint/thatcher/blob/main/src/index.js): entry point · `src/index.js`
- [CLI](https://github.com/anentrypoint/thatcher/blob/main/src/cli.js): command runtime · Starts development, migrations, validation, and example generation. · `src/cli.js`
- [Server Bootstrap](https://github.com/anentrypoint/thatcher/blob/main/src/server/server.js): HTTP runtime · `src/server/server.js`

### Configuration & Specs

- [Config Loader](https://github.com/anentrypoint/thatcher/blob/main/src/config/config-loader.js): YAML loader · Normalizes project configuration and environment. · `src/config/config-loader.js`
- [Spec Generator](https://github.com/anentrypoint/thatcher/blob/main/src/lib/config-generator-engine.js): metadata compiler · Produces runtime entity specifications from declarations and defaults. · `src/lib/config-generator-engine.js`
- [Domain Loader](https://github.com/anentrypoint/thatcher/blob/main/src/lib/domain-loader.js): domain metadata · `src/lib/domain-loader.js`

### HTTP API

- [Entity REST Route](https://github.com/anentrypoint/thatcher/blob/main/src/app/api/%5Bentity%5D/%5B%5B...path%5D%5D/route.js): generated API · Catch-all external CRUD endpoint. · `src/app/api/[entity]/[[...path]]/route.js`
- [Request Orchestration](https://github.com/anentrypoint/thatcher/blob/main/src/lib/universal-handler.js): HTTP dispatcher · Centralizes route resolution and method dispatch. · `src/lib/universal-handler.js`
- [CRUD Factory](https://github.com/anentrypoint/thatcher/blob/main/src/lib/crud-factory.js): handler generator · `src/lib/crud-factory.js`

### Core Execution

- [Application Engine](https://github.com/anentrypoint/thatcher/blob/main/src/engine.js): CRUD and workflow engine · Executes CRUD, search, transactions, authorization, and transitions from entity specs. · `src/engine.js`
- [Policy & Validation](https://github.com/anentrypoint/thatcher/blob/main/src/services/permission.service.js): security pipeline · Applies role and row access, input validation, and CSRF protection. · `src/services/permission.service.js`
- [Hooks & Workflows](https://github.com/anentrypoint/thatcher/blob/main/src/lib/workflow-engine.js): lifecycle engine · Runs extensions and enforces state transitions, locks, and role requirements. · `src/lib/workflow-engine.js`
- [Audit Logging](https://github.com/anentrypoint/thatcher/blob/main/src/lib/audit-logger-enhanced.js): audit trail · Records material actions for audit APIs. · `src/lib/audit-logger-enhanced.js`
- [Busybase Store](https://github.com/anentrypoint/thatcher/blob/main/src/lib/busybase/store.js): document persistence · Dynamically uses entity tables derived from specs. · `src/lib/busybase/store.js`

### Browser & Realtime

- [UI Client](https://github.com/anentrypoint/thatcher/blob/main/src/ui/client.js): browser entry · `src/ui/client.js`
- [Entity Renderer](https://github.com/anentrypoint/thatcher/blob/main/src/ui/entity-renderer.js): UI renderer · Renders entity pages and framework screens. · `src/ui/entity-renderer.js`
- [State Transport](https://github.com/anentrypoint/thatcher/blob/main/src/lib/state-transport-server.js): client sync server · Supports synchronized and reconnecting client state. · `src/lib/state-transport-server.js`

### Extensions & Operations

- [Hot Reload](https://github.com/anentrypoint/thatcher/blob/main/src/lib/hot-reload/index.js): development runtime · Watches configuration and rebuilds runtime state safely. · `src/lib/hot-reload/index.js`
- [Plugins](https://github.com/anentrypoint/thatcher/blob/main/src/plugins/index.js): extension registry · `src/plugins/index.js`
- [Google Services](https://github.com/anentrypoint/thatcher/blob/main/src/adapters/google-auth.js): external integration · OAuth, Drive, and Gmail adapters. · `src/adapters/google-auth.js`
- [Email Sender](https://github.com/anentrypoint/thatcher/blob/main/src/services/email-sender.js): external integration · SMTP email delivery. · `src/services/email-sender.js`

## Connections

- 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
