Architecture Overview
System map
Chewbills is split into a React frontend, a Node/Express backend, and this Astro Starlight documentation site. Key components:
- Frontend (
frontend/) — React 18 + React Router, Tailwind, React Query, Chart.js. - Backend (
backend/) — Express APIs, Postgres, AI-provider routing, PDF/OCR pipelines. - Docs (
docs/) — Astro + Starlight, fed byuserguide.mdto keep persona workflows synchronized.
Supporting scripts:
scripts/sync-readme-docs.jscopies persona sections fromuserguide.mdinto these MDX files.npm run docs:*helper commands build/run the docs locally and in CI.
See README.md for full architecture diagrams and deployment references.
Authorization and module governance
Section titled “Authorization and module governance”Backend guard model
Section titled “Backend guard model”Module routes should be protected with layered guards:
requireModule('<module-key>')for organization-level module enablement.requireModuleAccess('<module-key>')for role-level module visibility/access.requirePermission('<module-key>', '<action>')for action-level authorization.
This keeps feature enablement, module access, and operation permissions separate and explicit.
Frontend guard model
Section titled “Frontend guard model”Frontend module routes and navigation should align with backend authorization:
requiredFeature: '<module-key>'for feature toggle behavior.- Role-aware module checks (
hasModuleAccess) for UI visibility. - Permission-aware UI affordances for action-level controls.
Default role requirement (strict)
Section titled “Default role requirement (strict)”Membership assignment paths are strict:
- Organizations must have a configured default role (
core.organization_roles.is_default = true). - If missing, user creation, invite acceptance, and SSO JIT membership assignment fail with
DEFAULT_ORG_ROLE_REQUIRED(HTTP422in API flows).
Recommended validation query:
SELECT organization_id, COUNT(*) AS default_rolesFROM core.organization_rolesWHERE is_default = TRUEGROUP BY organization_idHAVING COUNT(*) <> 1;New module onboarding expectations
Section titled “New module onboarding expectations”When introducing a new module:
- Add module actions to
shared/permissions.ts(PERMISSION_CATALOG). - Ensure platform-admin role management UI exposes module access and actions.
- Add backend route guards (
requireModule,requireModuleAccess,requirePermission). - Add frontend route/nav gating (
requiredFeature,hasModuleAccess). - Update architecture and checklist docs (
architecture.md,docs/NEW_MODULE_CHECKLIST.md,docs/MODULE_DEVELOPMENT_GUIDE.md).