REST API for managing bank accounts and transactions with multi-currency support (COSMIC_COINS, GALAXY_GOLD, MOON_BUCKS).
The API is deployed and ready to use:
| Resource | URL |
|---|---|
| Base URL | https://api-production-6c87.up.railway.app |
| Health Check | https://api-production-6c87.up.railway.app/health |
| Generate API Key | https://api-production-6c87.up.railway.app/api/v1/auth |
| Accounts | https://api-production-6c87.up.railway.app/api/v1/accounts |
| Transactions | https://api-production-6c87.up.railway.app/api/v1/transactions |
-
Get your API key:
GET https://api-production-6c87.up.railway.app/api/v1/auth -
Use your key in all requests:
Header: x-api-key: <your-key> -
Create an account:
POST https://api-production-6c87.up.railway.app/api/v1/accounts Header: x-api-key: <your-key> Body: { "owner": "Your Name", "currency": "COSMIC_COINS", "balance": 5000 } -
Import into Postman: Set
baseUrlvariable tohttps://api-production-6c87.up.railway.app
These keys come with pre-seeded accounts for demo purposes:
| API Key | Accounts | Description |
|---|---|---|
1234 |
5 accounts | Admin/demo key |
workshop-alpha |
4 accounts | Workshop team A |
workshop-beta |
3 accounts | Workshop team B |
workshop-gamma |
3 accounts | Workshop team C |
Or generate a fresh key with GET /api/v1/auth and start from scratch.
# Install dependencies
npm install
# Start the server (requires DATABASE_URL)
DATABASE_URL=postgresql://localhost:5432/intergalactic_bank npm run dev
# Verify it's running
curl http://localhost:3000/health- Account Management - Create, view, update, delete accounts (ownership-based)
- Transaction Processing - Transfer funds between accounts or make deposits
- Multi-Currency - COSMIC_COINS, GALAXY_GOLD, MOON_BUCKS
- API Key Auth - Secure endpoints with API keys
- Rate Limiting - 300 requests/minute per key
- Ownership Control - Users can only access their own accounts
- Persistent Storage - PostgreSQL backend (data survives restarts)
- Atomic Transactions - Balance updates use SQL transactions for consistency
Use the Postman Collection for complete API documentation and testing:
- Import
OpenAPI/Bank API Reference Documentation.postman_collection.jsoninto Postman - Set
baseUrlvariable tohttps://api-production-6c87.up.railway.app(orhttp://localhost:3000for local) - Set
apiKeyvariable to1234(default admin key) - All endpoints are pre-configured with examples
| Endpoint | Method | Auth | Description |
|---|---|---|---|
/health |
GET | No | Health check |
/api/v1/auth |
GET | No | Generate API key |
/api/v1/accounts |
GET | Yes | List your accounts |
/api/v1/accounts/:id |
GET | Yes | Get single account |
/api/v1/accounts |
POST | Yes | Create account |
/api/v1/accounts/:id |
PUT | Yes | Update account (owner/type) |
/api/v1/accounts/:id |
DELETE | Yes | Delete account (soft) |
/api/v1/transactions |
GET | Yes | List transactions |
/api/v1/transactions/:id |
GET | Yes | Get transaction |
/api/v1/transactions |
POST | Yes | Transfer/deposit |
Include your API key in all authenticated requests:
Header: x-api-key: your-key-here
Generate a new key: GET /api/v1/auth
Default admin key: 1234
Create .env file (see .env.example):
PORT=3000
DATABASE_URL=postgresql://localhost:5432/intergalactic_bank
ADMIN_API_KEY=1234
RATE_LIMIT_REQUESTS=300
RATE_LIMIT_WINDOW_MS=60000src/
βββ server.js # Entry point
βββ database/
β βββ db.js # PostgreSQL database layer
β βββ pool.js # Connection pool setup
β βββ schema.sql # Table definitions
β βββ seed.js # Seed data (15 accounts, 7 transactions)
β βββ seed-runner.js # Standalone seed script
β βββ reset.js # Workshop reset (drop + recreate + seed)
βββ models/
β βββ Account.js # Account model + validation
β βββ Transaction.js # Transaction model
βββ routes/
β βββ admin.js # API key generation
β βββ accounts.js # Account CRUD
β βββ transactions.js # Transaction processing
βββ middleware/
βββ auth.js # API key validation
βββ errorHandler.js # Error handling
βββ rateLimit.js # Rate limiting
# Development mode (auto-reload)
npm run dev
# Production mode
npm start
# Run tests
npm test
# Seed the database
npm run seed
# Reset database (drop + recreate + seed)
npm run reset-db
# Lint code
npm run lintThe database is pre-seeded with 15 accounts across 4 API keys:
Admin key 1234:
| Account | Owner | Balance | Currency | Type |
|---|---|---|---|---|
| acc-001 | Nova Newman | 10,000 | COSMIC_COINS | STANDARD |
| acc-002 | Gary Galaxy | 237 | COSMIC_COINS | PREMIUM |
| acc-003 | Luna Starlight | 5,000 | GALAXY_GOLD | BUSINESS |
| acc-004 | Cosmo Nebula | 25,000 | MOON_BUCKS | PREMIUM |
| acc-005 | Stella Vortex | 1,500 | COSMIC_COINS | STANDARD |
Workshop keys (workshop-alpha, workshop-beta, workshop-gamma) each have 3-4 accounts with varied currencies and balances.
7 seed transactions are also included (transfers and deposits).
- STANDARD - Basic account (default)
- PREMIUM - Premium features
- BUSINESS - Business account
- COSMIC_COINS - Universal currency
- GALAXY_GOLD - Premium currency
- MOON_BUCKS - Alternative currency
- Ownership: Users can only access accounts created with their API key
- Soft Delete: Deleted accounts are marked as deleted (transaction history preserved)
- Immutable Fields: Balance and currency can only change via transactions
- Account Updates: Only owner name and account type are editable
- Persistent: Data survives server restarts (PostgreSQL)
Use Postman collection or POST to /api/v1/accounts:
{
"owner": "John Doe",
"currency": "COSMIC_COINS",
"balance": 1000,
"accountType": "STANDARD"
}POST to /api/v1/transactions:
{
"fromAccountId": "acc-001",
"toAccountId": "acc-002",
"amount": 500,
"currency": "COSMIC_COINS"
}Use "0" as fromAccountId to deposit from external source.
All errors follow this format:
{
"error": {
"name": "errorType",
"message": "Description of error"
}
}Common status codes:
- 400 - Validation error
- 401 - Missing/invalid API key
- 403 - Insufficient permissions
- 404 - Resource not found
- 429 - Rate limit exceeded
- 500 - Server error
- Node.js + Express.js
- PostgreSQL via
pg(node-postgres) - Railway for hosting
- API Key authentication
- Jest for testing
ISC
Need detailed API docs? Import the Postman collection
Found a bug? Check the tests with npm test
Need help? Review CLAUDE.md for architecture details