BlockGuardian is a portfolio and asset management platform: a Flask backend for authentication, portfolios, and read-only blockchain data, paired with a Next.js web dashboard, a React Native (Expo) mobile app, and Hardhat smart contracts. A user registers, signs in with JWT (with optional MFA), and manages portfolios of stocks, bonds, cryptocurrency, ETFs, mutual funds, commodities, forex, derivatives, real estate, and other alternative assets, with computed performance, allocation, and risk views.
- 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 |
|---|---|
| Portfolios | Create, update, and delete portfolios, record transactions, and view computed performance, allocation, and risk. |
| Blockchain | Hardhat-managed Solidity contracts, with a web3.py service that reads real on-chain state (contract addresses, token supply, portfolio and trade counts). |
| Clients | A Next.js web dashboard and a React Native mobile app, both talking to the same REST API. Their blockchain explorer views query the backend, not sample data. |
| Tests | 179 backend, 56 smart contract, 426 web, and 325 mobile tests. All four suites run in CI. |
flowchart TD
web["web-frontend (Next.js)"] -->|"HTTP/JSON"| api
mobile["mobile-frontend (React Native)"] -->|"HTTP/JSON"| api
api["Flask backend: /api/auth, /api/portfolios, /api/blockchain"] --> db[("PostgreSQL, SQLite for local dev")]
api --> redis[("Redis")]
api -->|"web3.py, BLOCKCHAIN_RPC_URL"| chain["Hardhat node: PortfolioManager, TradingPlatform, TokenizedAsset, DeFiIntegration, TestToken"]
The backend service in code/docker-compose.yml runs the Gunicorn production image on port 5000 with PostgreSQL and Redis as its dependencies. See docs/ARCHITECTURE.md for detail.
| Path | Purpose |
|---|---|
code/backend |
Flask REST API: routes, security, blockchain service, models, and tests |
code/blockchain |
Hardhat project: Solidity contracts, deploy scripts, and tests |
web-frontend |
Next.js dashboard, with Jest tests and Playwright end-to-end tests |
mobile-frontend |
React Native (Expo) app |
infrastructure |
Docker, Kubernetes, Terraform, Ansible, and disaster-recovery configuration |
scripts |
Setup, build, lint, health-check, and deployment scripts |
docs |
Project documentation |
.github |
CI/CD workflow and its documentation |
| Component | Details |
|---|---|
| API | Flask backend with three registered blueprints, /api/auth, /api/portfolios, and /api/blockchain, plus /health and /api/info. |
| Auth | JWT access and refresh tokens (Flask-JWT-Extended), optional TOTP-based MFA, password change, and profile management. If SECRET_KEY or JWT_SECRET_KEY is unset, a random value is generated for that process. |
| Portfolio and transactions | Ten asset types (stock, bond, cryptocurrency, ETF, mutual fund, commodity, forex, derivative, real estate, alternative). Buy, sell, deposit, withdrawal, dividend, interest, fee, transfer, split, and merger transactions. |
| Security infrastructure | Dedicated modules for authentication, field-level encryption, rate limiting (an in-house RateLimiter), audit logging, and input validation. |
| On-chain data | The /api/blockchain routes (status, contracts, explorer) are backed by a web3.py service that connects to the node at BLOCKCHAIN_RPC_URL and reads deployed contract addresses from BLOCKCHAIN_DEPLOYMENTS_DIR. |
| Smart contracts | PortfolioManager, TradingPlatform, TokenizedAsset, DeFiIntegration, and a TestToken, built on OpenZeppelin and compiled with Solidity 0.8.24. |
| Additional modules | User management routes, compliance and reporting, and monitoring metrics, plus an AI/ML metadata schema (models/ai_models.py, data model only). These are separate from the API surface listed below. |
| Web dashboard | Next.js 15 and React 19 (JavaScript, Tailwind CSS, Recharts) with Home, Login, Register, Dashboard, Portfolios (list and detail), Markets, Blockchain Explorer, and Account pages, plus About, Contact, Terms, and Privacy. |
| Mobile app | React Native (Expo SDK 52) with NativeWind and screens for Home, Login, Register, Dashboard, Portfolios, Portfolio Detail, Markets, Blockchain, and Account. |
| Area | Technology |
|---|---|
| Backend API | Python 3.11, Flask 3, Flask-CORS, Flask-JWT-Extended, Flask-SQLAlchemy, Gunicorn |
| Auth | PyJWT, bcrypt, pyotp (TOTP MFA) |
| Data layer | SQLAlchemy 2, PostgreSQL (SQLite for local development), Redis |
| Blockchain client | web3.py |
| Blockchain | Solidity 0.8.24, OpenZeppelin, Hardhat |
| Web frontend | Next.js 15, React 19, JavaScript, Tailwind CSS, Recharts |
| Mobile frontend | React Native, Expo (SDK 52), NativeWind, React Navigation |
| Infrastructure | Docker, Docker Compose, Kubernetes, Terraform, Ansible |
| Monitoring (infrastructure) | Prometheus, Grafana |
| CI/CD | GitHub Actions |
| Testing | pytest (backend), Hardhat (contracts), Jest (web and mobile), Playwright (web end-to-end) |
Prerequisites: Python 3.11+ and Node.js 20+. Docker is optional.
git clone https://github.com/quantsingularity/BlockGuardian.git
cd BlockGuardian
# Backend
cd code/backend
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env # edit as needed
# Smart contracts
cd ../blockchain
npm install
# 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/BlockGuardian.git
cd BlockGuardian
./scripts/setup_blockguardian_env.sh
./scripts/run_blockguardian.shFull, environment-specific instructions are in docs/INSTALLATION.md.
# Backend (from code/backend, venv active)
python -m src.main # http://localhost:5000, health check at /health
# Local blockchain (from code/blockchain): start a node, then deploy in a second terminal
npx hardhat node # http://127.0.0.1:8545
npm run deploy:local
# Web dashboard (from web-frontend)
npm run dev # http://localhost:3000
# Mobile app (from mobile-frontend)
npm startOr run the backend with PostgreSQL and Redis in Docker (from code/):
cd code
docker compose up --build backendThe web dashboard reads the API address from NEXT_PUBLIC_API_URL and the mobile app from EXPO_PUBLIC_API_URL; both default to http://localhost:5000. For anything beyond local use, set SECRET_KEY, JWT_SECRET_KEY, POSTGRES_PASSWORD, and REDIS_PASSWORD in the environment before starting Compose. See docs/USAGE.md and docs/CONFIGURATION.md.
Base URL http://localhost:5000.
| Group | Prefix | Endpoints |
|---|---|---|
| Health | Site root | GET /health, GET /api/info |
| Auth | /api/auth |
POST register, login, logout, refresh, setup-mfa, enable-mfa, disable-mfa, change-password, verify-token, and GET or PUT profile |
| Portfolios | /api/portfolios |
List and create, {id} (GET, PUT, DELETE), {id}/holdings, {id}/transactions (GET, POST), {id}/buy, {id}/sell, {id}/performance, {id}/allocation, {id}/risk, assets, assets/search |
| Blockchain | /api/blockchain |
GET status, GET contracts, GET explorer |
Full request and response shapes are in docs/API.md.
| Suite | Directory | Tests | Run locally |
|---|---|---|---|
| Backend | code/backend |
179 | pytest |
| Contracts | code/blockchain |
56 | npx hardhat test |
| Web | web-frontend |
426 | npm test |
| Mobile | mobile-frontend |
325 | npm test |
Run each command from the directory shown. All four suites run in CI. The Playwright end-to-end tests in web-frontend are run separately with npm run test:e2e. 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 seven 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, byte-compiles the sources, verifies the app imports in production mode, builds the production image, and smoke tests /health |
| 3 | Web-Frontend Test & Build | Code Quality Checks | npm ci, the Jest suite with coverage, the production Next.js build, and a build upload |
| 4 | Mobile-Frontend Test & Build | Code Quality Checks | npm ci, the Jest suite with coverage, the Expo web export, and a bundle upload |
| 5 | Smart Contract Tests | Code Quality Checks | Compiles the contracts with Hardhat, runs the contract tests, and uploads a coverage report |
| 6 | 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 |
| 7 | Infrastructure Validation | Code Quality Checks | Terraform, Kubernetes (base and all three overlays), and Ansible validation, plus yamllint, Docker Compose and Dockerfile checks, an infrastructure image build, and a secret scan |
| 8 | Scripts Validation | Code Quality Checks | ShellCheck, syntax, shebang, and executable-bit checks on every shell script, plus a --help smoke test for the deployment script |
Coverage reports and build artifacts are kept for 7 to 30 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 and design |
| docs/API.md | API endpoint documentation |
| docs/INSTALLATION.md | Environment setup |
| docs/CONFIGURATION.md | Configuration options and environment variables |
| docs/USAGE.md | End-user workflows |
| docs/CLI.md | Command-line usage |
| docs/FEATURE_MATRIX.md | Feature coverage |
| docs/TROUBLESHOOTING.md | Common issues and fixes |
| docs/CONTRIBUTING.md | Contribution process and standards |
| docs/examples/basic-portfolio.md | Example: creating and managing portfolios |
See docs/CONTRIBUTING.md.
This project is licensed under the MIT License. See the LICENSE file for details.
