How pdovhomilja/nextcrm-app works
Purpose and Entry Points
NextCRM is a self-hostable, full-stack CRM platform covering sales records, campaigns, projects, documents, email, invoicing, reporting, AI enrichment/search, and AI-agent access. It is a Next.js 16/React 19 App Router application with locale-prefixed UI routes. Primary entry points are app/[locale]/layout.tsx, app/[locale]/(routes)/page.tsx, API route handlers under app/api, and the background-function endpoint app/api/inngest/route.ts.
Application and Domain Boundary
The UI is organized by feature-oriented route groups; pages invoke server-side action modules rather than a separate internal REST layer for most mutations. actions/ is the principal application-service boundary, pairing domain reads/writes with authorization and validation patterns. The largest domain is CRM: accounts, contacts, leads, opportunities, contracts, products, targets, activities, and audit history.
• app/[locale]/(routes)/crm/page.tsx
• actions/crm/accounts/create-account.ts
• actions/crm/activities/create-activity.ts
Persistence, Authorization, and Auditability
PostgreSQL is accessed through Prisma, with schema migrations defining the durable model. pgvector supports embeddings and semantic similarity. Better Auth provides sessions and identity; centralized authorization scopes/roles gate actions and routes. CRM records use soft deletion and maintain a structured audit trail, separating operational data access from authorization/audit cross-cutting concerns.
• prisma/schema.prisma
• lib/prisma.ts
• lib/authz/index.ts
• lib/audit-log.ts
CRM Workflow and Semantic Search
CRM entities are edited through actions, rendered in entity/detail pages, and can be linked through activities, tasks, documents, products, or sales line items. Record changes can trigger embedding jobs; unified search combines conventional full-text results with pgvector semantic results, while similarity actions query related entities.
• actions/fulltext/unified-search.ts
• actions/crm/similarity/get-similar-accounts.ts
• inngest/functions/embed-account.ts
Campaigns and AI Enrichment
Campaigns model templates, recipients/target lists, scheduling, send-now, follow-up, delivery webhooks, and unsubscribe handling. Enrichment for contacts and targets is initiated through API routes/actions, dispatched to Inngest, then executed by an E2B sandboxed, browser-capable agent architecture; results are filtered/applied back to CRM records. It integrates Anthropic/OpenAI-style model access and supports encrypted, tiered API keys.
• inngest/functions/campaigns/send-step.ts
• app/api/campaigns/webhooks/resend/route.ts
• inngest/functions/enrich-target.ts
• lib/enrichment/agent-architecture/orchestrator.ts
Operational Modules
Documents use S3-compatible object storage with presigned uploads and asynchronous enrichment/thumbnail processing. The email module supports account synchronization and CRM linking through background jobs. Invoices implement lifecycle transitions, taxes, line items, payments, PDF rendering, and Resend-based delivery. Reports aggregate domain data and can export or run on schedules.
• app/api/upload/presigned-url/route.ts
• inngest/functions/emails/sync-account.ts
• actions/invoices/issue-invoice.ts
• lib/invoices/pdf/render.tsx
• actions/reports/schedule.ts
External API and Deployment Surface
The public API surface includes auth, integrations/webhooks, PDF/export/upload routes, and an MCP server exposing CRM, campaigns, projects, documents, and reports to AI clients using bearer API tokens. Runtime infrastructure comprises Next.js, PostgreSQL 17+ with pgvector, Inngest, MinIO/S3-compatible storage, and optional Resend, IMAP/SMTP, OpenAI, Anthropic, E2B, and Google OAuth. Docker Compose packages the app and core local services; the container entrypoint applies migrations.
• app/api/mcp/[transport]/route.ts
• lib/mcp/tools/index.ts
• docker-compose.yml
• docker-entrypoint.sh
Main entry points: create-account.ts Application actions · send-step.ts Background workflows · schema.prisma PostgreSQL + pgvector · prisma.ts Prisma data access
Components 21
NextCRM application
Next.js UI, application services, and public endpoints.
- Locale UI routes · Feature pages render CRM and operational modules.
app/[locale]/(routes)/crm/page.tsx - Locale layout
app/[locale]/layout.tsx - Application actions · Primary mutation and domain-service boundary.
actions/crm/accounts/create-account.ts - CRM activities · Links records, tasks, documents, and sales work.
actions/crm/activities/create-activity.ts - Public API routes · Serves integrations, uploads, exports, and webhooks.
app/api/upload/presigned-url/route.ts - MCP server · Bearer-token access to CRM and operational tools.
app/api/mcp/[transport]/route.ts - MCP tools
lib/mcp/tools/index.ts - Unified search · Combines full-text and semantic results.
actions/fulltext/unified-search.ts - Entity similarity
actions/crm/similarity/get-similar-accounts.ts - Campaign delivery webhook · Captures delivery events and unsubscribe handling.
app/api/campaigns/webhooks/resend/route.ts - Invoices and reports · Issues invoices, renders PDFs, and schedules reports.
actions/invoices/issue-invoice.ts
Data and governance
Durable CRM data, access control, and auditability.
- Authorization scopes · Roles and scopes gate routes and actions.
lib/authz/index.ts - Audit trail · Tracks structured CRM record changes.
lib/audit-log.ts - Prisma data access · Persists soft-deleted CRM and operational records.
lib/prisma.ts - PostgreSQL + pgvector · Durable schema, full-text data, and embeddings.
prisma/schema.prisma
Background workflows
Inngest-driven automation and AI processing.
- Inngest endpoint · Registers and receives workflow events.
app/api/inngest/route.ts - Background workflows · Runs campaign sends, email sync, embedding, and enrichment.
inngest/functions/campaigns/send-step.ts - Enrichment agent · Researches targets and applies filtered CRM updates.
lib/enrichment/agent-architecture/orchestrator.ts
External services
Storage, delivery, AI, and client integrations.
- S3-compatible storage · Stores documents and generated artifacts.
- Delivery and AI providers · Resend, mail servers, model APIs, and E2B support workflows.
- Container deployment · Starts core services; entrypoint applies migrations.
docker-compose.yml
Connections 22
- Locale layout → Locale UI routes: wraps locale pages
- Locale UI routes → Application actions: invokes
- Application actions → CRM activities: coordinates CRM work
- Application actions → Authorization scopes: authorizes
- Application actions → Prisma data access: reads and writes
- Application actions → Audit trail: records changes
- Prisma data access → PostgreSQL + pgvector: persists
- Unified search → PostgreSQL + pgvector: full-text + vector query
- Entity similarity → PostgreSQL + pgvector: vector similarity
- Application actions → Inngest endpoint: dispatches events
- Inngest endpoint → Background workflows: runs
- Background workflows → Enrichment agent: executes research
- Enrichment agent → Delivery and AI providers: uses models and E2B
- Background workflows → Prisma data access: applies results and embeddings
- Public API routes → S3-compatible storage: presigned uploads
- Campaign delivery webhook → Background workflows: delivery events
- Background workflows → Delivery and AI providers: campaign and email delivery
- MCP server → MCP tools: exposes
- MCP tools → Application actions: invokes domain operations
- Invoices and reports → Delivery and AI providers: sends invoice delivery
- Container deployment → PostgreSQL + pgvector: runs core database
- Container deployment → Inngest endpoint: hosts application