# ConusAI App Template

> A multi-tenant B2B application on ConusAI Cloud. Sign-in, organizations, workspaces and
> projects with roles and invitations, audit, usage metering, observability, background jobs and
> an accessible branded UI are already here. What a developer adds is domain modules under
> modules/; nothing under apps/ changes to add one.

Read AGENTS.md first: it is the contract for anyone, human or agent, writing code here.

## Shape

- Modular monolith. One repository, one image, three processes: `web`, `worker` and a `migrate`
  job (compose.yaml, conusai.json).
- `modules/<id>/` is a vertical slice: `contract/` (zod schemas and procedure contracts, the only
  thing other modules may import), `core/` (use cases, pure TypeScript), `adapters/` (one per
  engine), `ui/`, `i18n/`, `__tests__/`.
- `modules/index.ts` is the module list, and the registry is built from the manifests in it and
  from nothing else.
- `apps/web` is the Next.js shell and the one HTTP mount; `apps/worker` runs jobs, cron and the
  outbox relay; `config/` holds the deployment contract, the app brand and the feature flags.

## Kernel packages

- `@conusai-kit/core` — defineModule, the registry, the procedure builder, problem+json, the DI container
- `@conusai-kit/data` — repository and unit-of-work ports, the outbox, idempotency, JobQueue
- `@conusai-kit/tenancy` — organizations, workspaces, projects, roles, invitations
- `@conusai-kit/data-kysely` — the Postgres adapter, row-level security, the migration runner
- `@conusai-kit/jobs-pgboss` — the job adapter and the worker runtime
- `@conusai-kit/files`, `@conusai-kit/proposals` — uploads with `files.processors`; AI output a person approves, edits or rejects
- `@conusai-kit/platform` — the deployment contract and the ports over the ConusAI SDKs
- `@conusai-kit/auth` — the OIDC backend-for-frontend, sessions, bearer tokens, API keys
- `@conusai-kit/ui`, `@conusai-kit/i18n`, `@conusai-kit/brand` — components, messages, tokens
- `@conusai-kit/testing` — the adapter contract suite and the generated isolation suite

## Commands

- `pnpm gate` — typecheck, lint, boundaries, tests, build. Run it before you say you are done.
- `pnpm dev` — the web shell against the local stack in compose.dev.yaml
- `pnpm openapi` — regenerate openapi.json after a procedure's schemas change
- `pnpm migrate` — apply the migrations with the owner's URL (the migrate job's own command)

## Files worth reading first

- AGENTS.md — the rules (CLAUDE.md imports it; .claude/settings.json and .claude/skills/ are the Claude Code permissions and skills)
- README.md — how to run it and what is in it
- modules/index.ts — the module list
- config/src/env.ts — which Postgres role each process holds, and why
- apps/web/src/server/router.ts — the one HTTP mount
- migrations/postgres/0001_kernel.sql — the kernel schema
