# 08pranav/blue-carbon-registry-blockchain architecture

> Architecture diagram of the GitHub repository 08pranav/blue-carbon-registry-blockchain, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/08pranav/blue-carbon-registry-blockchain
- Repository: https://github.com/08pranav/blue-carbon-registry-blockchain

## Overview

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: [`src/pages`](https://github.com/08pranav/blue-carbon-registry-blockchain/tree/main/src/pages) (Role pages), [`backend/server.js`](https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/backend/server.js) (API server), [`src/App.tsx`](https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/src/App.tsx) (App shell), [`src/contexts/BlockchainContext.tsx`](https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/src/contexts/BlockchainContext.tsx) (Chain context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend SPA"]
  node_app_shell["App shell<br/>React SPA<br/>[App.tsx]"]
  node_role_access["Role access<br/>auth guards"]
  node_ui_pages["Role pages<br/>page layer"]
  node_ui_components["UI components<br/>shared UI"]
  node_wallet_layer["Wallet layer<br/>web3 wallet"]
  node_chain_context["Chain context<br/>web3 bridge"]
  node_abi_addresses["ABI/addresses<br/>contract config<br/>[addresses.json]"]
  node_api_clients["API clients<br/>service layer<br/>[api.ts]"]
end

subgraph group_backend["Off-chain Backend"]
  node_server_api["API server<br/>Express API<br/>[server.js]"]
  node_db_schema[("Database schema<br/>sql schema<br/>[init.sql]")]
  node_uploads["Uploads<br/>file storage"]
  node_serverless_api["Serverless API<br/>edge/api"]
end

subgraph group_chain["Blockchain Workspace"]
  node_registry_token["Registry + token<br/>smart contracts"]
  node_deploy_workspace["Deploy workspace<br/>hardhat ops"]
  node_sepolia_state["Sepolia state<br/>deployment state<br/>[sepolia.json]"]
end

subgraph group_infra["Deployment Infra"]
  node_infra_container["Containers<br/>docker<br/>[docker-compose.yml]"]
  node_infra_proxy["Proxy/hosting<br/>nginx/vercel<br/>[nginx.conf]"]
end

node_tests["Validation<br/>tests<br/>[vitest.config.ts]"]

node_app_shell -->|"wraps"| node_role_access
node_app_shell -->|"renders"| node_ui_pages
node_ui_pages -->|"composes"| node_ui_components
node_ui_pages -->|"connects"| node_wallet_layer
node_wallet_layer -->|"feeds"| node_chain_context
node_chain_context -->|"uses"| node_abi_addresses
node_chain_context -->|"calls"| node_registry_token
node_ui_pages -->|"fetches"| node_api_clients
node_api_clients -->|"requests"| node_server_api
node_server_api -->|"persists"| node_db_schema
node_server_api -->|"stores"| node_uploads
node_serverless_api -.->|"serves"| node_db_schema
node_deploy_workspace -->|"builds"| node_registry_token
node_deploy_workspace -->|"records"| node_sepolia_state
node_ui_pages -->|"triggers"| node_registry_token
node_ui_pages -->|"hydrates"| node_server_api
node_infra_container -->|"runs"| node_server_api
node_infra_proxy -->|"serves"| node_app_shell
node_infra_proxy -.->|"routes"| node_serverless_api
node_tests -.->|"verifies"| node_app_shell
node_tests -.->|"verifies"| node_deploy_workspace

click node_app_shell "https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/src/App.tsx"
click node_role_access "https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/src/contexts/RoleAuthContext.tsx"
click node_ui_pages "https://github.com/08pranav/blue-carbon-registry-blockchain/tree/main/src/pages"
click node_ui_components "https://github.com/08pranav/blue-carbon-registry-blockchain/tree/main/src/components"
click node_wallet_layer "https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/src/components/ConnectWalletButton_Wagmi.tsx"
click node_chain_context "https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/src/contexts/BlockchainContext.tsx"
click node_abi_addresses "https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/src/contracts/addresses.json"
click node_api_clients "https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/src/services/api.ts"
click node_server_api "https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/backend/server.js"
click node_db_schema "https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/backend/database/init.sql"
click node_uploads "https://github.com/08pranav/blue-carbon-registry-blockchain/tree/main/backend/uploads"
click node_serverless_api "https://github.com/08pranav/blue-carbon-registry-blockchain/tree/main/api"
click node_registry_token "https://github.com/08pranav/blue-carbon-registry-blockchain/tree/main/blockchain-deployment/contracts"
click node_deploy_workspace "https://github.com/08pranav/blue-carbon-registry-blockchain/tree/main/blockchain-deployment"
click node_sepolia_state "https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/blockchain-deployment/deployments/sepolia.json"
click node_infra_container "https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/docker-compose.yml"
click node_infra_proxy "https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/nginx/nginx.conf"
click node_tests "https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/vitest.config.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_shell,node_role_access,node_ui_pages,node_ui_components,node_wallet_layer,node_chain_context,node_abi_addresses,node_api_clients toneBlue
class node_server_api,node_db_schema,node_uploads,node_serverless_api toneAmber
class node_registry_token,node_deploy_workspace,node_sepolia_state toneMint
class node_infra_container,node_infra_proxy toneRose
class node_tests toneNeutral
```

## Components

### Frontend SPA

React/Vite user application with role-based pages and wallet-connected blockchain actions

- [App shell](https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/src/App.tsx): React SPA · Vite entry, routing, and top-level app composition · `src/App.tsx`
- [Role access](https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/src/contexts/RoleAuthContext.tsx): auth guards · Auth, role context, and protected route boundary · `src/contexts/RoleAuthContext.tsx`
- [Role pages](https://github.com/08pranav/blue-carbon-registry-blockchain/tree/main/src/pages): page layer · NGO, auditor, company, admin, marketplace, registry, submit, and verification screens · `src/pages`
- [UI components](https://github.com/08pranav/blue-carbon-registry-blockchain/tree/main/src/components): shared UI · Reusable dashboards, forms, wallets, maps, and verification widgets · `src/components`
- [Wallet layer](https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/src/components/ConnectWalletButton_Wagmi.tsx): web3 wallet · MetaMask connection and wallet state utilities · `src/components/ConnectWalletButton_Wagmi.tsx`
- [Chain context](https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/src/contexts/BlockchainContext.tsx): web3 bridge · Frontend blockchain context and services wrapping contract access · `src/contexts/BlockchainContext.tsx`
- [ABI/addresses](https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/src/contracts/addresses.json): contract config · Frontend contract ABIs and deployed addresses boundary · `src/contracts/addresses.json`
- [API clients](https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/src/services/api.ts): service layer · 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](https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/backend/server.js): Express API · Standalone backend server for app data and workflows · `backend/server.js`
- [Database schema](https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/backend/database/init.sql): sql schema · Persistent off-chain tables for profiles, submissions, and operational data · `backend/database/init.sql`
- [Uploads](https://github.com/08pranav/blue-carbon-registry-blockchain/tree/main/backend/uploads): file storage · Stored project documents and other uploaded artifacts · `backend/uploads`
- [Serverless API](https://github.com/08pranav/blue-carbon-registry-blockchain/tree/main/api): edge/api · Root API entrypoints for hosted deployment environments · `api`

### Blockchain Workspace

Hardhat contracts and deployment operations for Sepolia

- [Registry + token](https://github.com/08pranav/blue-carbon-registry-blockchain/tree/main/blockchain-deployment/contracts): smart contracts · BlueCarbonRegistry orchestration contract and BlueCarbonCredits ERC-20 token · `blockchain-deployment/contracts`
- [Deploy workspace](https://github.com/08pranav/blue-carbon-registry-blockchain/tree/main/blockchain-deployment): hardhat ops · Hardhat config, scripts, cache, artifacts, and Sepolia deployment state · `blockchain-deployment`
- [Sepolia state](https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/blockchain-deployment/deployments/sepolia.json): deployment state · Deployed addresses and network state for the testnet environment · `blockchain-deployment/deployments/sepolia.json`

### Deployment Infra

Container, proxy, and hosting configuration

- [Containers](https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/docker-compose.yml): docker · Repository containerization for app and backend services · `docker-compose.yml`
- [Proxy/hosting](https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/nginx/nginx.conf): nginx/vercel · Reverse proxy and SPA hosting rewrites for deployment · `nginx/nginx.conf`

### Other components

- [Validation](https://github.com/08pranav/blue-carbon-registry-blockchain/blob/main/vitest.config.ts): tests · Frontend and chain validation harnesses across the stack · `vitest.config.ts`

## Connections

- 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
