Professional Services Automation (Implementation Portal)
Source-backed overview for apps/backend/src/implementation-portal/.
The backend module is named implementation-portal. Product and MCP-facing wording may use PSA.
For deeper operational diagnostics, see:
dev/runbooks/implementation-portal-troubleshooting
What this module provides
- guide template management (phases and steps)
- implementation boards cloned from templates
- staff execution workflows (status, assignees, due dates, time, attachments, comments)
- OTP-secured client portal interactions
- invoice-draft generation and send flow
Architecture map (hexagonal)
| Layer | Key codepaths | Responsibility |
|---|---|---|
| Domain | domain/entities/*, domain/services/*, domain/ports/* | Core business rules and contracts |
| Application | application/use-cases/* | Workflow orchestration over ports |
| Infrastructure | infrastructure/persistence/kysely/*, storage/payment/notification adapters, cron processor | DB and third-party adapters |
| Interfaces | interfaces/http/*, DTOs, guards | HTTP endpoints and request adapters |
Rule of thumb:
- Domain/application define behavior.
- Infrastructure performs I/O (DB, Stripe, GCS, SendGrid).
Public interfaces (high-level)
Team-facing APIs
guide-template.controller.tsimplementation-board.controller.tsboard-step.controller.tsinvoice-draft.controller.ts
Client-facing APIs
client-portal.controller.tsportal-session.guard.tsfor write routes
Core workflows
1) Template to board
- Create guide template.
- Create board with optional template.
BoardFactoryServiceclones phases/steps and applies due offsets.
2) Execution
- Team updates step lifecycle and assignments.
- Time entries recorded on hourly steps.
- Attachments and comments recorded per step.
3) Client portal
- Client opens
/portal/:shareToken. - Client requests OTP and verifies OTP.
- Client writes through session-guarded routes.
4) Invoice flow
- Generate invoice draft from unbilled eligible steps.
- Review/edit line-item descriptions.
- Send via payment adapter (Stripe integration point).
- Track sent/paid/void states.
Important constraints from source
- Document steps require at least one attachment before completion.
- Time entries:
- only allowed on hourly steps
- minimum
0.25hours
- Step attachment max size: 50 MB (
STEP_ATTACHMENT_MAX_BYTES). - Team cannot edit/delete time entries once step is linked to an invoice draft.
- Client comments are persisted as
client_visible.
Invoice calculation rules (InvoiceCalculatorService):
non_billable: excludedfixed: include when step iscompleted|approved|client_approvedmilestone: only approval steps inapproved|client_approvedhourly:sum(timeEntry.hours) * hourlyRatein eligible statuses
Health model
OverdueCheckerService:
- green: 0 overdue
- yellow: 1-2 overdue
- red: 3+ overdue OR stale board (>7 days without step updates)
Multi-tenancy and authorization
- Team APIs scoped by
:businessId. - Policy decorators enforce
GuideTemplate,ImplementationBoard,BoardStep, andInvoiceDraftactions. - Client write operations require valid portal session token (header or cookie path).