Unclassified

Work Router Implementation Summary

Overview

Successfully built a complete Work Router system for IntegrateWise that maps users to role-specific workspace views at runtime based on their onboarding profile (Role × Department × Industry). The system is fully isolated, non-disruptive, and ready for integration with Descope auth.

Architecture

1. Data Layer (lib/data/)

Completely isolated data persistence layer with TypeScript-first design.

Files:

  • types.ts - TypeScript interfaces for all domain models (UserProfile, Tenant, Role, Capability, etc.)
  • in-memory-provider.ts - In-memory DataProvider implementation with seed data for dev/preview
  • index.ts - Factory function getDataProvider() for singleton instance

Key Design:

  • DataProvider interface abstracts all data access
  • Repository pattern for each domain (ProfileRepo, TenantRepo, UserRepo, etc.)
  • InMemoryDataProvider ships with seed data for 3 industries (SaaS, Healthcare, Fintech)
  • Drizzle ORM can be swapped in via DrizzleDataProvider (future)
  • No direct SQL/database calls - everything goes through repos

Database Schema (seeded):

  • Users, Profiles, Tenants, Roles, Permissions
  • Plugins, Capabilities, Agents, Deployments
  • Memory items, Audit logs

2. Onboarding Flow (components/onboarding/)

5-step form that collects user profile and persists to DataProvider.

Files:

  • layout.tsx - Onboarding container with progress stepper and navigation
  • steps.tsx - Five step components: Identity, Role, Department, Industry, Confirm
  • onboarding-container.tsx - State management and form orchestration
  • app/onboarding/page.tsx - Route entry point

Flow:

  1. Identity - Name, Email, Organization
  2. Role - Choose from 10 roles (Founder, Sales Rep, Sales Manager, CS Manager, Marketing, Finance, Operations, Product, Engineering, Admin)
  3. Department - Prioritize team focus (Engineering, Sales, Marketing, Operations, Finance, CS, Product, Leadership)
  4. Industry - SaaS, Healthcare, Fintech, or Other
  5. Confirm - Review and persist UserProfile

UX:

  • Responsive design (mobile-first)
  • Full keyboard navigation (Enter to submit)
  • Back button navigation (hidden on step 1)
  • Step progress indicator with completion checks
  • Validation feedback on each step
  • All sections gated by required field validation

3. Work Router (lib/work/)

Runtime view resolution engine.

Files:

  • router.ts - Core resolveWorkView() function with 10 role definitions
  • industry-presets.ts - Industry-specific vocabulary and KPI overrides (SaaS, Healthcare, Fintech, Other)
  • admin-preview.ts - Admin preview mode for impersonating other profiles

Role Views (10 total):

  1. Founder - Company Overview, Priorities, Revenue, Pipeline, Agent Activity
  2. Sales Rep - My Accounts, Contacts, Opportunities, Activities, Playbooks
  3. Sales Manager - Pipeline, Forecast, Team Performance, Deal Risk
  4. CS Manager - Customer Portfolio, Account 360, Health, Renewals, QBRs
  5. Marketing - Campaigns, Content, Calendar, Analytics, Product Launches
  6. Finance - Revenue, Expenses, Subscriptions, Forecast, Infrastructure Costs
  7. Operations - Queues, Tasks, Approvals, Incidents, Deployments
  8. Product - Roadmap, Feedback, Releases, Decisions
  9. Engineering - Connections, Capabilities, Runs, Logs, Deployments
  10. Admin - Organizations, Users, Roles & Permissions, Plugins, Audit Log

Router Logic:

  • Reads role from persisted UserProfile
  • Filters sections by:
    • Required permissions (from role definition)
    • Required capabilities (installed/available)
    • Required plugins (installed)
  • Department-based reordering (extensible for future filters)
  • Industry-specific vocabulary swapping via presets
  • Environment badge (production, staging, dev, etc.)

4. Work View Components (components/work/, app/work/)

Rendering layer that displays resolved views.

Files:

  • work-view-scaffold.tsx - Shared layout with header, sections grid, non-production banner
  • app/work/page.tsx - Main entry point that loads profile, resolves view, renders sections

UX:

  • Grid layout (1 col mobile, 2 col tablet, 3 col desktop)
  • Environment badge (production/staging/dev)
  • Impersonation banner (for admin preview mode)
  • Section cards with icons, descriptions, and placeholder content
  • Graceful error handling with redirect to onboarding
  • Loading state while fetching profile and resolving view

Integration Points

Descope Auth

Currently using mock auth in onboarding and work pages:

function getDemoUser() {
  return {
    userId: "user-demo-001",
    tenantId: "saas-demo",
  };
}

To integrate Descope:

  1. Import Descope auth SDK in onboarding/page.tsx
  2. Get userId from Descope session
  3. Get tenantId from session metadata or org context
  4. Pass to OnboardingContainer

Environment Variables

Uses existing project env vars:

  • DESCOPE_PROJECT_ID - Already configured
  • DESCOPE_MANAGEMENT_KEY - Already configured
  • NEXT_PUBLIC_DESCOPE_PROJECT_ID - Already configured

No new env vars required.

Platform API

Work Router integrates with existing Platform API:

  • DataProvider can read from platform.* surfaces
  • Future: Capabilities and Agents can come from platform registry
  • No modifications to existing Platform API needed

Isolation & Non-Disruption

All Work Router code is completely isolated:

Isolated Routes:

  • /onboarding - New onboarding flow
  • /work - New Work Router view

Isolated Components:

  • components/onboarding/* - Onboarding UI only
  • components/work/* - Work Router UI only
  • lib/data/* - Data persistence only
  • lib/work/* - Router logic only

No Changes to:

  • Existing routes (/home, /inbox, /founder, /sales, etc.)
  • Existing components or navigation
  • Existing API endpoints
  • Existing database schema or migrations

Behavior:

  • Work Router is opt-in - existing UI untouched
  • First-time users with onboardedAt = null redirected to onboarding
  • After onboarding, users can visit /work voluntarily
  • Existing authenticated users unaffected

Development & Testing

Running the App

cd /vercel/share/v0-project/apps/web
npm run dev

Demo Flow

  1. Visit /onboarding - Step through the 5-step form
  2. Complete onboarding - Persists UserProfile to InMemoryDataProvider
  3. Redirects to /work - Resolves and renders workspace
  4. View all 10 role views by changing profile data
  5. Use admin preview mode to test any role/dept/industry combo

Using Admin Preview Mode


// Create preview profile (not persisted)
const previewProfile = await createAdminPreviewProfile(
  {
    role: "founder",
    department: "engineering",
    industry: "healthcare",
    adminUserId: "admin-user-123",
  },
  "tenant-123"
);

// Use preview profile in resolveWorkView()

Data Models

UserProfile

{
  id: string;
  userId: string;
  tenantId: string;
  name: string;
  email: string;
  role: Role; // Set at onboarding
  department: Department; // Set at onboarding
  industry: Industry; // Set at onboarding
  onboardedAt: string;
  createdAt: string;
  updatedAt: string;
}

WorkContext

{
  profile: UserProfile;
  permissions: Permission[];
  installedPlugins: string[];
  availableCapabilities: Capability[];
  environment: Environment;
}

ResolvedWorkView

{
  role: Role;
  title: string;
  description: string;
  sections: WorkSection[];
  capabilities: Capability[];
  environmentBadge: { label: string; variant: string };
}

Future Enhancements

  1. Drizzle ORM Integration

    • Add DrizzleDataProvider implementation
    • Create migrations for all schema tables
    • Replace InMemoryDataProvider in production
  2. Department-based Filtering

    • Extend router to filter/reorder sections by department
    • Add department-specific KPI overrides
  3. Permissions Engine

    • Wire in role_permissions table
    • Extend router to check granular permissions
    • Hide/disable actions based on permissions
  4. Capability UI Integration

    • Add capability rail in Work view
    • Allow users to invoke capabilities inline
    • Show capability status and errors
  5. Real Section Implementations

    • Replace placeholder components with actual sections
    • Wire to existing dashboard templates
    • Add drill-down navigation
  6. Settings & User Preferences

    • Allow users to change role/dept/industry (with permissions)
    • Save workspace preferences
    • Customize section visibility
  7. Audit & Activity Logging

    • Log all profile changes
    • Track workspace access
    • Show activity feed in settings

File Manifest

lib/data/
├── types.ts                    (257 lines) - Domain types and repo interfaces
├── in-memory-provider.ts       (564 lines) - In-memory DataProvider + seed data
└── index.ts                    (34 lines)  - Factory function

lib/work/
├── router.ts                   (530 lines) - 10 role view definitions + resolveWorkView
├── industry-presets.ts         (131 lines) - SaaS/Healthcare/Fintech/Other presets
└── admin-preview.ts            (100 lines) - Admin preview mode

components/onboarding/
├── layout.tsx                  (120 lines) - Onboarding page container
├── steps.tsx                   (293 lines) - 5 step components
└── onboarding-container.tsx    (189 lines) - Form state management

components/work/
└── work-view-scaffold.tsx      (117 lines) - Shared work view layout

app/
├── onboarding/page.tsx         (30 lines)  - Route entry point
└── work/page.tsx               (167 lines) - Work router entry point

Total: ~2,550 lines of TypeScript/React

Testing Checklist

  • Data persistence (create/read/update profiles)
  • Onboarding flow (all 5 steps)
  • Form validation (required fields)
  • Work view resolution (all 10 roles)
  • Section filtering by permissions
  • Environment badge display
  • Admin preview mode logic
  • Industry preset vocabulary mapping
  • Responsive design (mobile, tablet, desktop)
  • Descope auth integration (pending)
  • Real section implementations (pending)
  • End-to-end user flow (pending Descope)

Next Steps

  1. Verify Descope Integration - Replace mock auth with real Descope calls
  2. Start Preview Mode - Access /onboarding to test the flow
  3. Build Real Sections - Implement individual section components
  4. Connect Platform API - Wire capabilities/agents from platform registry
  5. Add Drizzle - Swap InMemoryDataProvider for DrizzleDataProvider
  6. Deploy & Monitor - Deploy to staging, gather feedback