This document provides an overview of the technical architecture, database schema, and synchronization patterns used in the WorkGuru Dashboard.
The system is built with Next.js 15+ (App Router) and Drizzle ORM, communicating with a PostgreSQL database.
- Frontend: Tailwind CSS 4 + Shadcn UI (Manual integration for stability).
- Backend: Next.js Server Actions for data mutations and sync orchestration.
- Sync Layer: A modular service that pulls data from the WorkGuru API (v1) and performs ID-based upserts.
- Security: AES-256-CBC encryption for sensitive API keys stored in the database.
The schema is defined in src/db/schema.ts.
clients: Maps to WorkGuru Clients.projects: Primary entity, including budget/actual hours and delivery risk fields.tasks: Project-specific tasks for granular labor tracking.timeEntries: Individual labor entries.displayStages: Dynamic humand-friendly stages (Engineering, Production, etc.).stageMappings: Link raw WorkGuru statuses todisplayStages.
Projectbelongs toClient.Projecthas manyTasksandTimeEntries.TimeEntrybelongs toProjectand (optionally)Task.
The SyncService (src/lib/sync.ts) handles the integration:
- ID-Based Upsert: Every record uses
workguruIdas a unique constraint to prevent duplicates. - Incremental Logic: Designed to pull data updated since the last sync (currently set to full fetch for initial seeding).
- Validation: Every sync event is logged in
sync_logsfor auditability.
- Define the table in
src/db/schema.ts. - Run
npx drizzle-kit push(viacmd /con this environment) to update the database. - Update
src/db/index.tsif adding complex relations.
Update src/lib/risk.ts. Current risk is calculated based on:
Utilization = Remaining Hours / (Remaining Business Days * Capacity)
The dashboard uses custom-styled components in src/app/page.tsx for visual excellence. For new components, follow the Slate + Shadcn design tokens.
Version: 1.0.0 Lead AI Architect: Antigravity