BlockScore is a blockchain-based credit scoring platform: a Flask backend for authentication, credit scoring, loan applications, and blockchain-anchored records, paired with a React web dashboard, a React Native mobile app, Hardhat smart contracts, and a separate XGBoost scoring service.
- Overview
- Architecture
- Project Structure
- Feature Status
- Technology Stack
- Installation and Setup
- Running the Stack
- API Surface
- Testing
- CI/CD Pipeline
- Documentation
- Contributing
- License
| Topic | Summary |
|---|---|
| Scoring | A multi-factor rule-based engine, plus an XGBoost model served by the blockscore_ai package in code/ai_models. The model is used when reachable, and each stored score records which path produced it. |
| Fallback | If the AI service is unreachable or returns an invalid response, the backend falls back to the rule-based engine. |
| Blockchain | Hardhat-managed Solidity contracts, read and written by the backend through web3.py. |
| Clients | A React web dashboard and a React Native mobile app, both talking to the same REST API. |
| Tests | 233 backend, 62 AI service, 53 smart contract, 52 web, and 36 mobile tests. All five suites run in CI. |
flowchart TD
web["web-frontend (React, Vite)"] -->|"HTTP/JSON"| api
mobile["mobile-frontend (React Native)"] -->|"HTTP/JSON"| api
api["Flask backend: health, auth, credit, loans, profile"] --> db[("PostgreSQL, SQLite for local dev")]
api --> worker["Celery worker (Redis broker)"]
api -->|"AI_MODEL_URL, rule-based fallback"| ai["ai_models service (XGBoost)"]
api -->|"web3.py"| chain["Hardhat contracts: CreditScore, LoanContract, GovernanceToken"]
| Compose service | Image or build | Host port | Role |
|---|---|---|---|
backend |
code/backend/Dockerfile |
5000 | Flask API served by Gunicorn |
ai_model |
code/ai_models/Dockerfile |
None | Scoring service on port 5001, reachable only inside the stack |
celery_worker |
code/backend/Dockerfile |
None | Background jobs |
postgres |
postgres:15-alpine |
5432 | Primary database |
redis |
redis:7-alpine |
6379 | Cache and Celery broker (password protected) |
See docs/architecture.md for detail.
| Path | Purpose |
|---|---|
code/backend |
Flask application (routes in app.py), services, models, Celery jobs, and tests |
code/ai_models |
blockscore_ai scoring service: API, scoring, training, research, and tests |
code/blockchain |
Hardhat project: Solidity contracts and tests |
web-frontend |
React (Vite) dashboard |
mobile-frontend |
React Native app |
infrastructure |
Docker, Kubernetes, Terraform, and Ansible configuration |
scripts |
Setup, run, lint, and deployment scripts |
docs |
Project documentation |
.github |
CI/CD workflow and its documentation |
| Component | Details |
|---|---|
| API | Flask application with every route defined in app.py: health, auth (register, login, logout, refresh), credit (score calculation, history), loans (apply, calculate, list, anchor to blockchain), and profile. |
| Auth | JWT sessions with bcrypt password hashing and an in-house MFA service. In production the app refuses to start if SECRET_KEY or JWT_SECRET_KEY is a placeholder or shorter than 32 characters. |
| Credit scoring | Rule-based engine covering payment history, credit utilization, length of history, credit mix, new credit, income stability, and debt-to-income. Also calls the AI service for a model-based score, with retries and a circuit breaker. Responses include the scoring source, model version, confidence, and key insights. |
| AI model service | code/ai_models is a separate Flask API with its own Dockerfile. It exposes /health, /model-info, /predict, and /batch-predict, supports an optional API key (AI_MODEL_API_KEY), and includes a training CLI and research modules. |
| Background jobs | Celery app in code/backend/utils/background_jobs.py, backed by Redis and run by the celery_worker container. |
| Smart contracts | CreditScore and CreditScoreV2, LoanContract and LoanContractV2, and a GovernanceToken, deployed with Hardhat and used through the backend's web3.py blockchain service. |
| Web dashboard | React app (JavaScript, Vite, Material-UI, Chart.js) with Landing, Dashboard, Credit History, Loan Calculator, Profile, Help, and sign in, sign up, and password reset screens. |
| Mobile app | React Native app (TypeScript and JavaScript) with Home, Dashboard, Credit History, Loan Calculator, Login, Register, and Profile screens, using Redux Toolkit, React Navigation, and React Native Elements (@rneui). |
| Area | Technology |
|---|---|
| Blockchain | Solidity 0.8, OpenZeppelin, Hardhat |
| Backend API | Python 3.11, Flask, Flask-SQLAlchemy, Gunicorn |
| Auth | PyJWT, bcrypt, an in-house MFA service |
| Data layer | SQLAlchemy 2, PostgreSQL (SQLite for local development), Redis |
| Background jobs | Celery |
| ML (credit scoring) | scikit-learn, XGBoost, optional SHAP explainability, with a rule-based fallback |
| Web frontend | React 18, Vite 6, Material-UI (MUI), Chart.js, React Router, axios |
| Mobile frontend | React Native, TypeScript, Redux Toolkit, React Navigation, React Native Elements (@rneui) |
| Infrastructure | Docker, Docker Compose, Kubernetes, Terraform, Ansible |
| CI/CD | GitHub Actions |
| Testing | pytest (backend and AI service), Hardhat (contracts), Vitest (web), Jest (mobile) |
Prerequisites: Python 3.11+ and Node.js 18+ (CI uses Node 20). Docker is optional.
git clone https://github.com/quantsingularity/BlockScore.git
cd BlockScore
# Smart contracts
cd code/blockchain
npm install
# Backend
cd ../backend
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
# AI scoring service
cd ../ai_models
pip install -r requirements.txt
# Web frontend
cd ../../web-frontend
npm install --legacy-peer-deps
# Mobile frontend
cd ../mobile-frontend
npm install --legacy-peer-depsFor an automated setup:
git clone https://github.com/quantsingularity/BlockScore.git
cd BlockScore
./scripts/setup_blockscore_env.sh
./scripts/run_blockscore.shFull, environment-specific instructions are in docs/INSTALLATION.md, and a short walkthrough is in docs/QUICKSTART.md.
# Full local stack: Postgres, Redis, the AI service, the backend, and a Celery worker
# (from code/, Docker required). Both secrets must be 32+ characters.
cd code
export SECRET_KEY="$(openssl rand -hex 32)"
export JWT_SECRET_KEY="$(openssl rand -hex 32)"
docker compose up -dOr run the components individually:
# AI scoring service (from code/ai_models)
python -m src # http://127.0.0.1:5001
# Backend (from code/backend, venv active)
python app.py # http://127.0.0.1:5000
# Local blockchain node (from code/blockchain)
npx hardhat node
# Web dashboard (from web-frontend)
npm run dev # http://localhost:3000, proxies /api to :5000
# Mobile app (from mobile-frontend)
npm startThe backend reaches the AI service through AI_MODEL_URL (default http://localhost:5001). The mobile app reads its API address from API_BASE_URL (default http://localhost:5000). See docs/usage.md and docs/CONFIGURATION.md.
Base URL http://localhost:5000/api.
| Group | Endpoints |
|---|---|
| Health | GET health |
| Auth | POST auth/register, auth/login, auth/logout, auth/refresh |
| Credit | POST credit/calculate-score, GET credit/history |
| Loans | POST loans/apply, loans/calculate, GET loans/applications, POST loans/applications/{id}/blockchain |
| Profile | GET profile, PUT profile |
The AI service (default port 5001) exposes GET /health, GET /model-info, POST /predict, and POST /batch-predict. Full request and response shapes are in docs/API.md.
| Suite | Directory | Tests | Run locally |
|---|---|---|---|
| Backend | code/backend |
233 | pytest |
| AI model | code/ai_models |
62 | PYTHONPATH=. pytest tests/ |
| Contracts | code/blockchain |
53 | npx hardhat test |
| Web | web-frontend |
52 | npm test |
| Mobile | mobile-frontend |
36 | npm test |
Run each command from the directory shown. All five suites run in CI. Three backend integration tests that call the live AI service run only when the blockscore_ai package is installed. See CI/CD Pipeline.
GitHub Actions (.github/workflows/cicd.yml) runs on pushes and pull requests to main and develop, and on manual dispatch. Every job after the first depends on Code Quality Checks, so the other eight run in parallel once formatting passes.
| # | Job | Depends on | What it does |
|---|---|---|---|
| 1 | Code Quality Checks | None | autoflake and black --check on Python, plus a repository-wide Prettier check (JS, TS, JSON, HTML, CSS, Markdown, Solidity, YAML) |
| 2 | Backend Test & Build | Code Quality Checks | Runs pytest with coverage, builds the backend image, smoke tests it, checks that production rejects placeholder secrets, and uploads the image |
| 3 | AI Models Test & Validation | Code Quality Checks | Byte-compiles the service, verifies 14 modules import cleanly, and runs the AI service tests with coverage |
| 4 | Smart Contract Compile & Test | Code Quality Checks | Compiles the contracts with Hardhat, runs the contract tests, and uploads the compiled artifacts |
| 5 | Web-Frontend Test & Build | Code Quality Checks | npm ci, the Vitest suite, the production Vite build, and a bundle upload |
| 6 | Mobile-Frontend Test & Build | Code Quality Checks | npm ci, the Jest suite with coverage, the Expo web export, and a bundle upload |
| 7 | Docs Validation | Code Quality Checks | markdownlint, offline link and anchor checks, code-sample syntax checks, docs and scripts consistency checks, and an advisory external link check |
| 8 | Infrastructure Validation | Code Quality Checks | Terraform, rendered Kubernetes manifests for all three environments, and Ansible validation, plus yamllint, Compose and Dockerfile checks, a proxy image build, and a secret scan |
| 9 | Scripts Validation | Code Quality Checks | ShellCheck, syntax, shebang, and executable-bit checks on every shell script, plus a --help smoke test for the CLI scripts |
Coverage reports are kept for 30 days and build artifacts for 7 days. The step-by-step breakdown of each job is in .github/readme/README.md.
| Document | Contents |
|---|---|
| docs/README.md | Documentation index |
| docs/architecture.md | System architecture |
| docs/API.md | REST API reference |
| docs/QUICKSTART.md | Fast-track setup guide |
| docs/INSTALLATION.md | Setup for all components |
| docs/deployment.md | Deployment procedures |
| docs/CONFIGURATION.md | Environment variables and config |
| docs/usage.md | Running and using the platform |
| docs/CLI.md | Helper scripts reference |
| docs/FEATURE_MATRIX.md | Feature status, implemented vs planned |
| docs/SMART_CONTRACTS.md | Contract architecture and interfaces |
| docs/SECURITY.md | Security model and disclosure process |
| docs/troubleshooting.md | Common issues and fixes |
| docs/CONTRIBUTING.md | Contribution guide |
| docs/examples/auth_example.md | Example: registration, login, and authenticated requests |
| docs/examples/credit_scoring.md | Example: calculating scores and viewing history |
| docs/examples/loan_application.md | Example: loan terms and applications |
| docs/examples/ai_integration.md | Example: integrating with the AI model service |
See docs/CONTRIBUTING.md.
This project is licensed under the MIT License. See the LICENSE file for details.
