> For the complete documentation index, see [llms.txt](https://docs.kinwall.family/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kinwall.family/contributing/architecture.md).

# Architecture

The full design and API contract is in [SPEC.md](https://github.com/JohnDuprey/kinwall/tree/main/SPEC.md). In short:

* **One codebase, two runtimes.** A single **Hono** app (`server/src/app.ts`) runs on Cloudflare Workers with D1, or on Node 24 with the built-in `node:sqlite`. On Node, a small adapter (`d1-sqlite.ts`) makes SQLite look like D1.
* **One host seam.** `server/src/entry.ts` exports `createKinwall(env)`, which returns `fetch` and `scheduled`. `worker.ts` and `node.ts` are thin wrappers around it. See [Embedding the server](/contributing/embedding.md).
* **API-first.** The React UI (`web/`, Vite) is just another API client. `@hono/zod-openapi` builds `/openapi.json` and `/docs` from the route schemas. The MCP server (`mcp.ts`) calls the same routes in-process.
* **Providers.** `server/src/providers/` has one module per calendar kind (ICS via `ical.js`, CalDAV via `tsdav`, Google and Microsoft over plain `fetch`) behind one contract (`types.ts`).
* **Background work.** `sync.ts` (chunked calendar sync) and `notify.ts` (Web Push scheduling) run from the Workers cron or Node intervals. `webpush.ts` implements RFC 8291/8292 with Web Crypto, so it runs on Workers.
* **Change bus.** `bus.ts` `emit()` bumps the revision counter behind `/api/rev` and fires [webhooks](/integrations/webhooks.md).
* **Security.** `auth.ts` holds the key scopes, with a deny-by-default allow-list for display keys. `crypto.ts` does AES-256-GCM at rest, and `outbound.ts` has the SSRF guards.
* **Migrations.** `server/migrations/*.sql` are applied at runtime on both targets and tracked in `_migrations`.

```
server/src/  app.ts entry.ts worker.ts node.ts d1-sqlite.ts auth.ts bus.ts mcp.ts sync.ts notify.ts
             routes/*.ts (one file per resource)   providers/*.ts
server/migrations/NNNN_*.sql
web/src/     App.tsx Calendar.tsx Chores.tsx Lists.tsx Settings.tsx Setup.tsx …
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.kinwall.family/contributing/architecture.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
