Files
test-assignment/README.md
T

8.4 KiB

MerchantFlow

A local Merchant Onboarding CRM for a fictional crypto-payment provider. This milestone provides real login, database-backed browsing, role-scoped views, and a responsive English/Russian UI. Editing and workflow actions are intentionally deferred.

Start locally

Prerequisites: Node 22.19+ on the 22.x line, pnpm 10.32.1, and Docker Desktop with its engine running. .nvmrc pins the verified Node version.

nvm use
corepack enable
corepack prepare [email protected] --activate
cp .env.example .env
pnpm install --frozen-lockfile
pnpm db:setup
pnpm dev

Open http://localhost:5173. The API runs at http://localhost:3001/api; Vite forwards /api to it without rewriting the path. Local localhost and 127.0.0.1 browser URLs are both accepted. Docker runs only PostgreSQL; the two applications run on the host.

Development PostgreSQL uses 55440, to avoid existing local databases. The isolated test service uses 55441. Both bind to loopback only. If a port is occupied, update the matching Compose mapping and database URL (the test URL lives in scripts/test-database.mjs). Frontend/API ports and the trusted browser origin can be changed in .env.

pnpm db:setup starts PostgreSQL, applies the checked-in migration, generates/builds database code, and seeds the fixtures. Seeding is repeatable: existing fixture IDs, passwords, records and history are preserved. pnpm db:down stops the project services but preserves development data.

Demo accounts

All four accounts use MerchantFlow123!. The login page has credential-fill buttons; sign-in still goes through the API.

Email Role Visibility
[email protected] Head of Sales All 18 merchants
[email protected] Compliance Officer 4 merchants currently in KYB or Compliance Review
[email protected] Account Manager · Alex Morgan 9 assigned merchants
[email protected] Account Manager · Maria Chen 9 assigned merchants

Only Compliance can open the Review Queue. Scope restrictions apply to every list, detail, task, history event and aggregate; knowing a hidden merchant ID does not grant access. The API returns 404 for hidden merchant details and 403 for forbidden queue access.

Workspace structure

apps/web              React + Vite + React Router
apps/api              NestJS REST API
packages/ui           shadcn/Base UI components, tokens and reusable states
packages/contracts    Zod schemas, DTOs, canonical role/status codes
packages/database     Prisma schema, generated client, migrations and seed
docs                  Product brief and implementation checklist
tests                 Playwright journeys

The browser depends on UI and contracts only. Database exports have a Node-only condition, and Vite fails the build if Prisma, database code or PostgreSQL drivers enter its module graph. Contracts never import Prisma types. An integration test checks that Prisma enums and contract codes agree.

The shared UI follows shadcn's monorepo conventions: matching base-nova configuration, neutral tokens, rsc: false, shared CSS, and package subpath exports. Components were installed using the pinned shadcn 4.21.0 CLI; imports use the shared @merchantflow/ui/lib/utils utility. Forms use React Hook Form and shared Zod schemas.

API, database and contracts compile to ESM. Turbo builds dependencies before dependent apps. pnpm dev first compiles the API, then starts dependency watchers, the API compiler/process watcher, and Vite. Run pnpm db:generate after a Prisma schema edit. Add migrations with Prisma during development; db:migrate only applies checked-in migrations.

Routes and API

Public routes are / and /login. CRM routes are /app, /app/merchants, /app/merchants/:id, /app/pipeline, /app/tasks and /app/review-queue. Browser history URLs support direct navigation and refresh through Vite.

Method Endpoint Purpose
GET /api/health Database-aware health; 503 if unavailable
POST /api/auth/login Email/password login
POST /api/auth/logout Revoke session and clear cookie
GET /api/auth/me Current public user
GET /api/dashboard Scoped counts, distribution, activity, priority tasks
GET /api/merchants?search=&status=&page=1 Search, canonical status filter, 8 records per page
GET /api/merchants/:id Overview, checklist, notes, tasks, history
GET /api/pipeline Scoped merchants grouped in the UI
GET /api/tasks?filter=ALL ALL / OPEN / OVERDUE / UPCOMING / DONE
GET /api/review-queue Compliance-only, oldest review first

Passwords are salted with scrypt. A random session token lives in an HttpOnly, SameSite=Lax cookie; only its SHA-256 digest is stored in PostgreSQL. Sessions expire after eight hours. Login/logout validate browser origins; local failed logins have a bounded rate limit. The UI clears private query caches on logout, login and API session rejection.

Data and localization

The successful path is New Lead → Contacted → Qualified → KYB → Compliance Review → Integration → Testing → Live. Rejected is a separate terminal outcome. Luma Labs demonstrates a historical return from Compliance Review to KYB for corrections.

The seed creates 18 merchants, 36 tasks, document checklists, notes and chronological history. Dates are relative to the first seed, then preserved. There are no fabricated trend percentages or payment metrics. The dashboard counts visible merchants, current review records, open overdue tasks, and non-initial status changes during the past 30 days. Its activity feed uses persisted events; counts naturally change as fixtures age.

English is the default; EN/RU selection persists in local storage, including across sign-out. Dates and numbers use Intl and the viewer's local timezone. Status, role, industry and document labels are translated from canonical codes. Names, task titles and user notes remain verbatim. Checklists and tasks are read-only; reminders are derived from stored dates and refresh inside the app, without background notification infrastructure.

Verification

pnpm build
pnpm lint
pnpm typecheck
pnpm test
pnpm test:integration
pnpm exec playwright install chromium
pnpm test:e2e
pnpm format:check

Unit tests cover contracts, translated resources, return URLs, scope rules and password verification. Integration tests use an isolated merchantflow_test database on a separate Compose service with temporary storage; they never truncate the development database. Browser tests start dedicated web/API instances on 5174/3002, then test EN/RU at 390px/1440px, permissions, navigation, filtering, direct refresh, focus restoration, reduced motion, and loading/error/empty states. Reports and screenshots are written to ignored playwright-report/ and test-results/ directories. Run integration and browser commands sequentially.

Health smoke check while pnpm dev is running:

curl --fail http://localhost:3001/api/health
curl --fail http://localhost:5173/api/health

Both should return {"status":"ok","database":"connected"}. If startup fails, check Docker, port availability and .env; do not point the tests at development data.

The product brief and implementation checklist record the accepted scope and verification results. Merchant editing, stage/review actions and task management are later milestones. Uploads, merchant self-service, payments, external KYB/reminders and deployment remain out of scope.