How jdavidcruzc/bank-testing-lab works
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: app.js Express app · compose.yml Local stack · accounts.service.js Accounts service · server.js Server bootstrap
Components 16
Application Runtime
- Server bootstrap · Starts the HTTP runtime.
src/server.js - Express app · Configures middleware and mounts routes.
src/app.js - Local stack · Starts local application and database services.
compose.yml - Application image
Dockerfile - Connection settings · Documents environment-dependent connection settings.
.env.example
Accounts API
- Accounts routes · Accounts-facing HTTP boundary.
src/routes/accounts.routes.js - Accounts controller · Owns request validation, status codes, and response serialization.
src/controllers/accounts.controller.js - Accounts service · Implements account use cases and coordinates persistence.
src/services/accounts.service.js - Money utilities · Shared monetary formatting and calculations.
src/services/money.js
Persistence
- Database adapter · Owns SQL and database interaction.
src/db.js - Database
- Database bootstrap · Initializes the database schema.
db/init.sql
Compatibility & Tests
- Mobile consumer Pact · Defines mobile-app expectations for accounts endpoints.
tests/contract/consumer/mobile-app.pact.test.js - Provider Pact verification · Checks API conformance to consumer expectations.
tests/contract/provider/verify.pact.test.js - Accounts API integration
tests/integration/accounts.api.test.js - Accounts end-to-end · Exercises the real application and database boundary.
tests/e2e/accounts.e2e.test.js
Connections 17
- 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