|
| 1 | +# Backend Domain Model and Endpoint Boundaries |
| 2 | + |
| 3 | +This document outlines the core backend entities, their relationships, and the boundaries between different modules in the Access Layer Server. |
| 4 | + |
| 5 | +## Domain Model |
| 6 | + |
| 7 | +The following diagram illustrates the core entities and their relationships within the system: |
| 8 | + |
| 9 | +```mermaid |
| 10 | +erDiagram |
| 11 | + User ||--o| CreatorProfile : "owns" |
| 12 | + User ||--o| StellarWallet : "links" |
| 13 | + User { |
| 14 | + string id PK |
| 15 | + string email |
| 16 | + string passwordHash |
| 17 | + string firstName |
| 18 | + string lastName |
| 19 | + boolean emailVerified |
| 20 | + } |
| 21 | + CreatorProfile { |
| 22 | + string id PK |
| 23 | + string userId FK |
| 24 | + string handle |
| 25 | + string displayName |
| 26 | + string bio |
| 27 | + json perks |
| 28 | + } |
| 29 | + StellarWallet { |
| 30 | + string id PK |
| 31 | + string userId FK |
| 32 | + string address |
| 33 | + } |
| 34 | + IndexerDLQ { |
| 35 | + string id PK |
| 36 | + string jobType |
| 37 | + json payload |
| 38 | + string failureReason |
| 39 | + } |
| 40 | + AuditEvent { |
| 41 | + string id PK |
| 42 | + string actor |
| 43 | + string action |
| 44 | + string target |
| 45 | + string targetId |
| 46 | + json metadata |
| 47 | + } |
| 48 | +``` |
| 49 | + |
| 50 | +### Core Entities |
| 51 | + |
| 52 | +1. **User**: Represents a registered user. Holds authentication and basic profile data. |
| 53 | +2. **CreatorProfile**: Represents the creator persona of a user. Tied to a specific handle and contains metadata like bio and perks. |
| 54 | +3. **StellarWallet**: Links a user to their Stellar public address. Used for identity verification and ownership checks. |
| 55 | +4. **IndexerDLQ**: Stores failed indexing jobs from the Stellar blockchain for manual review or reprocessing. |
| 56 | +5. **AuditEvent**: A generic log for significant actions occurring in the system. |
| 57 | + |
| 58 | +## Module Boundaries |
| 59 | + |
| 60 | +The server is organized into feature-based modules under `src/modules/`. Each module is responsible for its own business logic, routes, and (where applicable) data validation. |
| 61 | + |
| 62 | +### Major Route Groups |
| 63 | + |
| 64 | +| Module | Responsibility | Primary Entities | |
| 65 | +| :--- | :--- | :--- | |
| 66 | +| `auth` | User registration, login, session management, and password resets. | `User` | |
| 67 | +| `creators` | Public and private creator profile management, including stats and discovery. | `CreatorProfile` | |
| 68 | +| `wallet` | Linking and verifying Stellar wallets. | `StellarWallet` | |
| 69 | +| `admin` | Internal management tools and system monitoring. | All | |
| 70 | +| `health` | System health checks and status monitoring. | N/A | |
| 71 | + |
| 72 | +### Cross-Module Rules |
| 73 | + |
| 74 | +To ensure a maintainable and decoupled architecture, the following rules apply: |
| 75 | + |
| 76 | +1. **No Direct Database Access**: Modules should not directly query Prisma models belonging to other modules if a service/utility exists. |
| 77 | +2. **Shared Utilities**: Common logic (e.g., mail sending, logging, pagination) belongs in `src/utils/` and can be used by any module. |
| 78 | +3. **Constants**: Shared configuration and string constants belong in `src/constants/`. |
| 79 | +4. **Types**: Cross-cutting TypeScript types belong in `src/types/`. |
| 80 | + |
| 81 | +### Interaction Patterns |
| 82 | + |
| 83 | +- **Initialization**: `src/app.ts` assembles the modules and registers global middlewares. |
| 84 | +- **Data Sharing**: If a module needs data from another (e.g., `creators` needing user info), it should use the Prisma client (which is shared) but respect the logical boundaries defined in the schema files. |
0 commit comments