Context
backend/src has 40+ route files and 80+ service files with no enforced layering. Routes reach directly into Supabase, services import other services freely, and business rules live in whichever file happened to need them first. This is the structural reason the same bug class (missing user scoping, missing audit event, swallowed persistence error) keeps recurring across unrelated features.
Scope
- Define the four layers and what each may import; write it into
backend/ARCHITECTURE.md.
- Reorganise
backend/src by domain module (subscriptions, payments, reminders, privacy, admin, integrations), each containing its own routes/controller/service/repository/schema files.
- Enforce the layering with an import-boundary lint rule that fails CI on violations.
- Migrate module by module behind the existing route paths so no API contract changes.
Acceptance criteria
Files / areas
backend/src, backend/ARCHITECTURE.md, eslint.config.mjs
Part of the SYNCRO v2 rewrite. Epic: D — Backend architecture.
Context
backend/srchas 40+ route files and 80+ service files with no enforced layering. Routes reach directly into Supabase, services import other services freely, and business rules live in whichever file happened to need them first. This is the structural reason the same bug class (missing user scoping, missing audit event, swallowed persistence error) keeps recurring across unrelated features.Scope
backend/ARCHITECTURE.md.backend/srcby domain module (subscriptions, payments, reminders, privacy, admin, integrations), each containing its own routes/controller/service/repository/schema files.Acceptance criteria
backend/ARCHITECTURE.mddocuments the layers and the allowed import directions.Files / areas
backend/src,backend/ARCHITECTURE.md,eslint.config.mjsPart of the SYNCRO v2 rewrite. Epic: D — Backend architecture.