Skip to content

[v2][backend] Adopt a layered module architecture (route -> controller -> service -> repository) #1261

Description

@Calebux

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

  • backend/ARCHITECTURE.md documents the layers and the allowed import directions.
  • An eslint boundary rule fails CI when a route imports a repository or a service imports a route.
  • At least the subscriptions, payments and reminders domains are fully migrated.
  • No public API path or response shape changes as part of the migration, verified by the existing route tests.

Files / areas

backend/src, backend/ARCHITECTURE.md, eslint.config.mjs


Part of the SYNCRO v2 rewrite. Epic: D — Backend architecture.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programarea:architectureArchitecture and structurearea:backendBackend services and platformpriority:p0Highest priorityv2-rewriteSYNCRO v2 rewrite program

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions