How premwizard/crm works
Purpose and deployment shape
IC CRM is a multi-tenant sales CRM for companies, contacts, leads, deals, tasks, activities, notes, tags, segments, and reporting. It has two independently runnable TypeScript services: a Next.js 15 App Router application and API surface, plus a standalone Express API server. Both target PostgreSQL through Prisma. Core entry points are frontend/src/app/page.tsx, frontend/src/app/layout.tsx, and backend/src/app.ts.
Web workspace and navigation
The Next.js application provides authentication pages and an authenticated dashboard workspace. Dashboard layout, header/sidebar navigation, and client-side providers form the UI boundary around CRM pages. Key paths: frontend/src/app/(dashboard)/layout.tsx, frontend/src/components/layout/header.tsx, frontend/src/components/providers/auth-provider.tsx.
API boundary: parallel implementations
The repository exposes REST resources under /api/v1 through Next.js route handlers, while Express implements a corresponding route-oriented API. Consumers should select/configure one API host deliberately; these are parallel server surfaces rather than a single layered request path. Representative paths: frontend/src/app/api/v1/companies/route.ts, frontend/src/app/api/v1/leads/[id]/convert/route.ts, backend/src/routes/companies.ts.
Identity, tenancy, and authorization
JWT authentication and bcrypt password handling protect application/API access. The frontend uses route middleware and auth utilities; Express enforces auth through middleware before protected routes. The schema defines users, organizations, and memberships, establishing the tenant boundary that business queries must preserve. Paths: frontend/src/middleware.ts, frontend/src/lib/auth.ts, backend/src/middleware/auth.ts.
CRM entity lifecycle
Companies, contacts, leads, and deals are the principal sales records. Lead conversion is a critical transactional workflow: eligible leads create or associate Company and Contact records, create a Deal, record conversion relations, and prevent invalid reconversion. Deal updates support pipeline stages, weighted forecasting, stage history, and activity logging. Paths: frontend/src/app/api/v1/leads/[id]/convert/route.ts, frontend/src/components/leads/lead-convert-modal.tsx, frontend/src/components/deals/deal-kanban-board.tsx.
Cross-cutting engagement records
Tasks, activities, notes, and tags attach to primary CRM entities, making detail views aggregation points rather than isolated resource screens. Timeline, task, note, and tag components call entity-filtered APIs and present shared operational context. Paths: frontend/src/components/timeline/activity-timeline.tsx, frontend/src/components/tasks/entity-tasks.tsx, frontend/src/components/notes/entity-notes.tsx.
Data operations and analytics
List endpoints support server-side pagination, sorting, filters, bulk actions, CSV import/export, global search, saved segments, dashboards, forecasts, and report generation. These operations should remain server-side against Prisma/PostgreSQL rather than loading full datasets into the browser. Paths: frontend/src/app/api/v1/search/route.ts, frontend/src/app/api/v1/import/execute/route.ts, frontend/src/app/api/v1/reports/generate/route.ts.
Persistence and runtime infrastructure
PostgreSQL 16 is the only stated external datastore; Prisma is the persistence boundary and schema authority, with separate schema copies per service. Next.js runs the React UI and serverless-style route handlers; Node.js/Express runs separately, with CORS configured. Paths: frontend/prisma/schema.prisma, frontend/src/lib/db.ts, backend/prisma/schema.prisma.
Main entry points: route.ts Next REST API · layout.tsx Dashboard Workspace · companies.ts Express CRM Routes · db.ts Frontend Prisma
Components 18
Next.js Web App
React workspace and parallel API handlers.
- Next.js App Router · Renders public and authenticated CRM application pages.
frontend/src/app/page.tsx - Dashboard Workspace · Layout, navigation, and auth provider surround CRM pages.
frontend/src/app/(dashboard)/layout.tsx - Web Auth Guard · Protects routes using frontend authentication utilities.
frontend/src/middleware.ts - Next REST API · Parallel /api/v1 server surface.
frontend/src/app/api/v1/companies/route.ts - Lead Conversion UI · Initiates transactional lead conversion.
frontend/src/components/leads/lead-convert-modal.tsx - Deal Pipeline UI · Presents deal stages and forecasting workflow.
frontend/src/components/deals/deal-kanban-board.tsx - Engagement Detail UI · Shows activities, tasks, notes, and tags for CRM records.
frontend/src/components/timeline/activity-timeline.tsx - Data Operations & Analytics · Search, bulk work, CSV, segments, dashboards, forecasts, and reports.
frontend/src/app/api/v1/reports/generate/route.ts
Express API
Independently runnable Node.js API.
- Express Server · Separate CORS-enabled REST API host.
backend/src/app.ts - Express Auth Middleware · Authenticates protected Express routes.
backend/src/middleware/auth.ts - Express CRM Routes · Corresponding route-oriented API resources.
backend/src/routes/companies.ts
Persistence
Separate Prisma schema authority for each runtime.
- Frontend Prisma · Prisma client and schema for Next.js handlers.
frontend/src/lib/db.ts - Frontend Schema · Frontend runtime schema authority.
frontend/prisma/schema.prisma - Backend Schema · Express runtime schema authority.
backend/prisma/schema.prisma - PostgreSQL 16 · Only stated external datastore.
Other components
- Identity & Tenancy · Users, organizations, and memberships scope tenant access.
- Sales Lifecycle · Companies, contacts, leads, deals, conversion, stages, and forecasts.
frontend/src/app/api/v1/leads/[id]/convert/route.ts - Engagement Records · Tasks, activities, notes, and tags attach to primary entities.
frontend/src/components/tasks/entity-tasks.tsx
Connections 23
- Next.js App Router → Dashboard Workspace: renders authenticated workspace
- Web Auth Guard → Dashboard Workspace: protects
- Dashboard Workspace → Lead Conversion UI: hosts
- Dashboard Workspace → Deal Pipeline UI: hosts
- Dashboard Workspace → Engagement Detail UI: hosts
- Lead Conversion UI → Next REST API: calls
- Deal Pipeline UI → Next REST API: calls
- Engagement Detail UI → Next REST API: queries filtered records
- Web Auth Guard → Next REST API: guards
- Next REST API → Identity & Tenancy: enforces tenant scope
- Next REST API → Sales Lifecycle: serves
- Next REST API → Engagement Records: serves
- Next REST API → Data Operations & Analytics: runs
- Sales Lifecycle → Engagement Records: logs deal activity
- Next REST API → Frontend Prisma: persists through
- Frontend Prisma → Frontend Schema: uses
- Frontend Prisma → PostgreSQL 16: queries
- Express Server → Express Auth Middleware: applies
- Express Auth Middleware → Express CRM Routes: authorizes
- Express CRM Routes → Identity & Tenancy: enforces tenant scope
- Express CRM Routes → PostgreSQL 16: persists via Prisma
- Backend Schema → PostgreSQL 16: models
- Next REST API → Express CRM Routes: parallel API surface; choose one host