Instruction file imported from Kevan-Y/Themoo (
.github/instructions/backend.instructions.md). Copyright stays with the author.
Backend Rules (services/core/)
Before Committing
- Always run
pnpm test:runfromservices/core/to verify no tests are broken. - Run
pnpm tscfromservices/core/to catch type errors. - If
@starter/sdkimports fail, runpnpm --filter @starter/sdk buildfirst.
Adding a Feature
Every feature lives in src/features/<name>/. Handler → service → DynamoDB:
- Handler (
<name>Handler.ts) — parse + validate input, call service, return response. - Service — pure business logic, receives
RequestWithAuth, calls DynamoDB. - Never put DynamoDB calls directly in the handler.
Error Handling
- Throw
AppException(message, StatusCode.XXX)—app.onErrorserializes it automatically. - Use
ErrorMessage[StatusCode.XXX].genericXxxfor standard messages, never raw strings.
DynamoDB
- All writes that touch multiple items must use
TransactWriteCommand. - Access pattern is always
PK = USER#<clerkUserId>— never query without this.
Testing
- Test files live in
src/features/<name>/__tests__/. - Use
vitest— no jest globals; importdescribe,it,expectfromvitest.