How stavomidnite661/sovrfincmdctr works
1. Overall shape
- This repo is a monorepo-style financial operations app centered on a Next.js 16 web application, backed by Prisma + SQLite, plus a separate Bun-based message service for real-time queue activity.
- The main architectural boundary is between the dashboard/API app on port 3000 and the message-processing service on port 3030.
2. User-facing application
- src/app/page.tsx and the App Router layout form the primary dashboard UI.
- The app is built as a financial command center: it aggregates ledger state, message queues, settlement info, and operational KPIs into one control plane.
3. API layer inside Next.js
- Business logic is exposed through route handlers under src/app/api/*.
- The major API domains are:
- ledger/* for master reserve, internal accounts, transactions, settlements
- messages/* for payment message CRUD and stats
- transactions/* for transaction workflows
- dashboard/stats for top-level KPIs
- ai/insights for an AI-assisted analysis endpoint
- These endpoints are the main synchronous data access path for the UI.
4. Persistence layer
- src/lib/db.ts is the Prisma client entrypoint.
- The schema lives in prisma/schema.prisma, and the repo includes SQLite database files under db/, notably internal-ledger.db and custom.db.
- The persistence model centers on ledger entities such as master reserves, internal accounts, transactions, and hash-chained ledger entries.
5. Internal ledger subsystem
- The ledger is the core domain model: a master reserve account backs multiple internal accounts and their balances.
- Transaction records and immutable ledger entries provide an audit trail; the README emphasizes hash chaining and sequential entry integrity.
- This subsystem is likely the source of truth for balances, allocations, settlements, and internal “SCreds” accounting.
6. Message processing subsystem
- mini-services/message-service/index.ts is a separate service that handles payment message queueing and processing.
- It exposes both HTTP REST and Socket.IO interfaces, and the README describes events like message:create, message:queued, message:settled, and queue:stats.
- This service is the real-time boundary for message lifecycle events, separate from the main Next.js app.
7. Real-time client flow
- src/hooks/useMessageSocket.ts is the client-side bridge to the message service.
- The dashboard can subscribe to live queue and settlement updates via Socket.IO rather than polling the main API alone.
- That makes the message service the real-time event source, while the Next.js APIs provide the persisted view.
8. Gateway and routing
- Caddyfile acts as a reverse proxy gateway.
- The intended routing splits traffic between /api/* to the Next.js app and /socket.io/* to the message service.
- Architecturally, this creates a clean separation between browser-facing HTTP routes and the socket-based event channel.
9. UI and component boundaries
- src/components/ui/* is a large shadcn/ui-style component library used to assemble the dashboard.
- src/hooks/use-mobile.ts and src/hooks/use-toast.ts are supporting client hooks for responsiveness and notifications.
- These are presentation-layer concerns and should sit above the API/service boundaries in a diagram.
10. Auxiliary and demo code
- examples/websocket/* contains a standalone websocket demo, useful as a reference for the real-time pattern.
- download/ and upload/ appear to be supporting folders, likely for file-based workflows or assets, but they are not central to the main architecture.
- public/ holds static assets such as branding and robots.txt.
11. Operational tooling
- .zscripts/* contains build/start/install helpers for local and mini-service workflows.
- package.json, bun.lock, eslint.config.mjs, tailwind.config.ts, and next.config.ts define the app toolchain: TypeScript, Tailwind, ESLint, and Bun-compatible scripting.
- These are supporting infrastructure rather than runtime subsystems.
12. Primary data flows to diagram
- UI → Next.js API → Prisma → SQLite for ledger, dashboard, and message persistence.
- UI → Socket.IO → message service for live queue and settlement updates.
- Caddy → route splitting → Next.js / message service as the entry gateway.
- The repository is therefore best understood as a dashboard + API monolith with one event-driven sidecar service for real-time message processing.
Main entry points: page.tsx Dashboard · db.ts Prisma client · route.ts Ledger API · schema.prisma Schema
Components 21
Gateway
Entry routing and traffic split
- Caddyfile · Routes browser and socket traffic to the appropriate runtime
Caddyfile
Next.js App
Dashboard UI and synchronous API surface
- Dashboard · Main control-plane UI for balances, messages, settlements, and KPIs
src/app/page.tsx - App shell · Global app shell and shared page structure
src/app/layout.tsx - API root · Top-level API routing boundary for the web app
src/app/api/route.ts - Stats API · Top-level dashboard KPI endpoint
src/app/api/dashboard/stats/route.ts - Ledger API · Ledger domain endpoints for master reserve, accounts, transactions, and settlements
src/app/api/ledger/transactions/route.ts - Messages API · Message CRUD and message statistics endpoints
src/app/api/messages/route.ts - Tx API · Transaction workflow endpoint
src/app/api/transactions/route.ts - AI insights · AI-assisted analysis endpoint
src/app/api/ai/insights/route.ts
Ledger Domain
Core financial persistence model
- Prisma client · Shared database access entrypoint
src/lib/db.ts - Schema · Data model for ledger and message persistence
prisma/schema.prisma - SQLite DB · Local persisted datastore backing the ledger system
db/internal-ledger.db - Master reserve · Primary reserve account backing internal balances
prisma/schema.prisma - Internal accounts · Sub-ledger balances and allocations
prisma/schema.prisma - Ledger entries · Hash-chained immutable entries for integrity and sequencing
prisma/schema.prisma
Realtime Service
Sidecar message processor and socket event source
- Message service · Separate real-time service for queueing and settlement events
mini-services/message-service/index.ts - Socket.IO · Live event channel for queue and settlement updates
mini-services/message-service/index.ts - REST API · HTTP interface for message operations and stats
mini-services/message-service/index.ts
Presentation
Reusable client-side UI and hooks
- Socket hook · Browser bridge to the message service event stream
src/hooks/useMessageSocket.ts - UI library · Reusable dashboard component set
src/components/ui/button.tsx - Toasts · Notification and responsive UI helpers
src/hooks/use-toast.ts
Connections 27
- Caddyfile → Dashboard: routes / · Gateway sends browser UI traffic to the Next.js app
- Caddyfile → Message service: routes socket · Gateway sends socket traffic to the realtime service
- Dashboard → App shell: uses shell · Dashboard is rendered within the shared app shell
- Dashboard → Stats API: loads KPIs · Dashboard reads aggregated operational stats
- Dashboard → Ledger API: reads ledger · Dashboard requests balances, accounts, and settlement state
- Dashboard → Messages API: reads messages · Dashboard fetches message lifecycle data
- Dashboard → Socket hook: subscribes live · Dashboard receives realtime queue and settlement updates
- Dashboard → UI library: composes UI · Dashboard is assembled from shared presentation components
- Dashboard → Toasts: notifies · Client interactions surface feedback through toast helpers
- Stats API → Prisma client: queries · Stats endpoint reads persisted operational data
- Ledger API → Prisma client: queries · Ledger endpoints access the database through Prisma
- Messages API → Prisma client: queries · Message endpoints persist and fetch message state
- Tx API → Prisma client: mutates · Transaction workflow persists through Prisma
- AI insights → Prisma client: reads · AI insights endpoint uses persisted operational context
- Prisma client → Schema: uses model · Prisma client is generated from the schema
- Schema → Master reserve: defines · Schema models the master reserve account
- Schema → Internal accounts: defines · Schema models internal account balances
- Schema → Ledger entries: defines · Schema models immutable ledger entries
- Schema → SQLite DB: stores in · Schema persists to local SQLite databases
- Message service → Socket.IO: emits events · Realtime service broadcasts lifecycle updates over Socket.IO
- Message service → REST API: serves · Realtime service exposes HTTP endpoints for message operations
- Socket hook → Socket.IO: connects to · Client hook listens to live service events
- Messages API → Message service: syncs view · Persisted message APIs complement the realtime service state
- Ledger API → Master reserve: operates on · Ledger routes manage reserve and account state
- Ledger API → Internal accounts: operates on · Ledger routes manage reserve and account state
- Ledger API → Ledger entries: records · Ledger routes append auditable entries
- Tx API → Ledger entries: books · Transaction workflow produces ledger trail entries