Overview
UME Loans API is a NestJS-based backend service providing RESTful endpoints for the Loan Application Management Portal. It features PostgreSQL storage via Drizzle ORM, Redis caching, AI-powered credit risk assessment, and Swagger documentation.
Tech Stack
| Technology | Purpose |
|---|---|
| NestJS 11 | Node.js framework (TypeScript) |
| Drizzle ORM | Type-safe database ORM |
| Neon PostgreSQL | Serverless database (Sydney region) |
| Upstash Redis | Caching & rate limiting |
| OpenAI API | AI credit risk assessment |
| Swagger / OpenAPI | Interactive API documentation |
| Docker | Containerized deployment |
| Railway | Cloud deployment platform |
Architecture
Clean Architecture with 4 distinct layers:
| Layer | Responsibility | Scalability |
|---|---|---|
| Controller | Request validation, routing, Swagger docs | API versioning (v1/v2) |
| Service | Business logic, state machine validation | Workflow engine, event publishing |
| Repository | Data access, query building | Pagination, filtering, full-text search |
| Provider | External service abstraction (AI) | Swap AI models, add credit bureau APIs |
API Endpoints
/api/v1/applications
List all loan applications. Optional filter: ?status=Pending
/api/v1/applications/:id
Get a single application with full status history
/api/v1/applications/:id/status
Update application status. Body: { "status": "Under Review", "notes": "..." }
/api/v1/applications/:id/ai-assessment
Run AI credit risk assessment for the application
/api/v1/health
Health check endpoint
Database Schema
Status Workflow
| From | Allowed Transitions | Validation |
|---|---|---|
| Pending | Under Review | Service layer enforces |
| Under Review | Approved, Rejected | Service layer enforces |
| Approved | None (terminal) | 400 Bad Request |
| Rejected | None (terminal) | 400 Bad Request |
AI Assessment
Provider Pattern
The AI module uses an interface-based provider pattern (AiProvider).
The default implementation uses OpenAI (gpt-4o-mini). If no API key is configured,
it falls back to a rule-based assessment engine using credit score and debt-to-income ratio.
The provider can be swapped without changing any business logic.
Caching & Rate Limiting
Redis Cache
- Application list cached for 30s
- Individual application cached for 30s
- Cache invalidated on status update
- Graceful degradation when Redis unavailable
Rate Limiting
- Sliding window: 60 requests per minute
- Powered by Upstash Ratelimit
- Analytics enabled
- Disabled when Redis not configured
CI/CD Pipeline
| Workflow | Trigger | Description |
|---|---|---|
| CI | Push / PR to main | Lint, type check, build |
| Security | Push / PR + weekly | npm audit + CodeQL analysis |
| Automation | PR opened | Auto-labeling by path and size |
| Pages | docs/ changed | Deploy documentation to GitHub Pages |
Deployment
Platform: Railway (Dockerfile-based deployment)
Health Check: /api/v1/health
Database: Neon PostgreSQL (ap-southeast-2, Sydney)
Swagger Docs: /docs (live interactive API documentation)