Backend-Modules
Status
Section titled “Status”This document is FINAL and ENFORCEABLE for all business module backends.
It defines:
- what modules exist
- what each module is responsible for
- how modules interact
- what modules must NOT do
- shared rules across all module backends
This is the business backend layer of the system.
1. Purpose
Section titled “1. Purpose”This document defines the Module Backends Domain.
Modules are:
independent backend services responsible for specific business domainsExamples:
- Finance
- Market
- Touring
- Venue
- AI
2. Position in architecture
Section titled “2. Position in architecture”Frontend → Module Backend → (Base optional) → DB → Middleware → AuthModules:
- DO NOT compute access
- DO NOT call Core for authorization
- DO NOT decide permissions
- ONLY enforce via middleware
3. Module catalog (initial)
Section titled “3. Module catalog (initial)”| Module | Description |
|---|---|
| basic | core platform features (events, dashboard, artists, etc.) |
| finance | expenses, income, settlements, accounting |
| market | contracts, deals, artist booking |
| touring | tours, routing, schedules |
| venue | venue management, availability |
| ai | analytics, copilots, predictions |
3.1 Module documentation links
Section titled “3.1 Module documentation links”Each module backend must have its own detailed documentation.
Use the following structure:
- Each file defines:
- module architecture
- API
- integration
- permissions
- All modules MUST follow this document (
2.3.-Backend-Modules.md)
4. Core rules for ALL modules
Section titled “4. Core rules for ALL modules”4.1 Access enforcement
Section titled “4.1 Access enforcement”Modules MUST use:
validateJwtrequireCompanyContextresolveAccessContextrequireModule()requirePermission()
Modules MUST NOT:
❌ compute access manually❌ trust frontend access state❌ call Core for entitlement checks❌ call Auth directly for decisions (middleware handles it)4.2 Module independence
Section titled “4.2 Module independence”Modules must be independently accessible.Meaning:
- Finance can exist without Basic
- Market can exist without Basic
- Venue can exist without Market
- AI can exist without any other module
4.3 Module = feature gate
Section titled “4.3 Module = feature gate”Access to a module is determined by:
company entitlement (Core)+ membership grant (Auth)5. Inter-module communication
Section titled “5. Inter-module communication”5.1 Allowed pattern
Section titled “5.1 Allowed pattern”Module → Base backend (shared entities)Module → own DBExamples:
- Finance reads Events from Base
- Market reads Artists from Base
- Venue reads Events from Base
5.2 Forbidden pattern
Section titled “5.2 Forbidden pattern”❌ Module → Core (for access decisions)❌ Module → Auth (for access decisions)❌ Module → Module direct coupling (tight coupling)6. Data ownership
Section titled “6. Data ownership”Each module owns its domain data.
Examples:
Section titled “Examples:”Finance owns:
Section titled “Finance owns:”- expenses
- income
- settlements
Market owns:
Section titled “Market owns:”- contracts
- deals
- negotiations
Touring owns:
Section titled “Touring owns:”- tours
- routing
- schedules
Venue owns:
Section titled “Venue owns:”- availability
- layouts
- bookings
AI owns:
Section titled “AI owns:”- predictions
- analytics
- scoring
6.1 Shared data
Section titled “6.1 Shared data”Shared entities (events, artists, etc.):
- live in Base backend
- are READ by modules
- not duplicated across modules
7. Dependency rules
Section titled “7. Dependency rules”7.1 Base dependency
Section titled “7.1 Base dependency”Modules MAY depend on Base for:
- shared entities
- read-only operations
Modules MUST NOT:
❌ replicate Base logic❌ become dependent on Base for access7.2 No Core dependency for access
Section titled “7.2 No Core dependency for access”Modules must NEVER call Core for authorizationCore is only used indirectly through Auth.
8. Standard module structure
Section titled “8. Standard module structure”Each module backend should define:
8.1 Purpose
Section titled “8.1 Purpose”- what problem it solves
8.2 Data ownership
Section titled “8.2 Data ownership”- what it owns
- what it reads
8.3 Required module key
Section titled “8.3 Required module key”Example:
financemarketvenue8.4 Required permissions
Section titled “8.4 Required permissions”Example:
finance.expense.viewfinance.expense.create8.5 Route groups
Section titled “8.5 Route groups”Example:
/api/finance/*/api/market/*8.6 Integration
Section titled “8.6 Integration”- with Base
- with external APIs
8.7 What it must NOT do
Section titled “8.7 What it must NOT do”- access logic duplication
- entitlement logic
- identity management
9. Communication model
Section titled “9. Communication model”Frontend → Module BackendModule Backend → Middleware (Auth resolution)Module Backend → DBModule Backend → Base (optional)10. Error contract
Section titled “10. Error contract”Modules must follow:
401→ auth problem403→ access problem503→ system failure
Defined in:
2.11.-Error-Contract.md
11. Caching
Section titled “11. Caching”Modules:
- may use local cache for performance
- MUST NOT cache access incorrectly
- MUST rely on Auth cache strategy (
2.7)
12. Logging
Section titled “12. Logging”Modules must log:
- userId
- companyId
- endpoint
- action
- result
13. Migration note
Section titled “13. Migration note”Legacy systems (especially Finance):
- must migrate to this model
- must remove local user/permission logic
- must rely on Auth/Core
14. Future modules
Section titled “14. Future modules”New modules must:
- be defined in Core (module catalog)
- be enabled via entitlements
- follow this document
- implement middleware enforcement
- integrate with Base if needed
15. Final rules
Section titled “15. Final rules”Modules own business logic.Auth owns access.Core owns entitlements.Middleware enforces access.16. One-line summary
Section titled “16. One-line summary”Modules are independent backend services that execute business logic, relying on Auth for access enforcement and Core for entitlement definition.