A robust banking API implementation that supports internal and external (B2B) transactions, following the specifications provided in SPECIFICATIONS.md
.
-
Account Management
- Create and manage bank accounts
- Support for multiple currencies (EUR, USD, GBP)
- Account balance tracking
- Transaction history
-
Transaction Processing
- Internal transfers between accounts
- External (B2B) transfers between banks
- Currency conversion support
- Transaction status tracking
-
Security
- JWT-based authentication
- RSA key pair management
- JWKS (JSON Web Key Set) support
- Rate limiting
- Input validation
-
Resilience
- Retry logic for external transfers
- Comprehensive error handling
- Detailed logging
- Transaction status tracking
- Node.js (v14 or higher)
- npm (v6 or higher)
- MongoDB (for data storage)
Create a .env
file with the following variables:
PORT=9000
MONGODB_URI=mongodb://localhost:27017/bank-api
JWT_SECRET=your-secret-key
BANK_PREFIX=your-bank-prefix
- Clone the repository:
git clone https://github.com/Gren-95/bank-api
cd bank-api
- Cope example env to production
cp .env.example .env
- Start the server (dependencies are installed at start):
npm start
The API will be available at http://localhost:9000
To run the API as a systemd service, create a service file at /etc/systemd/system/bank-api.service
:
[Unit]
Description=Bank API Service
After=network.target
[Service]
WorkingDirectory=/public/bank-api
ExecStart=/bin/sh -c 'npm start'
Restart=always
[Install]
WantedBy=multi-user.target
Then enable and start the service:
sudo systemctl enable bank-api
sudo systemctl start bank-api
Check the service status:
sudo systemctl status bank-api
API documentation is available at http://localhost:9000/docs
when the server is running.
POST /auth/login
- User authenticationPOST /accounts
- Create new accountGET /accounts/:id
- Get account detailsPOST /transactions/internal
- Process internal transferPOST /transactions/b2b
- Process external (B2B) transferGET /transactions/:id
- Get transaction detailsGET /transactions/jwks
- Get bank's public keys (JWKS)
-
Sending Bank
- Creates JWT with transaction details
- Signs JWT with private key
- Sends to receiving bank
-
Receiving Bank
- Verifies JWT using sender's public key
- Validates transaction details
- Processes transaction if valid
- Returns success/failure response
The API implements comprehensive error handling:
-
HTTP Status Codes
- 200: Success
- 201: Created
- 400: Bad Request
- 401: Unauthorized
- 403: Forbidden
- 404: Not Found
- 402: Payment Required
- 500: Server Error
-
Detailed Error Messages
- Validation errors
- Authentication failures
- Transaction processing errors
- External service errors
The API implements detailed logging for:
- Authentication attempts
- Transaction processing
- External service interactions
- Error scenarios
- JWT verification
- Currency conversions
- JWT-based authentication
- RSA key pair management
- JWKS support for B2B transactions
- Rate limiting
- Input validation
- Secure password handling