How saashqdev/saashq works
Purpose and Runtime
SaasHQ is a Next.js 14/TypeScript CRM/ERP starter: a localized, authenticated business application covering CRM, projects, documents, invoices, reporting, AI assistance, and workflow automation. It runs as a single Next App Router service, deployable to Vercel or Docker.
• app/[locale]/layout.tsx
• app/[locale]/(routes)/layout.tsx
• middleware.tsx
Entry Points, Identity, and Tenancy Boundaries
Locale-prefixed App Router pages are the browser entry points; route groups separate authentication screens from protected application modules. Auth.js is exposed through a catch-all API handler. User activation, roles/admin features, enabled modules, and profile settings are managed through user/admin endpoints and UI.
• app/[locale]/(auth)/sign-in/page.tsx
• app/api/auth/[...nextauth]/route.ts
• lib/auth.ts
Persistence and Domain Model
Prisma is the central persistence boundary over PostgreSQL (documented as Tembo-hosted in the README). Its schema defines cross-module business entities and relations; seeded reference data initializes CRM types, GPT models, and enabled modules. Server-side actions/ primarily read domain data for rendered views, while app/api/ owns mutation/integration endpoints.
• prisma/schema.prisma
• lib/prisma.ts
• prisma/seeds/seed.ts
CRM and Operational Work Management
CRM manages accounts, contacts, leads, opportunities, and account tasks, with detail views connecting related records. Projects provide boards, sections, Kanban tasks, assignments, comments, documents, watches, and task completion. These are separate UI/API domains but both expose task-oriented operations and notifications.
• app/[locale]/(routes)/crm/page.tsx
• app/api/crm/opportunity/[opportunityId]/route.ts
• app/[locale]/(routes)/projects/boards/[boardId]/components/Kanban.tsx
Workflow Definition and Execution Engine
The workflow module supplies graph-oriented create/edit/detail screens with React Flow and Monaco-based task configuration. Definitions and runtime records are accessed through workflow APIs. A server-side engine abstracts transport, task dispatch, and processors for function, guard, and wait stages; dedicated engine routes start executions and receive/listen for events.
• app/[locale]/(routes)/workflows/components/ReactFlow.tsx
• lib/engine/engine.service.ts
• app/api/engine/start/route.ts
Documents, Invoices, and External Storage/Extraction
Documents and uploads cross from app APIs into UploadThing/S3-oriented storage integrations. Invoice workflows add Rossum token, embedded cockpit, and annotation endpoints for AI-assisted invoice parsing; XML/export and email-send endpoints support downstream invoice handling. File storage and invoice extraction are material external-service boundaries.
• app/api/uploadthing/core.ts
• lib/digital-ocean-s3.ts
• app/api/invoice/rossum/get-annotation/[annotationId]/route.ts
AI, Messaging, and Background-style Reporting
OpenAI endpoints power chat/completions and project/board AI reports; admin settings select GPT models. Resend plus React Email templates deliver invites, task comments, CRM/project task notifications, password resets, and AI reports. SMTP/IMAP support also exists for email features. Cron-oriented actions retrieve AI task work, implying scheduled invocation is external to this repo.
• app/api/openai/create-chat-completion/route.ts
• actions/ai/projects/boards/getAiReport.tsx
• lib/resend.ts
Delivery and Client Data Flow
UI pages compose server actions and client-side fetching/state mechanisms (SWR, Axios, React Query per README), calling same-origin route handlers for mutations. Shared providers establish theme/toast behavior; dictionaries and locale layouts support i18n. Docker, Vercel, and CI definitions are the deployment/automation boundaries.
• app/providers/ThemeProvider.tsx
• dictionaries.ts
• docker-compose.yml
Main entry points: prisma.ts Prisma data layer · layout.tsx Locale route layouts · route.ts Business APIs · auth.ts Auth service
Components 26
Browser UI
- Sign-in UI
app/[locale]/(auth)/sign-in/page.tsx - UI providers · Theme and toast behavior.
app/providers/ThemeProvider.tsx - CRM & projects UI · CRM records and project Kanban work management.
app/[locale]/(routes)/projects/boards/[boardId]/components/Kanban.tsx - Workflow designer · Graph definition and task configuration.
app/[locale]/(routes)/workflows/components/ReactFlow.tsx
Next.js Application
- Locale route layouts · Locale-prefixed public and protected page boundary.
app/[locale]/layout.tsx - Protected app routes · Hosts authenticated business modules.
app/[locale]/(routes)/layout.tsx - Request middleware
middleware.tsx - Dictionaries
dictionaries.ts - Auth.js handler
app/api/auth/[...nextauth]/route.ts - Auth service · Authentication, activation, roles, and user access.
lib/auth.ts - Business APIs · Mutation and integration endpoints for domain modules.
app/api/crm/opportunity/[opportunityId]/route.ts - Engine start API · Starts executions and receives engine events.
app/api/engine/start/route.ts - Workflow engine · Dispatches function, guard, and wait processors.
lib/engine/engine.service.ts - OpenAI API · Chat and completion requests.
app/api/openai/create-chat-completion/route.ts - AI board reports · Retrieves AI task work for report generation.
actions/ai/projects/boards/getAiReport.tsx - Upload API · UploadThing-oriented document ingress.
app/api/uploadthing/core.ts - Invoice extraction API · Retrieves Rossum annotations for invoice parsing.
app/api/invoice/rossum/get-annotation/[annotationId]/route.ts
Data & Integrations
- Prisma data layer · Central domain persistence access.
lib/prisma.ts - Business schema · Cross-module entities and relations.
prisma/schema.prisma - PostgreSQL · Tembo-hosted persistence target.
- Reference-data seed · Initializes CRM types, GPT models, and enabled modules.
prisma/seeds/seed.ts - Object storage · S3-compatible uploaded file storage.
lib/digital-ocean-s3.ts - Email delivery · Sends notifications, invites, resets, and AI reports.
lib/resend.ts - OpenAI
- Rossum · Invoice cockpit and annotation service.
Delivery
- Docker deployment
docker-compose.yml
Connections 22
- Request middleware → Locale route layouts: routes requests
- Locale route layouts → Dictionaries: loads locale text
- Locale route layouts → UI providers: renders with
- Sign-in UI → Auth.js handler: signs in through
- Auth.js handler → Auth service: uses
- Auth service → Prisma data layer: reads users and roles
- Protected app routes → Auth service: enforces access
- CRM & projects UI → Business APIs: mutations
- Business APIs → Prisma data layer: persists domain data
- Workflow designer → Business APIs: manages definitions
- Engine start API → Workflow engine: starts execution
- Workflow engine → Prisma data layer: reads definitions and runtime
- OpenAI API → OpenAI: completions
- AI board reports → OpenAI: generates reports
- AI board reports → Email delivery: sends reports
- Upload API → Object storage: stores files
- Invoice extraction API → Rossum: gets annotations
- Prisma data layer → Business schema: maps models
- Prisma data layer → PostgreSQL: queries
- Reference-data seed → PostgreSQL: initializes
- Business APIs → Email delivery: sends notifications
- Docker deployment → Locale route layouts: runs application