Savings and Loans
# Savings & Loans Management Platform
Web admin portal replacing the Excel-based microfinance workflow. **Phase 1 — core lending slice.**
Stack: Node.js + Express + TypeScript (backend), React + Vite + TypeScript (frontend),
PostgreSQL (Supabase), Redis (sessions + rate limiting). Money is stored as integer **pesewas**.
## Monorepo layout
```
backend/ Express REST API (layered routes → controllers → services → repositories)
frontend/ React SPA (Vite)
```
## Prerequisites
- Node.js 20+ and npm 10+
- A Supabase Postgres database (connection string)
- A Redis instance (local or hosted)
## Setup
```bash
npm install # installs both workspaces
cp backend/.env.example backend/.env
# edit backend/.env — set DATABASE_URL, REDIS_URL, JWT secrets
cp frontend/.env.example frontend/.env # set VITE_API_URL if not
localhost
npm run migrate # create tables
npm run seed # company, branch, super admin, loan product, sample customers
npm run dev # starts API (:4000) and web (:5173) together
```
Default seeded super-admin login is printed by the seed script (see `backend/src/db/seeds`).
## Useful scripts (run from repo root)
| Command | Description |
| --- | --- |
| `npm run dev` | Run API + web concurrently |
| `npm run migrate` | Run Knex migrations |
| `npm run migrate:rollback` | Roll back the last migration batch |
| `npm run seed` | Seed baseline data |
| `npm test` | Backend unit tests (Vitest) |
## Business rules implemented (Phase 1 core slice)
- Custom JWT auth (access + refresh) with RBAC enforced in Express middleware.
- Savings-before-loan eligibility (≥4 weeks history + min balance + no active loan).
- Loan eligibility cap (configurable 2×–3× savings balance).
- Server-side loan calc engine: interest from a configurable **loan_products** rate table,
processing fee, `total = principal + interest + fee`, daily installment = `total / term_days` (80).
- Multi-st …