# Implementation Plan

## 1. Schema And Migration

- Add care enums and `care_tasks` table to `modules/core/server/schema.ts`.
- Add indexes for queue and schedule queries.
- Run `pnpm db:generate`.
- Review generated SQL.

## 2. Types And Permissions

- Add `care:read` and `care:manage` to `modules/core/types.ts`.
- Add permission definitions and default role grants in `modules/core/server/permissions.ts`.
- Move navigation `/care` permission to `care:read`.
- Add care DTOs, labels, and validators in `modules/care/types.ts`.

## 3. TDD API Tests

- Add `app/api/care/care-routes.test.ts` before implementation.
- Cover:
  - list care tasks
  - permission denial
  - missing active organization
  - start task
  - complete task with notes
  - invalid status
  - missing/cross-organization task

## 4. Server Operations And API Routes

- Add `modules/care/server/operations.ts`.
- Add `GET /api/care/tasks`.
- Add `PATCH /api/care/tasks/[id]`.
- Use `requirePermission`, structured failures, organization scoping, and audit logs.

## 5. Workspace UI

- Replace `app/(app)/app/care/page.tsx` placeholder with real Server Component.
- Keep scoped route delegating to the unscoped route.
- Add `modules/care/components/CareWorkspaceClient.tsx`.
- Implement metrics, filters, table, and start/complete actions.

## 6. Default Workspace Data

- Extend `modules/core/server/default-workspace-data.ts` with care task examples tied to seeded elders.
- Keep seed insertion inside the first-run default workspace transaction.

## 7. Verification

- `pnpm test`
- `pnpm lint`
- `pnpm type-check`
- `pnpm db:generate`
- Review generated SQL.
- `pnpm build`

## Rollback Points

- Before migration generation: remove schema and care module files.
- After migration generation: remove generated care migration plus schema changes.
- After UI/API: remove care API routes, `modules/care`, page changes, permissions, nav permission change, and seed rows.
