How palmiery/nexbank works
1. Overall shape
- NexBank is a small Next.js 14 App Router application written in TypeScript.
- It combines a web UI and a set of HTTP API routes in the same codebase and runtime.
2. Primary architectural layers
- The repo is organized into three clear layers:
- Presentation layer: src/app/page.tsx, layout.tsx, globals.css
- API layer: src/app/api/**/route.ts
- Domain/data layer: src/lib/business/* and src/lib/data/*
3. UI boundary
- src/app/page.tsx is the main browser-facing interface.
- Styling is handled with Tailwind CSS via the global app styles and config files.
- The UI is a client entry point into the banking operations, but the actual business logic lives below it.
4. API boundary
- All backend functionality is exposed through Next.js route handlers under src/app/api.
- The API surface includes:
- POST /api/accounts and GET /api/accounts
- GET /api/accounts/:id/balance
- POST /api/accounts/:id/transaction
- POST /api/transfer
- POST /api/accounts/render-juros
- These handlers act as the HTTP-to-domain translation layer.
5. Business logic subsystem
- src/lib/business/bankingService.ts is the core service layer.
- It centralizes the banking rules for the operations described in the README: account creation, balance lookup, credit/debit transactions, transfer, and the interest-related render-juros action.
- This is the main place where domain behavior is expected to live, separate from HTTP concerns.
6. Domain model
- src/lib/business/types.ts defines the banking types shared across layers.
- This file is the contract between API handlers, business logic, and the repository, helping keep the account and transaction model consistent.
7. Data persistence boundary
- src/lib/data/accountRepository.ts is the storage layer.
- The README states there is no database; account data is held in memory during the process/session.
- This means persistence is temporary, and a restart clears all stored state.
8. Request flow
- A typical call path is:
- browser UI or external client
- Next.js API route handler
- banking service
- in-memory account repository
- response back through the route
- The route layer should be viewed as a thin adapter, not the place for core rules.
9. State and consistency model
- Because the repository is in-memory, the system behaves like a single-node, ephemeral state application.
- There is no external database, queue, or third-party banking service in the architecture shown here.
- Any diagram should show the repository as process-local storage, not a separate infrastructure component.
10. Operational features
- The application supports the standard banking operations listed in the README plus an extra account-related interest rendering endpoint.
- The transfer operation is likely the most cross-cutting one, since it depends on both source and destination account state.
11. Runtime and tooling
- The app runs on Node.js 18+ and uses npm.
- next.config.js, tailwind.config.ts, postcss.config.js, and tsconfig.json support the build/runtime/tooling layer rather than the business architecture itself.
12. What to emphasize in a diagram
- Show four boxes: UI, API routes, banking service, in-memory repository.
- Mark the repository as non-persistent and inside the application boundary.
- If you include deployment concerns, represent this as a single Next.js process rather than a distributed system.
Main entry points: bankingService.ts Banking service · page.tsx Home page · types.ts Banking types · route.ts Accounts API
Components 11
UI
Browser-facing Next.js app shell and main page
- Home page · Main browser-facing entry point
src/app/page.tsx - App layout · Shared app shell for the UI
src/app/layout.tsx - Global CSS · Global styling entry for the app
src/app/globals.css
API routes
HTTP adapters under App Router
- Accounts API · Creates and lists accounts
src/app/api/accounts/route.ts - Balance API · Returns an account balance
src/app/api/accounts/[id]/balance/route.ts - Txn API · Processes credit and debit transactions
src/app/api/accounts/[id]/transaction/route.ts - Transfer API · Moves funds between accounts
src/app/api/transfer/route.ts - Juros API · Renders interest for accounts
src/app/api/accounts/render-juros/route.ts
Banking service
Core banking rules and shared domain types
- Banking service · Central banking rules and orchestration
src/lib/business/bankingService.ts - Banking types · Shared account and transaction contracts
src/lib/business/types.ts
In-memory store
Process-local persistence for account state
- Account repo · Ephemeral in-memory account persistence
src/lib/data/accountRepository.ts
Connections 15
- Home page → Accounts API: uses · UI initiates banking operations through HTTP
- Home page → Balance API: uses · UI can request balance data
- Home page → Txn API: uses · UI can submit account movements
- Home page → Transfer API: uses · UI can trigger transfers
- Home page → Juros API: uses · UI can request interest rendering
- Accounts API → Banking service: delegates · Route handlers translate HTTP into domain calls
- Balance API → Banking service: delegates · Balance lookup is handled by the service
- Txn API → Banking service: delegates · Transaction rules live in the service layer
- Transfer API → Banking service: delegates · Transfer orchestration is centralized in the service
- Juros API → Banking service: delegates · Interest rendering uses business logic
- Banking service → Banking types: uses · Service shares the domain contract
- Banking service → Account repo: persists · Service reads and updates process-local state
- Accounts API → Banking types: uses · API handlers work with shared banking types
- Txn API → Banking types: uses · Transaction payloads follow the shared model
- Transfer API → Banking types: uses · Transfer payloads follow the shared model