How kavinraj7305/workflowguard works
Purpose and runtime
WorkFlowGuard is a Next.js 16 employee productivity, retention, HR, and work-management system. It runs on Node.js 20+ with Postgres (intended for Neon) through Drizzle ORM. The main HTTP application is the App Router under src/app/; database access and relational model are centralized in src/db/index.ts and src/db/schema.ts.
Application entry points and audiences
The root application routes direct users into setup, login, or role-oriented experiences: src/app/setup/page.tsx, src/app/login/page.tsx, and src/app/page.tsx. HR/manager functions live in the admin console rooted by src/app/admin/layout.tsx and src/app/admin/page.tsx. Individual developers work in assignment-scoped workspaces rooted at src/app/workspace/[assignmentId]/layout.tsx and src/app/workspace/[assignmentId]/page.tsx.
Identity, sessions, and authorization
Authentication is API-driven: login/logout/current-user endpoints are at src/app/api/auth/login/route.ts, src/app/api/auth/logout/route.ts, and src/app/api/auth/me/route.ts. Session and password handling are separated in src/lib/auth/session.ts and src/lib/auth/password.ts; route-level protection is enforced by src/middleware.ts. Authorization boundaries additionally include assignment/workflow access logic in src/lib/workflow-access.ts, separating employee workspace access from administrative operations.
Organizational and workforce management
Organizations, users, HR profiles, leave, and payroll form the personnel domain exposed through route handlers such as src/app/api/orgs/route.ts, src/app/api/users/route.ts, and src/app/api/hrm/profiles/route.ts. Admin UI modules consolidate operational views, including src/app/admin/hrm/page.tsx, src/app/admin/payroll/page.tsx, and src/app/admin/orgs/page.tsx. Optional Resend-backed credentials notifications flow through src/lib/notify/credentials-email.ts; account creation remains functional when email is not configured.
Work assignment, tickets, and activity capture
Tickets are the primary work-unit API, with collection and per-ticket mutation boundaries at src/app/api/tickets/route.ts and src/app/api/tickets/[ticketId]/route.ts. Specialized actions—assignment, status transitions, activity, and screenshots—are separated into handlers under src/app/api/tickets/[ticketId]/. The developer workspace coordinates task actions, timer/activity tracking, and extension enrollment through src/components/workspace/TaskActions.tsx, src/components/workspace/PomodoroTimer.tsx, and src/components/workspace/WorkspaceActivityTracker.tsx.
Browser extension integration
A standalone Chrome extension captures tab activity from browser-extension/background.js and is configured by browser-extension/manifest.json. It authenticates using an extension-specific token issued by src/app/api/auth/extension-token/route.ts, rather than browser session credentials. Client activity resolution is abstracted behind src/lib/api/resolve-activity-client.ts, preserving the boundary between extension events and application domain handling.
Analytics, reporting, and AI
Database-derived productivity, retention, ticket, mood, and daily-report calculations are encapsulated in src/lib/ticket-analytics.ts, src/lib/analytics/mood.ts, and src/lib/reports/daily.ts. They feed explicit APIs including src/app/api/analytics/my-productivity/route.ts, src/app/api/analytics/org-retention/route.ts, and src/app/api/reports/daily/route.ts, consumed by the corresponding workspace and admin dashboards. The admin assistant endpoint at src/app/api/admin/ai/chat/route.ts invokes constrained admin tools from src/lib/admin/ai-tools.ts through an OpenAI-compatible provider adapter in src/lib/llm/openai-compatible.ts.
Persistence and lifecycle
Drizzle schema definitions are versioned by drizzle/ SQL migrations and managed through drizzle.config.ts; operational scripts include scripts/apply-schema.ts and scripts/seed.ts. First-run onboarding is deliberately limited to an empty user database through src/app/api/setup/route.ts, establishing the initial organization and HR authority before normal authenticated workflows begin.
Main entry points: index.ts Drizzle data layer · layout.tsx Admin console · route.ts Tickets API · page.tsx Entry routes
Components 21
Next.js application
- Entry routes · Routes users to setup, login, and role-specific experiences.
src/app/page.tsx - Admin console · HR, payroll, organization, and management dashboards.
src/app/admin/layout.tsx - Personnel APIs · Organization, user, and HR-profile operations.
src/app/api/users/route.ts
Identity & access
- Auth API · Login, logout, and current-user endpoints.
src/app/api/auth/login/route.ts - Sessions & passwords
src/lib/auth/session.ts - Route protection
src/middleware.ts - Workflow access · Separates assignment access from administrative operations.
src/lib/workflow-access.ts - First-run setup · Creates the initial organization and HR authority only on an empty user database.
src/app/api/setup/route.ts
Work management
- Developer workspace · Assignment-scoped task execution and activity tracking.
src/app/workspace/[assignmentId]/page.tsx - Workspace activity · Task actions, Pomodoro timer, and activity tracker.
src/components/workspace/WorkspaceActivityTracker.tsx - Tickets API · Ticket collection, mutation, assignment, status, activity, and screenshots.
src/app/api/tickets/route.ts
Data & insights
- Analytics & reports · Productivity, retention, mood, ticket, and daily-report calculations.
src/lib/ticket-analytics.ts - Analytics APIs · Serves individual productivity, organization retention, and daily reports.
src/app/api/analytics/my-productivity/route.ts - Admin AI assistant · Constrained assistant endpoint for administrators.
src/app/api/admin/ai/chat/route.ts - Admin AI tools · Constrained administrative operations exposed to the assistant.
src/lib/admin/ai-tools.ts - LLM provider adapter
src/lib/llm/openai-compatible.ts - Drizzle data layer · Centralized Postgres access and relational model.
src/db/index.ts - Schema lifecycle · Versioned SQL migrations, schema application, and seed operations.
Browser extension
- Extension token API · Issues extension-specific tokens instead of browser sessions.
src/app/api/auth/extension-token/route.ts - Chrome activity capture · Captures tab activity and sends authenticated events.
browser-extension/background.js - Activity resolver · Boundary between extension events and application domain handling.
src/lib/api/resolve-activity-client.ts
Connections 25
- Entry routes → Admin console: administrators
- Entry routes → Developer workspace: employees
- Entry routes → First-run setup: first run
- Route protection → Auth API: checks session
- Auth API → Sessions & passwords: creates and validates
- Auth API → Drizzle data layer: accounts
- First-run setup → Drizzle data layer: initial authority
- Admin console → Personnel APIs: manages workforce
- Personnel APIs → Drizzle data layer: organizations and people
- Developer workspace → Workspace activity: coordinates
- Workspace activity → Tickets API: task and activity actions
- Tickets API → Workflow access: authorizes
- Tickets API → Drizzle data layer: tickets and activity
- Chrome activity capture → Extension token API: obtains token
- Chrome activity capture → Activity resolver: tab events
- Activity resolver → Tickets API: resolved activity
- Developer workspace → Analytics APIs: personal metrics
- Admin console → Analytics APIs: organization reporting
- Analytics APIs → Analytics & reports: calculates
- Analytics & reports → Drizzle data layer: derives from
- Admin console → Admin AI assistant: assistant requests
- Admin AI assistant → Admin AI tools: constrained tools
- Admin AI assistant → LLM provider adapter: model calls
- Admin AI tools → Drizzle data layer: admin data
- Schema lifecycle → Drizzle data layer: evolves schema