PR 15 (docs): the numbered spec files mostly described the new model already at the conceptual level, but two needed concrete updates: - 07-DATABASE-SCHEMA.md: schema overview now lists the new Yacht / Company / Reservation domains alongside the existing ones, names the partial unique indexes (idx_yoh_active, idx_br_active) that enforce exclusivity, and notes that yacht/company details are no longer stored on `clients`. - CLAUDE.md: the Conventions section now points future contributors at the new schema files, the polymorphic ownership pattern, the EoiContext/dual-path EOI flow, and the merge-token allow-list. Adds a pointer to the husky `.env*` block so it doesn't trip people up. References the new field-mapping doc and `assets/README.md`. Task 15.3 (Tier 4 golden-image PDF regression) is deferred — those tests need committed reference PDFs that come out of a real, manually verified EOI render. Best landed once the actual `assets/eoi-template.pdf` is in place; tracking as a follow-up. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5.6 KiB
5.6 KiB
Port Nimara CRM
Multi-tenant CRM for marina/port management. Built with Next.js 15 App Router (standalone output), React 19, TypeScript (strict), Tailwind CSS 3, and Drizzle ORM on PostgreSQL.
Quick reference
pnpm dev # Start dev server
pnpm build # Production build
pnpm lint # ESLint
pnpm format # Prettier
pnpm db:generate # Generate Drizzle migrations
pnpm db:push # Push schema to DB
pnpm db:studio # Drizzle Studio GUI
pnpm db:seed # Seed database (tsx src/lib/db/seed.ts)
Tech stack
- Framework: Next.js 15.1 App Router,
output: 'standalone',experimental.typedRoutes - Auth: better-auth (session cookie:
pn-crm.session_token) - Database: PostgreSQL via
postgresdriver + Drizzle ORM - Queue: BullMQ + Redis (ioredis)
- Storage: MinIO (S3-compatible)
- Realtime: Socket.IO with Redis adapter
- UI: Radix UI primitives, shadcn/ui components (
src/components/ui/), Lucide icons, CVA + tailwind-merge + clsx - Forms: react-hook-form + zod resolvers
- Tables: TanStack Table
- State: Zustand stores (
src/stores/), TanStack React Query - PDF: pdfme
- Email: nodemailer + imapflow + mailparser
- AI: OpenAI SDK (optional)
- Testing: Vitest (unit), Playwright (e2e)
- Logging: pino + pino-pretty
Project structure
src/
app/
(auth)/ # Login/auth pages
(dashboard)/ # Main app - route: /[portSlug]/...
(portal)/ # Client portal
api/ # API routes
components/
ui/ # shadcn/ui base components
layout/ # Shell, sidebar, header
[domain]/ # Domain components (clients, invoices, berths, etc.)
shared/ # Cross-domain shared components
hooks/ # React hooks (use-auth, use-permissions, use-socket, etc.)
lib/
api/ # API client utilities
auth/ # better-auth config
db/
schema/ # Drizzle schema (one file per domain)
migrations/ # Generated Drizzle migrations
env.ts # Zod env validation (SKIP_ENV_VALIDATION=1 bypasses)
services/ # Business logic services
validators/ # Zod schemas for API input validation
utils/ # Shared utilities
middleware.ts # Auth middleware (cookie check, redirects)
providers/ # React context providers
stores/ # Zustand stores
types/ # Shared TypeScript types
Conventions
- TypeScript: Strict mode with
noUncheckedIndexedAccess. Noany(ESLint error). - Formatting: Prettier - single quotes, semicolons, trailing commas, 2-space indent, 100 char line width.
- Lint: ESLint flat config extending
next/core-web-vitals,next/typescript,prettier. Unused vars prefixed with_are allowed. - Imports: Use
@/*path alias (maps tosrc/*). - Components: shadcn/ui pattern - base components in
src/components/ui/, domain components insrc/components/[domain]/. Yacht / company / reservation domains live incomponents/yachts,components/companies,components/reservationsrespectively. - DB schema: One file per domain in
src/lib/db/schema/, re-exported fromindex.ts. Relations inrelations.ts. Domain files includeclients.ts,yachts.ts,companies.ts,reservations.ts,interests.ts,berths.ts,documents.ts,invoices.ts, etc. - Polymorphic ownership: Yachts and invoice billing-entities use
<entity>_type+<entity>_idcolumn pairs ('client' | 'company'). Resolve owner identity throughsrc/lib/services/yachts.service.ts/eoi-context.tsrather than reading the columns ad hoc — those services apply the type discriminator. - EOI generation: Two pathways share the same
EoiContext(src/lib/services/eoi-context.ts). Documenso pathway calls the template-generate endpoint viadocumenso-payload.ts; in-app pathway fills the same source PDF (assets/eoi-template.pdf) viasrc/lib/pdf/fill-eoi-form.ts(pdf-lib AcroForm). Routed throughgenerateAndSign(...)insrc/lib/services/document-templates.tswith apathwayparameter. - Merge fields: Token catalog lives in
src/lib/templates/merge-fields.ts; thecreateTemplateSchemavalidator usesVALID_MERGE_TOKENSas an allow-list, so unknown tokens are rejected at template creation time. - Routes: Multi-tenant via
[portSlug]dynamic segment. Typed routes enabled. - Pre-commit: Husky + lint-staged runs ESLint fix + Prettier on staged
.ts/.tsxfiles. The hook also blocks.env*files (including.env.example) from being committed; pass them via a separate workflow if needed.
Environment
Copy .env.example to .env for local dev. See src/lib/env.ts for the full schema. Set SKIP_ENV_VALIDATION=1 to bypass validation (used in Docker build).
Docker
Dockerfile- Production multi-stage build (deps -> build -> runner)Dockerfile.dev- Dev with bind-mounted sourceDockerfile.worker- BullMQ worker processdocker-compose.yml/docker-compose.dev.yml/docker-compose.prod.yml
Architecture docs
Numbered spec files in repo root (01-CONSOLIDATED-SYSTEM-SPEC.md through 15-DESIGN-TOKENS.md) contain detailed architecture decisions, feature specs, DB schema docs, API catalog, and implementation sequence.
Domain-specific references:
docs/eoi-documenso-field-mapping.md— canonical mapping fromEoiContextpaths to the Documenso template'sformValueskeys, with the matching AcroForm field names used by the in-app pathway.assets/README.md— what the in-app EOI source PDF must contain and how to override its path in dev/test.