TIP
This page mirrors .agents/end-to-end-features.md from the repository. Edit it at the source, not here.
End-to-End Feature Workflow
Use this when implementing a feature that spans data model, shared domain contracts, API, and web UI.
This file defines implementation order. For package-specific rules, follow the linked docs instead of repeating them here.
When a feature introduces shared contracts that should drive both API and frontend behavior, this workflow also includes packages/core.
Default Order
- If the feature needs new data or persisted fields, update
packages/dbfirst. - If the feature introduces shared enums, schemas, formatters, or defaults consumed across packages, update
packages/corenext. - Put reusable server-side domain workflows in
packages/appwhen both inline API fallback and workers need them. - Add queue contracts, dispatch, processors, schedules, or retention orchestration in
packages/jobswhen work is asynchronous. - Define or extend the oRPC contract in
packages/api. - Add slice-local TanStack Query wrappers in
apps/web. - Handle user-visible client errors using the typed oRPC client pattern.
- Wire route preloading, guards, and UI composition in
apps/web. - Run fixes and relevant validation according to Workflow, using Choice flows only when a human decision is needed.
Step 1: Database
- Edit schemas in
packages/db/src/schema/when the feature changes persisted data. - Follow Workflow for migration generation, localhost
DATABASE_URLsafety, and migration application. - Keep schema and migration work complete before defining API output shapes that depend on it.
Step 2: Shared Domain Contract
- Use
packages/corefor shared Zod schemas, enums, normalizers, formatters, option builders, and defaults consumed by more than one package. - Follow Core package patterns.
- Unless explicitly told not to, if a change should propagate automatically into both API and frontend behavior, centralize it in
packages/coreinstead of duplicating literals in app code. - Route validators, frontend filters, and shared API input or output schemas should import core contracts when they represent the same domain surface.
Step 3: API Contract
Before transport work, decide whether server-side behavior belongs in an application service or a job:
Use
packages/appfor worker-safe domain services with DB/storage/provider side effects but no oRPC or BullMQ registration.Use
packages/jobsfor queue payloads, enqueue helpers, processors, repeatable schedules, and post-domain orchestration such as notifications.Keep
apps/workerlimited to process startup/shutdown, readiness, metrics, signals, andcreateAllWorkers()composition.Add or extend the router in
packages/api.Follow oRPC patterns for procedure factories, explicit
inputandoutputschemas, and typed errors.Prefer type-safe errors with
.errors(...)anderrors.MY_ERROR(...)for expected failure cases the client needs to handle.
Step 4: Web Data Layer
- Use oRPC's TanStack Query integration from
@saasweave/api/client/tanstack-start/orpc. - Follow API fetching patterns for
*.query.ts,*.mutation.ts, query keys, query options, and hook wrappers. - Keep
orpcand TanStack Query wiring inside slice-localapi/files, not inline in page components.
Step 5: Client Error Handling
- For user-visible failure states, follow the type-safe client error pattern in oRPC patterns.
- Do not duplicate string-matched or ad hoc client error handling in web slices when the server already defines typed oRPC errors.
Step 6: Routes And UI
- Follow TanStack patterns for route placement, thin
beforeLoad, and page composition. - Follow UI guidelines for app-level component composition.
- Add Auth patterns, SEO patterns, or i18n guidelines when the feature touches those surfaces.