src/index.ts– Hono app entry; mounts routes and Durable ObjectCallState.src/routes/– API surfaces:api.ts,webhooks.ts,mcp.ts,sona.ts(each default-exports a router).src/lib/– Service clients and domain logic (e.g.,openphone.ts,database.ts,ai-orchestrator.ts).src/types/– Shared TypeScript types and env bindings.src/mcp/andmcp-server.ts– MCP server implementation for Claude/Desktop.scripts/– TypeScript maintenance scripts; shell deploy helpers live at repo root.wrangler.toml– Cloudflare Workers, KV, Durable Objects, and env configs.
npm run dev– Start local Worker (Wrangler) with live reload.npm run build– TypeScript compile for the Worker (tsc).npm run build:mcp– Compilemcp-server.tstomcp-server.js.npm test/npm run test:unit/npm run test:watch– Run Vitest.npm run typecheck– TS type-check without emitting.npm run tail– Stream Cloudflare logs.- Deploy:
npm run deploy:staging|npm run deploy:production.
- TypeScript, ES2022, NodeNext modules. Indent 2 spaces.
- Files: kebab-case (
ai-orchestrator.ts), routes default-export their router. - Classes/Types: PascalCase; functions/vars: camelCase.
- Prefer explicit return types; avoid
any. - Validate inputs where applicable (e.g.,
zod). Keep route handlers thin; put logic insrc/lib/.
- Framework: Vitest. Place tests alongside code as
*.test.tsundersrc/. - Test public behavior of routes and lib functions; mock external calls.
- Run
npm testlocally before PRs; add tests for new features and bug fixes.
- Commits: imperative present (“fix: …”, “feat: …”), concise subject.
- PRs must include: summary, rationale, test notes, and any
wrangler.toml/secrets changes. Link issues when relevant. - Ensure
npm run typecheckandnpm testpass; update docs if routes or envs change.
- Do not commit secrets. Use Wrangler secrets:
wrangler secret put NAME --env <env>. - Required secrets commonly include:
OPENPHONE_API_KEY,NEON_DATABASE_URL,JWT_SECRET,ENCRYPTION_KEY,CHITTY_*_SERVICE_TOKEN. - KV (
RECEPTION_KV) and Durable Object (CallState) bindings are defined inwrangler.toml; keep staging/production sections in sync.