How roysubhrajit113/green-pulse-web-app works
Overview of Project Type and Purpose
• Green Pulse is a full-stack energy management platform that combines:
• A Node.js/Express backend exposing a REST API
• A React-based frontend dashboard for data visualization
• A Python/Flask chatbot microservice integrated with Google Gemini AI
• A blockchain layer (Solidity smart contracts, Hardhat, Ethers.js) for energy trading and carbon credits
• MongoDB as the primary data store
• Key use-cases:
• Monitoring carbon footprint and energy consumption
• Tokenized energy trading on-chain
• Gamified dashboard for administrators
• AI-powered user assistance via chatbot
Analyzing File Structure to Identify Components
• Top-level directories:
• backend/ (Express API, controllers, models, services, config, middleware)
• frontend/ (React app, components, contexts, services, assets)
• chatbot/ (Flask service, AI integration)
• contracts/ (Solidity smart contracts, tests, Hardhat config)
• deploy/ & docker-compose.yml (container orchestration)
• Cross-cutting concerns:
• config files and environment variables (.env)
• build/deploy scripts (scripts/, backend/scripts/, Hardhat scripts)
• tests (backend test scripts, contracts tests)
Main Components and Their Interactions
• Frontend (React)
• Hosts UI at http://localhost:3000
• Uses Axios (apiClient.js) to call backend endpoints (/auth, /buildings, /carbonData, /wallet, etc.)
• Renders charts (ApexCharts), forms, menus, and Chatbot widget
• Auth flow via JWT tokens stored in context
• Backend (Node.js/Express + MongoDB)
• Listens on port 5000
• MVC structure:
– Models: Mongoose schemas (User, Building, CarbonData, EnergyConsumption, etc.)
– Controllers: request handlers (authController, carbonDataController, alertController, etc.)
– Services: business logic, blockchainService (Ethers.js), alertService
– Routes: mount REST endpoints
– Middleware: auth, instituteAuth, validation
• Interacts with:
– MongoDB (backend/config/database.js)
– Ethereum network via blockchainService (backend/services/blockchainService.js)
• Chatbot Service (Python/Flask)
• Runs on port 5001
• Exposes REST endpoint for chat requests
• Communicates with Google Gemini AI using GEMINI_API_KEY
• Invoked by frontend Chatbot component (chatbotService.js)
• Blockchain Layer
• Hardhat network for local chain
• Solidity contracts under contracts/ (control, market, lib, test)
• Deploy scripts in scripts/ (deploy.js, trade.js, governance.js, etc.)
• Interaction via Ethers.js in backend and frontend blockchainService modules
• Database
• MongoDB cluster or local instance
• Stores user profiles, institute metadata, carbon metrics, energy transactions
Relationships and Data Flow
1. User ↔ React Frontend
– Login/Signup → calls /auth routes on backend
– Dashboard data fetch → GET /carbonData, /buildings, /meterData
– Blockchain transactions → POST /wallet (calls blockchainService → Ethereum)
– Chat queries → POST to Flask chatbot service → Gemini AI
2. Frontend ↔ Backend
– RESTful calls with JWT in header
– Real-time alerts via polling or websockets (if implemented)
3. Backend ↔ MongoDB
– CRUD operations through Mongoose models
4. Backend ↔ Ethereum network
– Smart contract calls (minting, trading carbon credits) via Ethers.js
5. Deployment
– Docker-Compose orchestrates services: backend, frontend, chatbot, MongoDB, Hardhat node
Architectural Patterns and Principles
• Layered architecture in backend (routes → controllers → services → models)
• Separation of concerns:
• Frontend presentation vs. backend API vs. blockchain logic vs. AI microservice
• Modularization:
• Smart contracts isolated under contracts/ and tested via Hardhat
• Chatbot as a standalone microservice
• Stateless REST API with JWT for authentication
• Context-based state management in React (AuthContext, CarbonContext, etc.)