# How the kit works

Your app has public pages, customer screens, an API, and a PostgreSQL database. Read this overview when deciding where a feature belongs. You can follow the [quickstart](quickstart.md) without learning every layer first.

## Deployment boundary

A founder runs a copy of this kit inside their own Adios team. That deployment owns its PostgreSQL database. Customers of the founder's product are users and workspaces inside that database. They do not need to become members of the founder's Adios team.

A personal workspace and a team workspace use the same schema. Turning a personal workspace into a team changes its kind and memberships; it does not migrate its records to another database.

## Layers

| Layer | Ownership | Current implementation |
| --- | --- | --- |
| kit | Migration ledger and installed modules | SQL and administration CLI |
| core | Users, identities, workspaces, memberships, billing records, usage, audit, outbox, agent-run references | Database foundation |
| contacts / files | Shared contacts, organizations, and object-storage metadata | Database foundation |
| crm / booking / documents / support / cms | Product-specific records | Database foundation |
| Backend | Verified identity, membership, action authorization, transaction boundaries | JavaScript account/team/CRM/billing endpoints; Python/Go adapters |
| Frontend | Public site and authenticated customer app | Kit landing page and JavaScript CRM app |
| Adios integration | Provisioning, workloads, workflows, secrets, managed agents | `adios kit deploy` and `adios kit delete` for PostgreSQL and the CRM app; workflows and agents pending |

Keep large files in object storage and their metadata in PostgreSQL. The files table records an opaque storage key, not a publicly accessible URL. Download authorization must recheck workspace access.

## Module selection versus customer entitlements

Module installation is a founder/deployment decision: it creates schemas and enables code paths for the SaaS. Customer entitlements are separate workspace-scoped records describing access to paid features. Installing CRM must not automatically grant every customer a paid CRM plan.

## Request flow

1. Verify the session or API credential on the server.
2. Resolve the requested customer workspace.
3. Acquire a runtime connection and start a transaction.
4. Set app.workspace_id locally and verify membership for the authenticated user.
5. Check action-level role permissions, module state, and feature entitlement.
6. Read/write domain records using parameters; record events in the same transaction.
7. Commit; dispatch external effects asynchronously with idempotency keys.

The JavaScript runtime implements authentication, membership checks, CRM role checks, and free/Pro limits on top of the transaction adapters. Event workers and broader module authorization remain work. See [the runtime guide](crm-runtime.md) for current behavior.

## AI boundaries

Company, Product, and Tech agents support the founder's business. Customer-facing AI features belong to the application modules and must be scoped to the customer workspace. Existing Agent Kit definitions are candidates for integration, not embedded running services in this increment.
