REST API for managing bank accounts and transactions with multi-currency support (COSMIC_COINS, GALAXY_GOLD, MOON_BUCKS).
- Quick Start
- Features
- API Overview
- Authentication
- Configuration
- Project Structure
- Development
- Domain Reference
- Usage Examples
- Error Handling
- Tech Stack
- Extending the API
npm install
npm run devServer: http://localhost:3000
Verify:
curl http://localhost:3000/healthPostman: Import OpenAPI/Bank API Reference Documentation.postman_collection.json, set baseUrl to http://localhost:3000 and apiKey to 1234.
| Area | Description |
|---|---|
| Accounts | Create, read, update, delete (ownership-based). |
| Transactions | Transfers between accounts; deposits from external source. |
| Currencies | COSMIC_COINS, GALAXY_GOLD, MOON_BUCKS. |
| Auth | API key in x-api-key header. |
| Rate limit | 300 requests per minute per key. |
| Ownership | Each key only accesses accounts created with that key. |
| Method | Path | Auth | Description |
|---|---|---|---|
| GET | /health |
No | Health check. |
| GET | /api/v1/auth |
No | Generate a new API key. |
| GET | /api/v1/accounts |
Yes | List accounts for the current key. |
| GET | /api/v1/accounts/:id |
Yes | Get one account by ID. |
| POST | /api/v1/accounts |
Yes | Create an account. |
| PUT | /api/v1/accounts/:id |
Yes | Update account (owner name, account type only). |
| DELETE | /api/v1/accounts/:id |
Yes | Soft-delete account. |
| GET | /api/v1/transactions |
Yes | List transactions (query params supported). |
| GET | /api/v1/transactions/:id |
Yes | Get one transaction by ID. |
| POST | /api/v1/transactions |
Yes | Transfer funds or deposit (body defines type). |
Base URL: http://localhost:3000 (or your configured PORT).
- Header:
x-api-key: <your-api-key> - Get a key:
GET /api/v1/auth(no auth required). - Default admin key:
1234(fromADMIN_API_KEYin.env).
All endpoints except /health, /, and /api/v1/auth require this header.
Optional .env (copy from .env.example if present):
| Variable | Default | Description |
|---|---|---|
PORT |
3000 |
Server port. |
ADMIN_API_KEY |
1234 |
Admin API key. |
RATE_LIMIT_REQUESTS |
300 |
Max requests per window. |
RATE_LIMIT_WINDOW_MS |
60000 |
Rate limit window (ms). |
src/
├── server.js # Entry point, middleware, route mounting
├── database/
│ └── db.js # In-memory storage (singleton)
├── models/
│ ├── Account.js # Account model and validation
│ └── Transaction.js # Transaction model
├── routes/
│ ├── admin.js # GET /api/v1/auth (key generation)
│ ├── accounts.js # Account CRUD
│ └── transactions.js # Transactions list, get, transfer/deposit
└── middleware/
├── auth.js # API key validation and admin check
├── errorHandler.js # Central error handler
└── rateLimit.js # Per-key rate limiting
| Command | Purpose |
|---|---|
npm run dev |
Run with auto-reload. |
npm start |
Run in production mode. |
npm test |
Run test suite. |
npm test -- --coverage |
Run tests with coverage. |
npm run lint |
Lint; use npm run lint:fix to fix. |
- STANDARD — Default.
- PREMIUM — Premium features.
- BUSINESS — Business account.
- COSMIC_COINS — Universal.
- GALAXY_GOLD — Premium.
- MOON_BUCKS — Alternative.
Three accounts are created, all owned by admin key 1234:
- Account 1: Nova Newman — 10,000 COSMIC_COINS
- Account 2: Gary Galaxy — 237 COSMIC_COINS
- Account 3: Luna Starlight — 5,000 GALAXY_GOLD
- Ownership: A key can only access accounts created with that key.
- Soft delete: Deleted accounts are marked deleted; history is kept.
- Balance/currency: Change only via transactions, not via account update.
- Editable fields: Only owner name and account type on existing accounts.
POST /api/v1/accounts with body:
{
"owner": "John Doe",
"currency": "COSMIC_COINS",
"balance": 1000,
"accountType": "STANDARD"
}POST /api/v1/transactions with body:
{
"fromAccountId": "account-uuid-1",
"toAccountId": "account-uuid-2",
"amount": 500,
"currency": "COSMIC_COINS"
}Same endpoint; use fromAccountId: "0":
{
"fromAccountId": "0",
"toAccountId": "account-uuid",
"amount": 100,
"currency": "COSMIC_COINS"
}All error responses use this shape:
{
"error": {
"name": "errorType",
"message": "Human-readable description"
}
}| Status | Meaning |
|---|---|
| 400 | Validation or bad request. |
| 401 | Missing or invalid API key. |
| 403 | Not allowed (e.g. wrong account owner). |
| 404 | Resource not found. |
| 429 | Rate limit exceeded. |
| 500 | Server error. |
- Runtime: Node.js
- Framework: Express.js
- Storage: In-memory (Map-based; swappable)
- Testing: Jest
- Auth: API key via header
Using a real database:
- Install the driver (e.g.
pg,mongodb). - Update
src/database/db.jswith connection and CRUD using the same interface so routes stay unchanged.
ISC.
Detailed API docs → Postman collection
Architecture → CLAUDE.md
Issues → Run npm test and check tests