Hands-On Lab & Phase Exit
Workflow rules, membership invariant, transaction reasoning, exercises, and oral exam
Phase 14 - Service & Business Logic Architecture
Volume 04 - Professional Backend
Architecture milestone
Implement
v
Verify state
v
Explain boundaries
v
Transfer skill
Phase 14 turns CRUD-oriented service methods into explicit application rules and workflows while keeping infrastructure simple.
Hands-on lab
This lab proves that TaskFlow now protects business state, not only request shape.
Lab A - Status workflow
• Implement ALLOWED_STATUS_TRANSITIONS in TasksService.
• Reject a transition that is not in the policy.
• Set completedAt when moving into DONE.
• Clear completedAt when reopening DONE.
• Verify the persisted row after each operation.
Lab B - Workspace assignment invariant
• Add assigneeId to write DTOs as optional/nullable UUID.
• Load the Task Project workspace context.
• Verify Membership(workspaceId,userId) exists before assignment.
• Return ASSIGNEE_NOT_WORKSPACE_MEMBER for a syntactically valid non-member.
• Verify unassigning with null succeeds.
Lab C - Transaction reasoning
• Implement the explicit /tasks/:id/assignee workflow from the snapshot.
• Use tx for every Prisma query inside the interactive transaction.
• Explain why update-title does not need the same extra transaction.
• Identify one future enterprise operation that would require several dependent writes.
Lab D - Smoke matrix
Scenario Expected
TODO -> IN_PROGRESS Success
IN_PROGRESS -> DONE Success + completedAt populated
DONE -> IN_PROGRESS Success + completedAt cleared
DONE -> TODO directly 409 TASK_STATUS_TRANSITION_NOT_ALLOWED
assign Workspace member Success
assign non-member 409 ASSIGNEE_NOT_WORKSPACE_MEMBER
set new due date in past 400 DUE_DATE_IN_PAST
set dueAt null Success; due date cleared
Exercise levels
Level Challenge
1 - Follow Implement the reference rules and pass the PowerShell smoke checks.
2 - Modify Add a rule that CANCELED Tasks cannot receive a new assignee until restored to TODO.
Level Challenge
3 - Implement Create a changeStatus(id,targetStatus) service method and make generic update delegate status changes
through it.
4 - Engineer Design an approvePurchaseOrder() workflow with at least four invariants and identify exactly which steps must be
transactional. Do not write code until the responsibilities are mapped.
Architecture oral exam
• Why does Zod not own the assignee membership rule?
• Why should completedAt be server-derived?
• When is a single Prisma write enough without $transaction?
• Why does a controller delegate workflow decisions to a service?
• What evidence would justify extracting Task transition rules into another provider?
• How is a business invariant different from a database foreign key?
• Why is authorization not the same as membership-validity business logic?
Phase exit checklist
• controllers remain thin and transport-focused.
• TasksService protects explicit Task workflow rules.
• invalid status transitions produce stable business errors.
• completedAt stays consistent with DONE/reopen behavior.
• Task assignees must belong to the Task workspace.
• business validation is distinct from Zod shape validation.
• transactions are used intentionally, not automatically.
• no Repository Pattern or unnecessary architecture layers were introduced.
• you can map the same service-layer reasoning to HRIS, payroll, procurement, and inventory use cases.
Figure 1 - Phase 14 complete architecture
HTTP request
v
Controller = transport
v
TasksService = use case + invariants
v
PrismaService / transaction when justified
v
PostgreSQL = durable integrity
TaskFlow now has a real application-service layer instead of database-driven CRUD.
Next phase
Phase 15 adds Filtering, Search, Sorting & Pagination. We will design query parameters, safe dynamic Prisma filters,
pagination trade-offs, index-aware access patterns, query DTOs, metadata, and API contracts for collection endpoints.