Next.js frontend for PartnerLedger OS. This app connects to the NestJS backend and provides login, dashboard analytics, transaction entry, settlement visibility, and realtime updates through Socket.IO.
- Next.js 16 App Router
- TypeScript
- Tailwind CSS
- shadcn/ui
- TanStack Query
- Recharts
- Socket.IO client
/login/dashboard/sales/expenses/settlements
Copy .env.example to .env.local and update the backend URLs:
cp .env.example .env.localRequired variables:
NEXT_PUBLIC_API_BASE_URL=http://localhost:4000/api/v1NEXT_PUBLIC_WS_URL=http://localhost:4000/realtime
npm install
npm run devFrontend runs on http://localhost:3000.
npm run build- Users log in from
/login - Access and refresh tokens are stored in
localStorage - Protected pages redirect to
/loginwhen no session is present - API requests attach the JWT automatically
The client listens for backend events and refreshes cached queries automatically:
dashboard.updatesettlement.updatedalert.triggered
lib/api.tsfor backend communicationlib/auth.tsfor browser session storagecomponents/providers/app-providers.tsxfor TanStack Query and toastscomponents/providers/realtime-sync.tsxfor Socket.IO syncingcomponents/layout/app-shell.tsxfor shared authenticated layout
- The UI assumes the backend is already running with the PartnerLedger APIs available.
- Current auth persistence is browser-based and suitable for the requested demo flow; cookie-based auth can be added later if needed.
Backend foundation for PartnerLedger OS using NestJS, Prisma, PostgreSQL (Supabase), and Socket.IO.
This step establishes:
- NestJS application bootstrap
- Clean architecture folder layout
- Prisma schema for the core finance domain
- Config validation for Supabase and JWT settings
- Event bus and engine skeletons
- WebSocket gateway foundation for live updates
- Working auth module with JWT and refresh token rotation
- Working partner module with ownership validation and wallet initialization
- Working sales module with validated revenue capture and
sale.createdevents - Working expenses module with validated spend capture and
expense.createdevents - Working engine layer for wallet updates, live settlements, insights, alerts, and websocket broadcasts
- Working read APIs for dashboard aggregation and settlement suggestions
- Copy
.env.exampleto.env. - Replace the Supabase connection strings and JWT secrets.
- Install dependencies:
npm install- Generate the Prisma client:
npm run prisma:generate- Run the backend in development mode:
npm run start:devsrc/modules: feature modules such as auth, sales, expense, settlement, and dashboardsrc/core/engines: domain logic engines for wallet, settlements, insights, and alertssrc/core/events: event names and the event bus abstractionsrc/gateway: Socket.IO gateway and event-to-websocket bridgesrc/prisma: Prisma service and moduleprisma/schema.prisma: database models and indexesdocs/architecture.md: backend design notes
POST /api/v1/auth/registerPOST /api/v1/auth/loginPOST /api/v1/auth/refreshPOST /api/v1/partnersGET /api/v1/partnersPOST /api/v1/salesGET /api/v1/salesPOST /api/v1/expensesGET /api/v1/expensesGET /api/v1/dashboardGET /api/v1/settlements
- Only
ADMINusers can create partners. - Partner creation automatically provisions a wallet with zero balances.
- Total ownership across partners cannot exceed
100%.
- Only
ADMINandPARTNERusers can create sales. - Sales validate the receiving partner before persistence.
- Sales do not update wallets directly; they emit
sale.createdfor downstream engines.
- Only
ADMINandPARTNERusers can create expenses. - Expenses validate the paying partner before persistence.
- Expenses do not update wallets directly; they emit
expense.createdfor downstream engines.
sale.createdandexpense.createdtrigger theWalletEngine.WalletEngineupdates balances atomically and emitswallet.updated.SettlementEnginerecalculates the live settlement batch from the latest wallet state.InsightEnginestores lightweight business signals such as expense spikes and profit drops.AlertEnginestores operational alerts such as loss days, overspending, no-sales days, and imbalance warnings.- Websocket broadcasts publish
transaction.created,dashboard.update,settlement.updated,insight.generated, andalert.triggered.
GET /api/v1/dashboardreturns totals, partner balances, and recent sales/expenses.GET /api/v1/settlementsreturns the current live settlement suggestions asfrom -> to -> amount.- Both routes require JWT authentication and allow
ADMINandPARTNER.
- Use the pooled connection string in
DATABASE_URLfor the running API. - Use the direct connection string in
DIRECT_URLfor Prisma migrations. - The schema already targets PostgreSQL and uses Prisma relations and indexes suitable for Supabase-hosted Postgres.