Add Service
When the user invokes /add-service, follow these steps:
- •
Ask for the domain, action, and entity (e.g., domain=users, action=upsert, entity=user).
- •
Create/update repository at
apps/api/src/repositories/[entity].repo.ts:- •Class-based with Drizzle queries
- •Always filter
isNull(deletedAt)for reads - •Use
onConflictDoUpdatefor upserts - •Export type:
export type Entity = typeof dimEntityTable.$inferSelect
- •
Create service function at
apps/api/src/services/[domain]/[action]-[entity].ts:- •Factory pattern:
export function actionEntityService(repo) { return async (input) => { ... } } - •Keep business logic here, not in repos or routes
- •Factory pattern:
- •
Add to ServiceContainer: Wire the service into the domain service class and
ServiceContainer. - •
Update services middleware if needed:
apps/api/src/middleware/services.middleware.ts - •
Write tests at
apps/api/src/services/[domain]/[action]-[entity].test.ts:- •Mock repositories
- •Test success and error paths
- •Use
describeblocks and descriptive names
- •
Run tests:
pnpm --filter=api testto verify everything passes.