# amandeep4567/carbon-crunch architecture

> Architecture diagram of the GitHub repository amandeep4567/carbon-crunch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amandeep4567/carbon-crunch
- Repository: https://github.com/amandeep4567/carbon-crunch

## Overview

##### Project type and purpose
- Carbon-Crunch is a full-stack decentralized application (dApp) built with Next.js (React) for the front end and Hardhat/Ethers.js for blockchain integration.
- It tokenizes carbon credits into ERC-20/ERC-721-like tokens, features “stacking” mechanisms (staking) and user-facing games to boost engagement and liquidity in the Carbon Market.

##### File structure
- Top-level directories:
- Components/ – React UI components
- Context/ – React Context providers for on-chain data and sale parameters
- pages/ – Next.js page routes (_app.js, index.js)
- public/ & styles/ – static assets (CSS, fonts, JS libraries)
- contracts/ – Solidity smart contracts
- scripts/ – deployment scripts (scripts/deploy.js)
- test/ – Hardhat tests (test/Lock.js)
- Utils/ – shared JavaScript helpers (e.g., formatting, API calls)
- Configuration files: hardhat.config.js, next.config.js, package.json

##### README for additional insights
- The README highlights three pillars: tokenized credits, user games, stacking/discounts.
- No pre-drawn architecture is provided, so we’ll capture front-end, blockchain, testing, and deployment flows.

##### Elements
– Labels: “User Browser”, “Next.js Frontend”, “React Context”, “Ethers.js RPC Provider”, “Ethereum Node”, “Smart Contracts”
- User → Frontend (UI events)
- Frontend → Context → Ethers.js (function calls)
- Ethers.js → Ethereum Node (JSON-RPC)
- Ethereum Node ↔ Smart Contracts (state changes, events)
- Deployment Script → Ethereum Node → Smart Contracts
- UI components in blue rectangles
- Context and utils in green rectangles
- Blockchain integration (Ethers.js, Hardhat) in orange
- Smart contracts and Ethereum node in gray

##### Detail without overthinking
- Both runtime interactions (user flows) and development/deployment processes.
- The goal is a comprehensive, accurate depiction of how the dApp’s front end, blockchain contracts, and deployment pipeline fit and work together.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User["User Browser"]:::external

    %% Frontend Layer
    subgraph "Next.js Frontend"
        direction TB
        subgraph "Pages Layer" 
            direction TB
            App["_app.js"]:::ui
            IndexPage["index.js"]:::ui
        end
        subgraph "UI Components"
            direction TB
            CompIndex["index.js"]:::ui
            About["About.jsx"]:::ui
            ArrowUp["ArrowUp.jsx"]:::ui
            Banner["Banner.jsx"]:::ui
            Blog["Blog.jsx"]:::ui
            Client["Client.jsx"]:::ui
            Contact["Contact.jsx"]:::ui
            Distribution["Distribution.jsx"]:::ui
            Faq["Faq.jsx"]:::ui
            Footer["Footer.jsx"]:::ui
            Header["Header.jsx"]:::ui
            Loader["Loader.jsx"]:::ui
            MobileApp["MobileApp.jsx"]:::ui
            Service["Service.jsx"]:::ui
            Team["Team.jsx"]:::ui
            TimeLine["TimeLine.jsx"]:::ui
            TokenSaleComp["TokenSale.jsx"]:::ui
        end
        subgraph "React Context & ABIs"
            direction TB
            ContextIndex["index.js"]:::context
            Constants["constants.js"]:::context
            TBCodersJSON["TheBlockchainCoders.json"]:::context
            TokenSaleJSON["TokenSale.json"]:::context
        end
        Utils["Utils/index.js"]:::context
    end

    %% Blockchain Integration
    subgraph "Blockchain Integration"
        direction TB
        Ethers["Ethers.js RPC Provider"]:::blockchain
        subgraph "Ethereum Network"
            direction TB
            EthNode["Ethereum Node\n(Infura/Alchemy or Hardhat Local)"]:::contract
            Contracts["Smart Contracts\n(contracts/*.sol)"]:::contract
        end
    end

    %% Development & Deployment
    subgraph "Dev & Deployment"
        direction TB
        HardhatConfig["hardhat.config.js"]:::blockchain
        DeployScript["scripts/deploy.js"]:::blockchain
        Tests["test/Lock.js"]:::blockchain
        NextConfig["next.config.js"]:::blockchain
        PackageJSON["package.json\npackage-lock.json"]:::blockchain
    end

    %% Connections
    User -->|"loads pages"| App
    App -->|"renders"| IndexPage
    IndexPage -->|"uses components"| CompIndex
    CompIndex --> About
    CompIndex --> ArrowUp
    CompIndex --> Banner
    CompIndex --> Blog
    CompIndex --> Client
    CompIndex --> Contact
    CompIndex --> Distribution
    CompIndex --> Faq
    CompIndex --> Footer
    CompIndex --> Header
    CompIndex --> Loader
    CompIndex --> MobileApp
    CompIndex --> Service
    CompIndex --> Team
    CompIndex --> TimeLine
    CompIndex --> TokenSaleComp

    About --> ContextIndex
    ArrowUp --> ContextIndex
    Banner --> ContextIndex
    Blog --> ContextIndex
    Client --> ContextIndex
    Contact --> ContextIndex
    Distribution --> ContextIndex
    Faq --> ContextIndex
    Footer --> ContextIndex
    Header --> ContextIndex
    Loader --> ContextIndex
    MobileApp --> ContextIndex
    Service --> ContextIndex
    Team --> ContextIndex
    TimeLine --> ContextIndex
    TokenSaleComp --> ContextIndex

    ContextIndex --> Constants
    ContextIndex --> TBCodersJSON
    ContextIndex --> TokenSaleJSON
    ContextIndex --> Utils

    ContextIndex -->|"web3 calls"| Ethers
    Utils -->|"helpers"| Ethers

    Ethers -->|"JSON-RPC"| EthNode
    EthNode -->|"deploy/interact"| Contracts
    Contracts -->|"events/state"| EthNode
    EthNode -->|"events"| Ethers

    DeployScript -->|"deploys contracts"| EthNode
    Tests -->|"tests on"| EthNode
    HardhatConfig --> DeployScript
    HardhatConfig --> Tests

    %% Click Events
    click App "https://github.com/amandeep4567/carbon-crunch/blob/main/pages/_app.js"
    click IndexPage "https://github.com/amandeep4567/carbon-crunch/blob/main/pages/index.js"
    click CompIndex "https://github.com/amandeep4567/carbon-crunch/blob/main/Components/index.js"
    click About "https://github.com/amandeep4567/carbon-crunch/blob/main/Components/About.jsx"
    click ArrowUp "https://github.com/amandeep4567/carbon-crunch/blob/main/Components/ArrowUp.jsx"
    click Banner "https://github.com/amandeep4567/carbon-crunch/blob/main/Components/Banner.jsx"
    click Blog "https://github.com/amandeep4567/carbon-crunch/blob/main/Components/Blog.jsx"
    click Client "https://github.com/amandeep4567/carbon-crunch/blob/main/Components/Client.jsx"
    click Contact "https://github.com/amandeep4567/carbon-crunch/blob/main/Components/Contact.jsx"
    click Distribution "https://github.com/amandeep4567/carbon-crunch/blob/main/Components/Distribution.jsx"
    click Faq "https://github.com/amandeep4567/carbon-crunch/blob/main/Components/Faq.jsx"
    click Footer "https://github.com/amandeep4567/carbon-crunch/blob/main/Components/Footer.jsx"
    click Header "https://github.com/amandeep4567/carbon-crunch/blob/main/Components/Header.jsx"
    click Loader "https://github.com/amandeep4567/carbon-crunch/blob/main/Components/Loader.jsx"
    click MobileApp "https://github.com/amandeep4567/carbon-crunch/blob/main/Components/MobileApp.jsx"
    click Service "https://github.com/amandeep4567/carbon-crunch/blob/main/Components/Service.jsx"
    click Team "https://github.com/amandeep4567/carbon-crunch/blob/main/Components/Team.jsx"
    click TimeLine "https://github.com/amandeep4567/carbon-crunch/blob/main/Components/TimeLine.jsx"
    click TokenSaleComp "https://github.com/amandeep4567/carbon-crunch/blob/main/Components/TokenSale.jsx"
    click ContextIndex "https://github.com/amandeep4567/carbon-crunch/blob/main/Context/index.js"
    click Constants "https://github.com/amandeep4567/carbon-crunch/blob/main/Context/constants.js"
    click TBCodersJSON "https://github.com/amandeep4567/carbon-crunch/blob/main/Context/TheBlockchainCoders.json"
    click TokenSaleJSON "https://github.com/amandeep4567/carbon-crunch/blob/main/Context/TokenSale.json"
    click Utils "https://github.com/amandeep4567/carbon-crunch/blob/main/Utils/index.js"
    click DeployScript "https://github.com/amandeep4567/carbon-crunch/blob/main/scripts/deploy.js"
    click Tests "https://github.com/amandeep4567/carbon-crunch/blob/main/test/Lock.js"
    click HardhatConfig "https://github.com/amandeep4567/carbon-crunch/blob/main/hardhat.config.js"
    click NextConfig "https://github.com/amandeep4567/carbon-crunch/blob/main/next.config.js"
    click PackageJSON "https://github.com/amandeep4567/carbon-crunch/blob/main/package.json"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef context fill:#DFFFD0,stroke:#2E7D32,color:#2E7D32
    classDef blockchain fill:#FFE0B2,stroke:#EF6C00,color:#E65100
    classDef contract fill:#E0E0E0,stroke:#616161,color:#424242
    classDef external fill:#FFFFFF,stroke:#000000,color:#000000,stroke-dasharray: 2 2
```
