# shreya64684/te_mini_project architecture

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

- Interactive diagram: https://gitdiagram.com/shreya64684/te_mini_project
- Repository: https://github.com/shreya64684/te_mini_project

## Overview

##### Project Overview
- This project is a full-stack application that integrates a React-based frontend (bootstrapped via Create React App) with a Node.js/Express backend. In addition to traditional REST API components, the project also incorporates blockchain smart contracts (via Truffle) and Web3 interactions, suggesting it’s a decentralized application (dApp) focused on carbon footprint tracking (and possibly related data like fuel, raw materials, logistics, waste, etc.).

a. Frontend:
- React application. Indicate major areas like UI components (dashboards, forms, company selection, etc.), utilities (IPFS integration, web3Setup), and API interactions.
- That it handles user input, dashboard rendering, and communicates with the backend through API calls.

b. Backend:
- Node.js/Express server divided into MVC-like structure:
- Routes: For authentication and various domain-specific resources (fuel, goods and services, raw material, waste, logistics, etc.).
- Controllers: Manage business logic for various data submissions.
- Models: Represent entities such as Company, User, FuelData, WasteData etc. which likely interact with a database.
- Middlewares: For authentication, ensuring secure API endpoints.

c. Blockchain Integration:
- A separate block for smart contracts:
- Truffle directory: Highlight contracts (CarbonFootprint, UserRoleManagement) and migrations.
- Web3 setup usage in the frontend (in src/utils) and any contract artifacts in src/contracts.
- How the backend or frontend uses these smart contracts for blockchain interactions.

d. External Services & Storage:
- If relevant, include an IPFS node or service as indicated by the src/ipfs.js file. This suggests files or data may be stored via IPFS, so show a link from the frontend (or backend) to an external IPFS storage/service.

e. Additional Components:
- Optionally, include basic infrastructure components like hosting, deployment services, and a potential load balancer if this application were to be deployed at scale. Even though these aren’t directly shown, they help provide context.

##### Relationships and Data Flow
- User Activities: User interaction with the React UI.
- API Calls: The React frontend sends HTTP requests to the Express backend.
- Business Logic: Within the backend, requests are processed via controllers which interact with the database (for persistence) and sometimes invoke blockchain transactions using Web3.

##### Highlighting Architectural Patterns and Technologies
- Underline that the backend follows the MVC (Model-View-Controller) pattern, as seen with categorized directories (controllers, models, routes).
- That the application is split into clearly defined layers (presentation, business logic, persistence) and extends with blockchain integration via a smart contract layer.
- That the frontend is built with React and uses functional components (hooks) and routing to offer different dashboards (Admin, Company, Electricity, etc.).
- Mention the key frameworks and libraries such as Express (backend), React (frontend), Truffle & Web3 (for blockchain), and possibly a database connector (from config/db.js).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Global Entities
    User("User"):::external

    %% Frontend Layer
    subgraph "Frontend Layer"
        FE1["React App"]:::frontend
        FE2["Static Assets"]:::frontend
        UI["UI Components"]:::frontend
        PC["Page Components"]:::frontend
        API["API Layer (Frontend)"]:::frontend
        WS["Web3 Setup"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE["Server Entry"]:::backend
        ROUTES["Routes"]:::backend
        CTRLS["Controllers"]:::backend
        MODELS["Models"]:::backend
        MIDD["Middlewares"]:::backend
        DBC["DB Config"]:::backend
        DB[(Database)]:::database
    end

    %% Blockchain Layer
    subgraph "Blockchain Layer"
        TP["Truffle Project"]:::blockchain
        TC["Truffle Contracts"]:::blockchain
        MIG["Migrations"]:::blockchain
        CA["Contract Artifacts"]:::blockchain
    end

    %% External Services
    subgraph "External Services"
        IPFS["IPFS Service"]:::external
    end

    %% Relationships
    User -->|"uses"| FE1
    FE1 -->|"composes"| UI
    FE1 -->|"composes"| PC
    FE1 -->|"handles"| API
    FE1 -->|"configures"| WS
    FE1 -->|"serves"| FE2

    API -->|"HTTP Call"| BE
    BE -->|"routes to"| ROUTES
    ROUTES -->|"calls"| CTRLS
    CTRLS -->|"manipulates"| MODELS
    CTRLS -->|"applies"| MIDD
    MODELS -->|"CRUD Operations"| DB
    BE -->|"invokes"| CA
    WS -->|"calls"| CA

    TP -->|"defines"| TC
    TP -->|"executes"| MIG
    TC -->|"generates"| CA

    FE1 -->|"IPFS Transfer"| IPFS

    %% Click Events - Frontend
    click FE1 "https://github.com/shreya64684/te_mini_project/tree/main/src/"
    click FE2 "https://github.com/shreya64684/te_mini_project/tree/main/public/"
    click UI "https://github.com/shreya64684/te_mini_project/tree/main/src/components/"
    click PC "https://github.com/shreya64684/te_mini_project/tree/main/src/pages/"
    click API "https://github.com/shreya64684/te_mini_project/blob/main/src/api.js"
    click WS "https://github.com/shreya64684/te_mini_project/blob/main/src/utils/web3Setup.js"

    %% Click Events - Backend
    click BE "https://github.com/shreya64684/te_mini_project/blob/main/backend/app.js"
    click ROUTES "https://github.com/shreya64684/te_mini_project/tree/main/backend/routes/"
    click CTRLS "https://github.com/shreya64684/te_mini_project/tree/main/backend/controllers/"
    click MODELS "https://github.com/shreya64684/te_mini_project/tree/main/backend/models/"
    click MIDD "https://github.com/shreya64684/te_mini_project/tree/main/backend/middlewares/"
    click DBC "https://github.com/shreya64684/te_mini_project/blob/main/backend/config/db.js"

    %% Click Events - Blockchain
    click TP "https://github.com/shreya64684/te_mini_project/tree/main/truffle/"
    click TC "https://github.com/shreya64684/te_mini_project/tree/main/truffle/contracts/"
    click MIG "https://github.com/shreya64684/te_mini_project/tree/main/truffle/migrations/"
    click CA "https://github.com/shreya64684/te_mini_project/tree/main/src/contracts/"

    %% Click Events - External Services
    click IPFS "https://github.com/shreya64684/te_mini_project/blob/main/src/ipfs.js"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef backend fill:#A9DFBF,stroke:#28B463,stroke-width:2px;
    classDef database fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef blockchain fill:#F5CBA7,stroke:#E67E22,stroke-width:2px;
    classDef external fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
```
