# jdavidcruzc/bank-testing-lab architecture

> Architecture diagram of the GitHub repository jdavidcruzc/bank-testing-lab, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jdavidcruzc/bank-testing-lab
- Repository: https://github.com/jdavidcruzc/bank-testing-lab

## Overview

#### Purpose and entry points
`bank-testing-lab` is a Node.js banking/accounts API designed with layered tests, including consumer/provider contract verification. The HTTP runtime starts at `src/server.js`, which boots the Express application assembled in `src/app.js`.

#### HTTP application boundary
`src/app.js` defines application middleware and mounts route modules. `src/routes/accounts.routes.js` owns the accounts-facing HTTP endpoints and maps requests to controller handlers. This is the boundary between external clients—including the mobile-app Pact consumer—and internal account logic.

#### Accounts request handling
`src/controllers/accounts.controller.js` translates HTTP request/response concerns into service calls: extracting request inputs, selecting status codes, and serializing API responses. It should remain the place for transport validation and error presentation rather than business or persistence rules.

#### Accounts domain/service layer
`src/services/accounts.service.js` implements account-oriented use cases and coordinates persistence access. It is the primary business boundary between the controller/API layer and the database adapter. `src/services/money.js` centralizes monetary formatting or calculation behavior used by account flows, avoiding currency logic in HTTP handlers.

#### Persistence and database infrastructure
`src/db.js` is the application’s database access boundary, used by services rather than routes/controllers. Database schema/bootstrap SQL lives in `db/init.sql`. Local/containerized database startup is defined by `compose.yml`; the application image/runtime is defined by `Dockerfile`. Environment-dependent connection settings are represented by `.env.example`.

#### Core flow
A typical accounts operation flows:
`src/server.js` → `src/app.js` → `src/routes/accounts.routes.js` → `src/controllers/accounts.controller.js` → `src/services/accounts.service.js` → `src/db.js` → database initialized by `db/init.sql`.

Responses return through the same layers, with `src/services/money.js` supplying shared money representation where needed. Controllers own HTTP semantics; services own account behavior; `src/db.js` owns SQL/database interaction.

#### Verification and external compatibility
The API’s critical external compatibility surface is accounts endpoints. Consumer expectations are expressed by `tests/contract/consumer/mobile-app.pact.test.js`; provider conformance is checked by `tests/contract/provider/verify.pact.test.js`. End-to-end API behavior runs through the real application/database boundary in `tests/e2e/accounts.e2e.test.js`, while integration coverage targets the accounts API in `tests/integration/accounts.api.test.js`.

Main entry points: [`src/app.js`](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/src/app.js) (Express app), [`compose.yml`](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/compose.yml) (Local stack), [`src/services/accounts.service.js`](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/src/services/accounts.service.js) (Accounts service), [`src/server.js`](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/src/server.js) (Server bootstrap)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Application Runtime"]
  node_server["Server bootstrap<br/>Node entry point<br/>[server.js]"]
  node_app["Express app<br/>HTTP composition<br/>[app.js]"]
  node_compose{{"Local stack<br/>container orchestration<br/>[compose.yml]"}}
  node_dockerfile["Application image<br/>container build"]
  node_env_example["Connection settings<br/>environment template<br/>[.env.example]"]
end

subgraph group_accounts["Accounts API"]
  node_accounts_routes["Accounts routes<br/>route module<br/>[accounts.routes.js]"]
  node_accounts_controller["Accounts controller<br/>HTTP controller"]
  node_accounts_service["Accounts service<br/>domain service"]
  node_money["Money utilities<br/>domain utility<br/>[money.js]"]
end

subgraph group_persistence["Persistence"]
  node_db_adapter["Database adapter<br/>data access boundary<br/>[db.js]"]
  node_database[("Database")]
  node_db_schema["Database bootstrap<br/>SQL schema<br/>[init.sql]"]
end

subgraph group_verification["Compatibility &amp; Tests"]
  node_mobile_consumer_contract["Mobile consumer Pact<br/>consumer contract test"]
  node_provider_verification["Provider Pact verification<br/>provider contract test"]
  node_integration_tests["Accounts API integration<br/>integration test"]
  node_e2e_tests["Accounts end-to-end<br/>end-to-end test"]
end

node_server -->|"boots"| node_app
node_app -->|"mounts"| node_accounts_routes
node_accounts_routes -->|"dispatches"| node_accounts_controller
node_accounts_controller -->|"invokes"| node_accounts_service
node_accounts_service -->|"uses"| node_money
node_accounts_service -->|"persists through"| node_db_adapter
node_db_adapter -->|"queries"| node_database
node_db_schema -->|"initializes"| node_database
node_dockerfile -->|"builds application service"| node_compose
node_compose -->|"runs"| node_server
node_compose -->|"starts"| node_database
node_env_example -.->|"configures connection"| node_db_adapter
node_mobile_consumer_contract -.->|"specifies expectations"| node_accounts_routes
node_provider_verification -.->|"verifies provider"| node_app
node_integration_tests -.->|"exercises API"| node_app
node_e2e_tests -.->|"runs through HTTP runtime"| node_server
node_e2e_tests -.->|"uses real boundary"| node_database

click node_server "https://github.com/jdavidcruzc/bank-testing-lab/blob/main/src/server.js"
click node_app "https://github.com/jdavidcruzc/bank-testing-lab/blob/main/src/app.js"
click node_accounts_routes "https://github.com/jdavidcruzc/bank-testing-lab/blob/main/src/routes/accounts.routes.js"
click node_accounts_controller "https://github.com/jdavidcruzc/bank-testing-lab/blob/main/src/controllers/accounts.controller.js"
click node_accounts_service "https://github.com/jdavidcruzc/bank-testing-lab/blob/main/src/services/accounts.service.js"
click node_money "https://github.com/jdavidcruzc/bank-testing-lab/blob/main/src/services/money.js"
click node_db_adapter "https://github.com/jdavidcruzc/bank-testing-lab/blob/main/src/db.js"
click node_db_schema "https://github.com/jdavidcruzc/bank-testing-lab/blob/main/db/init.sql"
click node_compose "https://github.com/jdavidcruzc/bank-testing-lab/blob/main/compose.yml"
click node_dockerfile "https://github.com/jdavidcruzc/bank-testing-lab/tree/main/Dockerfile"
click node_env_example "https://github.com/jdavidcruzc/bank-testing-lab/blob/main/.env.example"
click node_mobile_consumer_contract "https://github.com/jdavidcruzc/bank-testing-lab/blob/main/tests/contract/consumer/mobile-app.pact.test.js"
click node_provider_verification "https://github.com/jdavidcruzc/bank-testing-lab/blob/main/tests/contract/provider/verify.pact.test.js"
click node_integration_tests "https://github.com/jdavidcruzc/bank-testing-lab/blob/main/tests/integration/accounts.api.test.js"
click node_e2e_tests "https://github.com/jdavidcruzc/bank-testing-lab/blob/main/tests/e2e/accounts.e2e.test.js"

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_server,node_app,node_compose,node_dockerfile,node_env_example toneBlue
class node_accounts_routes,node_accounts_controller,node_accounts_service,node_money toneAmber
class node_db_adapter,node_database,node_db_schema toneMint
class node_mobile_consumer_contract,node_provider_verification,node_integration_tests,node_e2e_tests toneRose
```

## Components

### Application Runtime

- [Server bootstrap](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/src/server.js): Node entry point · Starts the HTTP runtime. · `src/server.js`
- [Express app](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/src/app.js): HTTP composition · Configures middleware and mounts routes. · `src/app.js`
- [Local stack](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/compose.yml): container orchestration · Starts local application and database services. · `compose.yml`
- [Application image](https://github.com/jdavidcruzc/bank-testing-lab/tree/main/Dockerfile): container build · `Dockerfile`
- [Connection settings](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/.env.example): environment template · Documents environment-dependent connection settings. · `.env.example`

### Accounts API

- [Accounts routes](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/src/routes/accounts.routes.js): route module · Accounts-facing HTTP boundary. · `src/routes/accounts.routes.js`
- [Accounts controller](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/src/controllers/accounts.controller.js): HTTP controller · Owns request validation, status codes, and response serialization. · `src/controllers/accounts.controller.js`
- [Accounts service](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/src/services/accounts.service.js): domain service · Implements account use cases and coordinates persistence. · `src/services/accounts.service.js`
- [Money utilities](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/src/services/money.js): domain utility · Shared monetary formatting and calculations. · `src/services/money.js`

### Persistence

- [Database adapter](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/src/db.js): data access boundary · Owns SQL and database interaction. · `src/db.js`
- **Database**: database runtime
- [Database bootstrap](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/db/init.sql): SQL schema · Initializes the database schema. · `db/init.sql`

### Compatibility & Tests

- [Mobile consumer Pact](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/tests/contract/consumer/mobile-app.pact.test.js): consumer contract test · Defines mobile-app expectations for accounts endpoints. · `tests/contract/consumer/mobile-app.pact.test.js`
- [Provider Pact verification](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/tests/contract/provider/verify.pact.test.js): provider contract test · Checks API conformance to consumer expectations. · `tests/contract/provider/verify.pact.test.js`
- [Accounts API integration](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/tests/integration/accounts.api.test.js): integration test · `tests/integration/accounts.api.test.js`
- [Accounts end-to-end](https://github.com/jdavidcruzc/bank-testing-lab/blob/main/tests/e2e/accounts.e2e.test.js): end-to-end test · Exercises the real application and database boundary. · `tests/e2e/accounts.e2e.test.js`

## Connections

- Server bootstrap → Express app: boots
- Express app → Accounts routes: mounts
- Accounts routes → Accounts controller: dispatches
- Accounts controller → Accounts service: invokes
- Accounts service → Money utilities: uses
- Accounts service → Database adapter: persists through
- Database adapter → Database: queries
- Database bootstrap → Database: initializes
- Application image → Local stack: builds application service
- Local stack → Server bootstrap: runs
- Local stack → Database: starts
- Connection settings → Database adapter: configures connection
- Mobile consumer Pact → Accounts routes: specifies expectations
- Provider Pact verification → Express app: verifies provider
- Accounts API integration → Express app: exercises API
- Accounts end-to-end → Server bootstrap: runs through HTTP runtime
- Accounts end-to-end → Database: uses real boundary
