An enterprise-grade peer-to-peer lending platform combining a Node.js REST API, Python ML credit-risk services, and Ethereum smart contracts.
code/
├── backend/ # Node.js / Express REST API
├── blockchain/ # Solidity smart contracts (Hardhat + Truffle)
├── ml_services/ # Python ML models & compliance framework
└── README.md # This file
- Node.js ≥ 18, npm ≥ 9
- Python ≥ 3.11, pip
- Docker & Docker Compose (for containerised setup)
- MongoDB 7 & Redis 7 (or use Docker)
git clone https://github.com/quantsingularity/LendSmart
cd LendSmart/code
cp backend/.env.example backend/.envEach service ships its own Dockerfile. Use the docker-compose.yml provided at the repo root (outside this code/ directory) to spin up the full stack:
docker compose up --buildServices started:
| Service | URL | Description |
|---|---|---|
| Backend API | http://localhost:3000 | Node.js REST API |
| ML Service | http://localhost:8000 | Python credit-risk model |
| MongoDB | localhost:27017 | Primary database |
| Redis | localhost:6379 | Cache / sessions |
Backend
cd backend
npm install
npm run dev # Development (nodemon + debug port 9229)
npm start # Production
npm test # Jest test suiteML Services
pip install -r ml_services/requirements.txt
# Train the model (first time)
python -m ml_services.credit_risk.train_model
# Start the prediction server
python -m ml_services.credit_risk.prediction_service --server --port 8000Blockchain
cd blockchain
npm install
npx hardhat compile
npx hardhat test
npx hardhat node # Local chain
npx hardhat run scripts/deploy.js --network localhostNode.js + Express REST API with MongoDB, Redis, JWT auth, rate limiting, audit logging and GDPR compliance.
backend/src/
├── controllers/ authController, loanController, userController, adminController
├── models/ User.js, Loan.js (Mongoose schemas)
├── routes/ authRoutes, loanRoutes, userRoutes, adminRoutes
├── services/
│ ├── ai/ aiService.js – calls ML prediction endpoints
│ ├── blockchain/ blockchainService.js – ethers.js multi-network client
│ ├── compliance/ complianceService.js
│ └── notification/ notificationService.js
├── middleware/
│ ├── auth.js JWT protect / authorize helpers
│ ├── monitoring/ errorHandler, healthCheck, metricsCollector
│ ├── security/ authMiddleware, rateLimiter, securityMiddleware
│ └── validation/ inputValidator (Joi schemas)
├── compliance/ auditLogger.js, gdprCompliance.js
├── config/ database.js, redis.js, blockchain.js, encryption.js
├── security/ authService.js
├── gateway/ apiGateway.js
└── utils/ logger.js, complianceMonitor.js
Key environment variables → see backend/.env.example.
Smart contracts for on-chain loan lifecycle management.
contracts/– Hardhat contracts (LendSmartLoan.sol,LoanContract.sol,Lock.sol,MockERC20.sol)truffle/– Legacy Truffle contracts (LoanManager.sol,BorrowerContract.sol)test/– Hardhat Mocha/Chai test suitescripts/– Deployment scripts
See blockchain/README.md for full toolchain instructions.
Python ML pipeline for credit scoring, risk assessment, alternative data scoring, and regulatory compliance.
credit_risk/– Ensemble ML models (sklearn, XGBoost, LightGBM, SHAP), Flask prediction APIcompliance/– Fair-lending, AML, GDPR, adverse-action notice generationintegration/–LendingSystemorchestrator combining all ML and compliance components
See ml_services/README.md for full service documentation.
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /api/auth/register |
– | Register new user |
| POST | /api/auth/login |
– | Login, returns JWT |
| POST | /api/auth/logout |
JWT | Invalidate token |
| GET | /api/users/me |
JWT | Get current user profile |
| PUT | /api/users/me |
JWT | Update profile |
| POST | /api/loans |
JWT | Apply for a loan |
| GET | /api/loans |
JWT | List user loans |
| GET | /api/loans/:id |
JWT | Get loan detail |
| POST | /api/loans/:id/repay |
JWT | Make a repayment |
| GET | /api/admin/loans |
JWT+Admin | All loans (admin) |
| GET | /health |
– | Health check |
| GET | /metrics |
– | Prometheus metrics |
| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Model health + load status |
| POST | /predict |
Single applicant prediction |
| POST | /predict/batch |
Batch predictions (JSON array) |
# Backend
cd backend && npm test
# ML Services
pytest ml_services/credit_risk/tests/ -v
# Smart Contracts
cd blockchain && npx hardhat test