19 KiB
19 KiB
Tasks: OnDeck Policy Renewal Workflow Management System
Generated from:
prd-ondeck-policy-renewal.md
Relevant Files
package.json- Project dependencies and scriptsdocker-compose.yml- Docker configuration for app and PostgreSQLDockerfile- Container build configuration.env.example- Environment variable templateprisma/schema.prisma- Database schema definitionprisma/migrations/- Database migration filesprisma/seed.ts- Database seeding scriptsrc/app/layout.tsx- Root layout with providerssrc/app/page.tsx- Landing/redirect pagesrc/app/api/auth/[...nextauth]/route.ts- NextAuth.js API route for Entra IDsrc/app/api/auth/[...nextauth]/route.test.ts- Tests for auth routesrc/lib/auth.ts- NextAuth configuration and helperssrc/lib/auth.test.ts- Tests for auth helperssrc/middleware.ts- Auth and RBAC middlewaresrc/middleware.test.ts- Tests for middlewaresrc/app/api/sync/route.ts- Manual sync trigger endpointsrc/app/api/sync/route.test.ts- Tests for sync endpointsrc/lib/sync/sync-engine.ts- AFW sync logicsrc/lib/sync/sync-engine.test.ts- Tests for sync enginesrc/lib/sync/scheduler.ts- Cron-based sync schedulersrc/lib/sync/afw-connection.ts- SQL Server connection to AFWsrc/lib/sync/afw-connection.test.ts- Tests for AFW connectionsrc/lib/sync/mappers.ts- AFW to local data mapperssrc/lib/sync/mappers.test.ts- Tests for data mapperssrc/app/(dashboard)/layout.tsx- Dashboard layout with sidebarsrc/app/(dashboard)/dashboard/page.tsx- Personal dashboardsrc/app/(dashboard)/dashboard/page.test.tsx- Tests for personal dashboardsrc/app/(dashboard)/clients/page.tsx- Client list pagesrc/app/(dashboard)/clients/page.test.tsx- Tests for client listsrc/app/(dashboard)/clients/[id]/page.tsx- Client detail pagesrc/app/(dashboard)/clients/[id]/page.test.tsx- Tests for client detailsrc/app/(dashboard)/tasks/page.tsx- Task list pagesrc/app/(dashboard)/tasks/page.test.tsx- Tests for task listsrc/app/(dashboard)/manager/page.tsx- Manager dashboardsrc/app/(dashboard)/manager/page.test.tsx- Tests for manager dashboardsrc/app/(dashboard)/admin/page.tsx- Admin dashboardsrc/app/(dashboard)/admin/shapes/page.tsx- Shape management pagesrc/app/(dashboard)/admin/templates/page.tsx- Task template managementsrc/app/(dashboard)/admin/sync/page.tsx- Sync configuration pagesrc/app/(dashboard)/admin/users/page.tsx- User/role management pagesrc/app/api/clients/route.ts- Clients API endpointssrc/app/api/clients/route.test.ts- Tests for clients APIsrc/app/api/clients/[id]/route.ts- Single client APIsrc/app/api/tasks/route.ts- Tasks API endpointssrc/app/api/tasks/route.test.ts- Tests for tasks APIsrc/app/api/tasks/[id]/route.ts- Single task APIsrc/app/api/shapes/route.ts- Shapes API endpointssrc/app/api/shapes/route.test.ts- Tests for shapes APIsrc/app/api/templates/route.ts- Task templates APIsrc/app/api/templates/route.test.ts- Tests for templates APIsrc/app/api/notifications/route.ts- Notifications APIsrc/app/api/admin/sync-config/route.ts- Sync configuration APIsrc/app/api/admin/roles/route.ts- Role mapping APIsrc/components/ui/- shadcn/ui components directorysrc/components/layout/sidebar.tsx- Navigation sidebar componentsrc/components/layout/header.tsx- Header with user menusrc/components/clients/client-list.tsx- Client list componentsrc/components/clients/client-detail.tsx- Client detail componentsrc/components/clients/shape-selector.tsx- Shape dropdown componentsrc/components/clients/personnel-picker.tsx- Entra user pickersrc/components/tasks/task-list.tsx- Task list componentsrc/components/tasks/task-card.tsx- Individual task cardsrc/components/tasks/task-form.tsx- Task create/edit formsrc/components/tasks/status-select.tsx- Status dropdown with N/A notessrc/components/dashboard/kpi-card.tsx- KPI display cardsrc/components/dashboard/task-summary.tsx- Task summary widgetsrc/components/dashboard/workload-chart.tsx- Workload distribution chartsrc/components/notifications/notification-bell.tsx- Notification icon/dropdownsrc/components/admin/shape-form.tsx- Shape create/edit formsrc/components/admin/template-form.tsx- Template create/edit formsrc/components/admin/sync-status.tsx- Sync health widgetsrc/lib/db.ts- Prisma client singletonsrc/lib/utils.ts- Utility functionssrc/types/index.ts- TypeScript type definitionssrc/types/enums.ts- Enum definitions matching Prismatailwind.config.ts- Tailwind CSS configurationjest.config.js- Jest test configurationjest.setup.js- Jest setup file
Notes
- Unit tests should typically be placed alongside the code files they are testing (e.g.,
MyComponent.tsxandMyComponent.test.tsxin the same directory). - Use
npx jest [optional/path/to/test/file]to run tests. Running without a path executes all tests found by the Jest configuration. - This project uses Next.js App Router with server components by default.
- shadcn/ui components are installed via
npx shadcn-ui@latest add [component-name]. - Environment variables should never be committed; use
.env.exampleas a template.
Tasks
-
1.0 Project Setup & Infrastructure
- 1.1 Initialize Next.js project with TypeScript (
npx create-next-app@latest ondeck --typescript --tailwind --eslint --app --src-dir) - 1.2 Install and configure shadcn/ui (
npx shadcn-ui@latest init) - 1.3 Install core shadcn/ui components (button, card, input, select, table, dialog, dropdown-menu, tabs, badge, toast, avatar, skeleton)
- 1.4 Create
docker-compose.ymlwith app service and PostgreSQL service (use ondeck database credentials) - 1.5 Create
Dockerfilefor Next.js production build - 1.6 Create
.env.examplewith all required environment variables (DATABASE_URL, NEXTAUTH_, AZURE_AD_, AFW_*) - 1.7 Configure Tailwind with custom theme colors for Shape designations
- 1.8 Set up Jest testing framework with React Testing Library
- 1.9 Create base project folder structure (
src/app,src/components,src/lib,src/types) - 1.10 Create
src/lib/utils.tswith common utility functions (cn, formatDate, etc.)
- 1.1 Initialize Next.js project with TypeScript (
-
2.0 Authentication & Authorization (Entra ID)
- 2.1 Install NextAuth.js and Azure AD provider (
npm install next-auth @azure/msal-node) - 2.2 Create NextAuth configuration in
src/lib/auth.tswith Azure AD provider - 2.3 Configure Azure AD provider to request group claims in token
- 2.4 Create
src/app/api/auth/[...nextauth]/route.tsAPI route - 2.5 Create auth session provider wrapper component
- 2.6 Implement user upsert on first login (create user record from Entra token)
- 2.7 Create role resolution logic (map Entra groups to app roles from entra_group_role_mappings table)
- 2.8 Create
src/middleware.tsfor route protection and RBAC enforcement - 2.9 Define permission sets per role (Admin, Manager, Account Executive, Claims) in constants
- 2.10 Create
useSessionandusePermissionscustom hooks for client components - 2.11 Create higher-order component or wrapper for role-based UI rendering
- 2.12 Write unit tests for auth helpers and role resolution logic
- 2.1 Install NextAuth.js and Azure AD provider (
-
3.0 Database Schema & ORM Setup
- 3.1 Install Prisma (
npm install prisma @prisma/client) - 3.2 Initialize Prisma with PostgreSQL (
npx prisma init --datasource-provider postgresql) - 3.3 Define User model with Entra fields (entra_oid, email, display_name, department, is_active, last_login_at)
- 3.4 Define Role model with permissions JSONB field
- 3.5 Define EntraGroupRoleMapping model for group-to-role configuration
- 3.6 Define UserRole junction table for direct role assignments
- 3.7 Define Shape model with name, description, color, rules, display_order, is_active
- 3.8 Define Client model with AMS sync fields and custom fields (shape_id, shape2_id, primary_personnel_id, notes, custom_fields JSONB)
- 3.9 Define ClientPersonnel junction table for additional personnel assignments
- 3.10 Define Policy model with AMS sync fields and expiration_date index
- 3.11 Define TaskStatus and TaskPriority enums (include NA status)
- 3.12 Define TaskTemplate model with department, timing, days_offset, default_priority
- 3.13 Define Task model with all fields including na_reason, cancelled_reason
- 3.14 Define TaskAssignment junction table for multi-user assignment
- 3.15 Define SyncLog model for sync run tracking
- 3.16 Define SyncConfig model for admin-configurable sync settings
- 3.17 Define AuditLog model for change tracking
- 3.18 Define Notification model for in-app notifications
- 3.19 Define NotificationPreference model for user notification settings
- 3.20 Create initial migration (
npx prisma migrate dev --name init) - 3.21 Create
src/lib/db.tsPrisma client singleton - 3.22 Create
prisma/seed.tswith default roles, initial shapes, and sample task templates - 3.23 Run seed script (
npx prisma db seed)
- 3.1 Install Prisma (
-
4.0 AFW Data Sync Engine
- 4.1 Install SQL Server driver (
npm install mssql) - 4.2 Create
src/lib/sync/afw-connection.tswith connection pool management - 4.3 Create AFW query functions for: AFW_Customer, AFW_BasicPolInfo, AFW_Employee, AFW_GeneralLedgerDepartment, AFW_Company, AFW_PRCode
- 4.4 Implement date filter for policies (current year + 24 months expiration)
- 4.5 Create
src/lib/sync/mappers.tswith AFW-to-local data transformation functions - 4.6 Create
src/lib/sync/sync-engine.tswith main sync orchestration logic - 4.7 Implement incremental sync based on ChangedDate/ModifiedDate fields
- 4.8 Implement upsert logic (insert new, update existing based on ams_*_id)
- 4.9 Implement soft-delete handling (mark inactive if removed from AFW, never hard delete)
- 4.10 Create SyncLog entries for each sync run (start, end, counts, errors)
- 4.11 Implement retry logic with exponential backoff (3 attempts)
- 4.12 Create
src/lib/sync/scheduler.tsusing node-cron for scheduled sync - 4.13 Read sync schedule from SyncConfig table (default 2 AM)
- 4.14 Create
src/app/api/sync/route.tsPOST endpoint for manual sync trigger (Admin only) - 4.15 Create
src/app/api/sync/status/route.tsGET endpoint for sync status - 4.16 Write unit tests for mappers and sync logic (mock AFW connection)
- 4.1 Install SQL Server driver (
-
5.0 Client Management Module
- 5.1 Create
src/app/api/clients/route.tswith GET (list with pagination, filtering) and search - 5.2 Implement client list filters: department, shape, personnel, search term
- 5.3 Create
src/app/api/clients/[id]/route.tswith GET (detail), PATCH (update custom fields) - 5.4 Create
src/app/api/clients/[id]/personnel/route.tsfor managing additional personnel - 5.5 Implement RBAC filtering (users see only assigned clients unless Manager/Admin)
- 5.6 Create
src/components/clients/client-list.tsxwith data table, sorting, filtering - 5.7 Create
src/components/clients/client-card.tsxfor list item display with Shape color badge - 5.8 Create
src/app/(dashboard)/clients/page.tsxclient list page - 5.9 Create
src/app/(dashboard)/clients/[id]/page.tsxclient detail page - 5.10 Create
src/components/clients/client-detail.tsxwith tabs for policies, tasks, personnel - 5.11 Create
src/components/clients/shape-selector.tsxdropdown with color swatches - 5.12 Create
src/components/clients/personnel-picker.tsxsearchable Entra user selector - 5.13 Implement audit logging for client modifications
- 5.14 Create policies sub-section showing all client policies with days-until-renewal
- 5.15 Write unit tests for client components and API routes
- 5.1 Create
-
6.0 Shape/Designation Management
- 6.1 Create
src/app/api/shapes/route.tswith GET (list) and POST (create) - Admin only - 6.2 Create
src/app/api/shapes/[id]/route.tswith GET, PATCH (update), DELETE (soft delete/deactivate) - 6.3 Create
src/components/admin/shape-form.tsxwith fields: name, description, color picker, rules, display_order, is_active - 6.4 Create
src/components/admin/shape-list.tsxwith drag-and-drop reordering - 6.5 Create
src/app/(dashboard)/admin/shapes/page.tsxShape management page - 6.6 Implement color picker component for Shape color selection
- 6.7 Add validation to prevent deleting Shapes that are in use (only deactivate)
- 6.8 Design UI to be extensible for future designation types (abstract designation pattern)
- 6.9 Write unit tests for Shape API and components
- 6.1 Create
-
7.0 Task Management & Templates
- 7.1 Create
src/app/api/templates/route.tswith GET (list by department) and POST (create) - Admin/Manager - 7.2 Create
src/app/api/templates/[id]/route.tswith GET, PATCH, DELETE - 7.3 Create
src/components/admin/template-form.tsxwith fields: name, description, department, timing, days_offset, default_priority - 7.4 Create
src/app/(dashboard)/admin/templates/page.tsxtemplate management page grouped by department - 7.5 Create
src/app/api/tasks/route.tswith GET (list with filters) and POST (create) - 7.6 Create
src/app/api/tasks/[id]/route.tswith GET, PATCH (update status, reassign), DELETE - 7.7 Create
src/app/api/tasks/bulk/route.tsfor bulk status update and reassignment - 7.8 Implement task due_date calculation: policy.expiration_date + days_offset
- 7.9 Create
src/components/tasks/status-select.tsxwith N/A option that shows notes modal - 7.10 Implement N/A status validation (require na_reason when status = NA)
- 7.11 Implement CANCELLED status validation (require cancelled_reason)
- 7.12 Create
src/components/tasks/task-list.tsxwith filtering, sorting, status badges - 7.13 Create
src/components/tasks/task-card.tsxwith priority indicator, due date, assignees - 7.14 Create
src/components/tasks/task-form.tsxfor create/edit with client/policy selection - 7.15 Create
src/app/(dashboard)/tasks/page.tsxtask list page - 7.16 Create
src/lib/tasks/auto-generate.tstask auto-generation logic from templates - 7.17 Implement renewal window detection (configurable days before expiration, default 90)
- 7.18 Implement duplicate prevention (check existing tasks for same policy/template)
- 7.19 Auto-assign generated tasks to client's primary_personnel_id
- 7.20 Create cron job or trigger for daily task auto-generation check
- 7.21 Implement audit logging for task changes
- 7.22 Write unit tests for task API, auto-generation, and components
- 7.1 Create
-
8.0 Dashboards & Reporting
- 8.1 Create
src/components/dashboard/kpi-card.tsxreusable KPI display component - 8.2 Create
src/components/dashboard/task-summary.tsxshowing overdue, due today, due this week, upcoming - 8.3 Create
src/components/dashboard/renewal-calendar.tsxmini calendar showing upcoming renewals - 8.4 Create
src/app/api/dashboard/personal/route.tsaggregating personal KPIs - 8.5 Create
src/app/(dashboard)/dashboard/page.tsxpersonal dashboard with My Tasks, My Clients, Quick Stats - 8.6 Create
src/components/dashboard/workload-chart.tsxbar chart for tasks per team member - 8.7 Create
src/components/dashboard/completion-chart.tsxline chart for completion trends - 8.8 Create
src/components/dashboard/status-pie-chart.tsxpie chart for task status distribution - 8.9 Create
src/app/api/dashboard/manager/route.tsaggregating team KPIs - 8.10 Create
src/app/(dashboard)/manager/page.tsxmanager dashboard with team overview, department metrics - 8.11 Implement drill-down from aggregate metrics to individual user/task lists
- 8.12 Create
src/components/admin/sync-status.tsxwidget showing last sync, status, row counts - 8.13 Create
src/app/api/dashboard/admin/route.tsaggregating system health and cross-department metrics - 8.14 Create
src/app/(dashboard)/admin/page.tsxadmin dashboard with system health, sync status, user activity - 8.15 Implement dashboard data caching for <2 second load times
- 8.16 Install charting library (recharts or chart.js) for visualizations
- 8.17 Write unit tests for dashboard components and API routes
- 8.1 Create
-
9.0 Notifications System
- 9.1 Create
src/app/api/notifications/route.tswith GET (list user notifications) and PATCH (mark read) - 9.2 Create
src/app/api/notifications/[id]/route.tsfor individual notification actions - 9.3 Create Notification model entries for: task_assigned, task_overdue, task_completed, sync_failed
- 9.4 Create
src/components/notifications/notification-bell.tsxwith unread count badge - 9.5 Create
src/components/notifications/notification-dropdown.tsxshowing recent notifications - 9.6 Create
src/components/notifications/notification-item.tsxindividual notification display - 9.7 Implement notification creation triggers (on task assignment, status change, overdue detection)
- 9.8 Create daily job to generate overdue task notifications
- 9.9 Create
src/app/api/notifications/preferences/route.tsfor user notification settings - 9.10 Create notification preferences UI in user settings
- 9.11 Design notification system to support future Teams/Email channels (abstract notification sender)
- 9.12 Write unit tests for notification components and API
- 9.1 Create
-
10.0 Admin Configuration & System Health
- 10.1 Create
src/app/api/admin/sync-config/route.tsGET and PATCH for sync settings - 10.2 Create
src/app/(dashboard)/admin/sync/page.tsxwith sync time picker, enable/disable toggle, manual trigger button - 10.3 Create
src/app/api/admin/sync-logs/route.tsGET for sync history with pagination - 10.4 Display sync log history with status, duration, row counts, errors
- 10.5 Create
src/app/api/admin/roles/route.tsfor Entra group-to-role mapping CRUD - 10.6 Create
src/app/(dashboard)/admin/users/page.tsxshowing users, their roles, last login - 10.7 Create UI for managing Entra Group → Role mappings
- 10.8 Create
src/app/api/admin/audit-logs/route.tsGET for audit log viewing - 10.9 Create audit log viewer with filtering by user, entity type, date range
- 10.10 Implement audit log creation middleware/helper for sensitive operations
- 10.11 Implement system health checks (DB connection, AFW connection, last sync status)
- 10.12 Write unit tests for admin API routes and components
- 10.1 Create