How 08pranav/blue-carbon-registry-blockchain works
1. Repository shape: a three-part system
- This repo combines a React/Vite frontend, an Express-style backend, and a Hardhat blockchain deployment workspace.
- The architecture is centered on a carbon-credit workflow: NGOs submit projects, auditors verify them, and companies buy credits through a blockchain marketplace.
2. Frontend is the primary user-facing application
- The main app lives in src/ and is a React 18 + TypeScript SPA built with Vite, Tailwind CSS, and shadcn/ui.
- Routing is page-driven (src/pages/*) with role-specific dashboards such as NGO, Auditor, Company, Admin, Marketplace, Registry, Verification, and Submit flows.
- The component layer includes reusable UI, wallet/connect widgets, dashboards, maps, forms, and verification interfaces.
3. Role-based UX is a first-class boundary
- src/contexts/RoleAuthContext.tsx, AuthContext.tsx, and ProtectedRoute.tsx indicate the app enforces role-based access at the UI boundary.
- The repo distinguishes at least four user types: NGO, Auditor, Company, Admin.
- Separate dashboards and login flows show that each role has different navigation, data visibility, and allowed blockchain actions.
4. Blockchain interaction is isolated into its own frontend subsystem
- src/blockchain-integration/, src/contexts/BlockchainContext.tsx, src/services/blockchain.ts, and wallet-related utilities encapsulate all chain access.
- The frontend uses Wagmi + Viem for wallet connectivity and contract calls, with MetaMask as the expected wallet.
- Contract ABIs and deployed addresses are stored in src/blockchain-integration/abi/ and src/contracts/addresses.json, which forms the boundary between UI code and on-chain contracts.
5. On-chain domain model: registry + token
- The README identifies two main contracts:
- BlueCarbonCredits: an ERC-20 token representing carbon credits.
- BlueCarbonRegistry: the orchestration contract for NGO registration, project submission, verification, and marketplace execution.
- The contract boundary is important because verification and trading are described as on-chain actions, not just off-chain database writes.
6. Canonical business flow runs from UI to blockchain
- NGO registration and project submission start in the frontend, then trigger wallet-signed blockchain transactions.
- Auditor verification is the key transition point: approval/rejection can trigger minting of carbon credit tokens.
- Marketplace purchases move credits between wallets and record the trade on-chain, which makes the blockchain the source of truth for ownership and transfer.
7. Backend serves off-chain application data and uploads
- The backend/ folder contains server.js, database/init.sql, and an uploads/ directory, indicating a separate server for persisted off-chain data and file handling.
- This backend likely supports project metadata, user/admin records, and document uploads that are not suitable for on-chain storage.
- api/ at the repo root suggests additional serverless/API entrypoints for deployment platforms such as Vercel, complementing or replacing the standalone backend in some environments.
8. Data storage is split between chain and database
- The blockchain stores immutable records for registrations, approvals, token balances, and trades.
- The backend database stores operational data such as profiles, submissions, and uploaded artifacts that need querying, editing, or larger payloads.
- DATABASE_ARCHITECTURE.md and backend/database/init.sql reinforce that the system is intentionally hybrid: immutable chain state + mutable off-chain application state.
9. Deployment and infrastructure are multi-target
- The repo includes:
- Dockerfile and backend/Dockerfile for containerized deployment,
- docker-compose.yml for local multi-service orchestration,
- nginx/nginx.conf for reverse-proxy/static hosting,
- vercel.json and public/_redirects for frontend hosting routes.
- This suggests the frontend can be deployed as a static SPA while the backend and blockchain tooling can run separately.
10. Blockchain deployment is treated as its own ops workspace
- blockchain-deployment/ contains Hardhat config, artifacts, deployment scripts, and Sepolia deployment state.
- Scripts cover deployment, permission fixes, role grants, verification tests, and marketplace state checks.
- The network target is explicitly Ethereum Sepolia testnet, which is the environment the app expects for wallet-connected interactions.
11. External dependencies that materially shape the architecture
- MetaMask is the wallet/authentication mechanism.
- Ethereum Sepolia is the chain the app is built around.
- Vite/React define the frontend runtime model.
- Wagmi/Viem define the blockchain interaction layer.
- Hardhat/OpenZeppelin define the smart contract deployment and token standards.
12. Observability, testing, and validation exist at multiple layers
- Frontend tests use Vitest (vitest.config.ts, src/test/*, component tests).
- There is coverage output in coverage/, implying test coverage is part of the workflow.
- The blockchain workspace includes dedicated scripts for connection checks, balance checks, role setup, and NGO verification testing, which suggests contract behavior is validated separately from the UI.
13. Important architectural takeaway for a diagram
- Draw the system as three interconnected planes:
- Presentation/UI: React SPA with role-specific pages and wallet connection.
- Application/Data: backend API + database + uploads for off-chain records.
- Blockchain: registry contract + ERC-20 token + Sepolia deployment/scripts.
- The key integration points are the wallet, the contract ABI/address layer, and the API/database boundary for off-chain metadata.
Main entry points: pages Role pages · server.js API server · App.tsx App shell · BlockchainContext.tsx Chain context
Components 18
Frontend SPA
React/Vite user application with role-based pages and wallet-connected blockchain actions
- App shell · Vite entry, routing, and top-level app composition
src/App.tsx - Role access · Auth, role context, and protected route boundary
src/contexts/RoleAuthContext.tsx - Role pages · NGO, auditor, company, admin, marketplace, registry, submit, and verification screens
src/pages - UI components · Reusable dashboards, forms, wallets, maps, and verification widgets
src/components - Wallet layer · MetaMask connection and wallet state utilities
src/components/ConnectWalletButton_Wagmi.tsx - Chain context · Frontend blockchain context and services wrapping contract access
src/contexts/BlockchainContext.tsx - ABI/addresses · Frontend contract ABIs and deployed addresses boundary
src/contracts/addresses.json - API clients · Frontend calls to backend and admin APIs
src/services/api.ts
Off-chain Backend
API and database layer for mutable application records and uploads
- API server · Standalone backend server for app data and workflows
backend/server.js - Database schema · Persistent off-chain tables for profiles, submissions, and operational data
backend/database/init.sql - Uploads · Stored project documents and other uploaded artifacts
backend/uploads - Serverless API · Root API entrypoints for hosted deployment environments
api
Blockchain Workspace
Hardhat contracts and deployment operations for Sepolia
- Registry + token · BlueCarbonRegistry orchestration contract and BlueCarbonCredits ERC-20 token
blockchain-deployment/contracts - Deploy workspace · Hardhat config, scripts, cache, artifacts, and Sepolia deployment state
blockchain-deployment - Sepolia state · Deployed addresses and network state for the testnet environment
blockchain-deployment/deployments/sepolia.json
Deployment Infra
Container, proxy, and hosting configuration
- Containers · Repository containerization for app and backend services
docker-compose.yml - Proxy/hosting · Reverse proxy and SPA hosting rewrites for deployment
nginx/nginx.conf
Other components
- Validation · Frontend and chain validation harnesses across the stack
vitest.config.ts
Connections 21
- App shell → Role access: wraps · App shell is guarded by auth and role-aware routing
- App shell → Role pages: renders · Routes into role-specific pages and workflows
- Role pages → UI components: composes · Pages reuse shared UI, maps, dashboards, and forms
- Role pages → Wallet layer: connects · Pages initiate wallet sign-in and transaction flows
- Wallet layer → Chain context: feeds · Wallet state is passed into blockchain interaction layer
- Chain context → ABI/addresses: uses · Contract calls are bound to ABIs and deployed addresses
- Chain context → Registry + token: calls · Frontend transaction and read operations target on-chain contracts
- Role pages → API clients: fetches · Pages read and write off-chain application data
- API clients → API server: requests · Client API layer talks to backend endpoints
- API server → Database schema: persists · Backend stores mutable records in the database
- API server → Uploads: stores · Backend manages uploaded project artifacts
- Serverless API → Database schema: serves · Hosted API entrypoints can share the same data model
- Deploy workspace → Registry + token: builds · Hardhat workspace compiles and deploys contracts
- Deploy workspace → Sepolia state: records · Deployment outputs track Sepolia addresses and state
- Role pages → Registry + token: triggers · NGO, auditor, and marketplace actions become wallet-signed chain transactions
- Role pages → API server: hydrates · UI combines blockchain state with off-chain metadata
- Containers → API server: runs · Backend is containerized for local and production deployment
- Proxy/hosting → App shell: serves · Reverse proxy and hosting config deliver the SPA
- Proxy/hosting → Serverless API: routes · Deployment rewrites can forward API traffic to hosted endpoints
- Validation → App shell: verifies · Vitest checks the frontend behavior
- Validation → Deploy workspace: verifies · Blockchain scripts validate deployment and contract behavior