# palmiery/nexbank architecture

> Architecture diagram of the GitHub repository palmiery/nexbank, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/palmiery/nexbank
- Repository: https://github.com/palmiery/nexbank

## Overview

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: [`src/lib/business/bankingService.ts`](https://github.com/palmiery/nexbank/blob/main/src/lib/business/bankingService.ts) (Banking service), [`src/app/page.tsx`](https://github.com/palmiery/nexbank/blob/main/src/app/page.tsx) (Home page), [`src/lib/business/types.ts`](https://github.com/palmiery/nexbank/blob/main/src/lib/business/types.ts) (Banking types), [`src/app/api/accounts/route.ts`](https://github.com/palmiery/nexbank/blob/main/src/app/api/accounts/route.ts) (Accounts API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["UI"]
  node_page["Home page<br/>Next.js page<br/>[page.tsx]"]
  node_layout["App layout<br/>Next.js layout<br/>[layout.tsx]"]
  node_styles["Global CSS<br/>Tailwind base<br/>[globals.css]"]
end

subgraph group_api["API routes"]
  node_accounts_route["Accounts API<br/>route handler<br/>[route.ts]"]
  node_balance_route["Balance API<br/>route handler<br/>[route.ts]"]
  node_transaction_route["Txn API<br/>route handler<br/>[route.ts]"]
  node_transfer_route["Transfer API<br/>route handler<br/>[route.ts]"]
  node_juros_route["Juros API<br/>route handler<br/>[route.ts]"]
end

subgraph group_business["Banking service"]
  node_banking_service["Banking service<br/>domain service<br/>[bankingService.ts]"]
  node_types["Banking types<br/>domain model<br/>[types.ts]"]
end

subgraph group_data["In-memory store"]
  node_account_repo[("Account repo<br/>memory store")]
end

node_page -->|"uses"| node_accounts_route
node_page -->|"uses"| node_balance_route
node_page -->|"uses"| node_transaction_route
node_page -->|"uses"| node_transfer_route
node_page -->|"uses"| node_juros_route
node_accounts_route -->|"delegates"| node_banking_service
node_balance_route -->|"delegates"| node_banking_service
node_transaction_route -->|"delegates"| node_banking_service
node_transfer_route -->|"delegates"| node_banking_service
node_juros_route -->|"delegates"| node_banking_service
node_banking_service -->|"uses"| node_types
node_banking_service -->|"persists"| node_account_repo
node_accounts_route -->|"uses"| node_types
node_transaction_route -->|"uses"| node_types
node_transfer_route -->|"uses"| node_types

click node_page "https://github.com/palmiery/nexbank/blob/main/src/app/page.tsx"
click node_layout "https://github.com/palmiery/nexbank/blob/main/src/app/layout.tsx"
click node_styles "https://github.com/palmiery/nexbank/blob/main/src/app/globals.css"
click node_accounts_route "https://github.com/palmiery/nexbank/blob/main/src/app/api/accounts/route.ts"
click node_balance_route "https://github.com/palmiery/nexbank/blob/main/src/app/api/accounts/[id]/balance/route.ts"
click node_transaction_route "https://github.com/palmiery/nexbank/blob/main/src/app/api/accounts/[id]/transaction/route.ts"
click node_transfer_route "https://github.com/palmiery/nexbank/blob/main/src/app/api/transfer/route.ts"
click node_juros_route "https://github.com/palmiery/nexbank/blob/main/src/app/api/accounts/render-juros/route.ts"
click node_banking_service "https://github.com/palmiery/nexbank/blob/main/src/lib/business/bankingService.ts"
click node_types "https://github.com/palmiery/nexbank/blob/main/src/lib/business/types.ts"
click node_account_repo "https://github.com/palmiery/nexbank/blob/main/src/lib/data/accountRepository.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_page,node_layout,node_styles toneBlue
class node_accounts_route,node_balance_route,node_transaction_route,node_transfer_route,node_juros_route toneAmber
class node_banking_service,node_types toneMint
class node_account_repo toneRose
```

## Components

### UI

Browser-facing Next.js app shell and main page

- [Home page](https://github.com/palmiery/nexbank/blob/main/src/app/page.tsx): Next.js page · Main browser-facing entry point · `src/app/page.tsx`
- [App layout](https://github.com/palmiery/nexbank/blob/main/src/app/layout.tsx): Next.js layout · Shared app shell for the UI · `src/app/layout.tsx`
- [Global CSS](https://github.com/palmiery/nexbank/blob/main/src/app/globals.css): Tailwind base · Global styling entry for the app · `src/app/globals.css`

### API routes

HTTP adapters under App Router

- [Accounts API](https://github.com/palmiery/nexbank/blob/main/src/app/api/accounts/route.ts): route handler · Creates and lists accounts · `src/app/api/accounts/route.ts`
- [Balance API](https://github.com/palmiery/nexbank/blob/main/src/app/api/accounts/[id]/balance/route.ts): route handler · Returns an account balance · `src/app/api/accounts/[id]/balance/route.ts`
- [Txn API](https://github.com/palmiery/nexbank/blob/main/src/app/api/accounts/[id]/transaction/route.ts): route handler · Processes credit and debit transactions · `src/app/api/accounts/[id]/transaction/route.ts`
- [Transfer API](https://github.com/palmiery/nexbank/blob/main/src/app/api/transfer/route.ts): route handler · Moves funds between accounts · `src/app/api/transfer/route.ts`
- [Juros API](https://github.com/palmiery/nexbank/blob/main/src/app/api/accounts/render-juros/route.ts): route handler · Renders interest for accounts · `src/app/api/accounts/render-juros/route.ts`

### Banking service

Core banking rules and shared domain types

- [Banking service](https://github.com/palmiery/nexbank/blob/main/src/lib/business/bankingService.ts): domain service · Central banking rules and orchestration · `src/lib/business/bankingService.ts`
- [Banking types](https://github.com/palmiery/nexbank/blob/main/src/lib/business/types.ts): domain model · Shared account and transaction contracts · `src/lib/business/types.ts`

### In-memory store

Process-local persistence for account state

- [Account repo](https://github.com/palmiery/nexbank/blob/main/src/lib/data/accountRepository.ts): memory store · Ephemeral in-memory account persistence · `src/lib/data/accountRepository.ts`

## Connections

- 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
