How krish-depani/decentralized-voting-system works
Project Type and Purpose
• This is a full-stack decentralized voting dApp.
• Purpose: Provide a secure, transparent voting process by combining a web frontend, a Node.js server, a blockchain layer (Ethereum contracts), a Python microservice for authentication, and a MySQL database.
File Structure
– Top-level “index.js” (Node.js web server serving static assets & possibly proxying API calls)
– “src/” (static frontend: HTML, CSS, JS bundled via Browserify)
– “contracts/”, “migrations/”, “truffle-config.js” (smart contract source + deployment scripts)
– “Database_API/main.py” (FastAPI microservice for JWT-based auth against MySQL)
– “public/” (images, screenshots)
– Configuration: “.env” files for DB & blockchain endpoints
README for Technical Stack
– Frontend: HTML/CSS/JS, Browserify
– Backend #1: Node.js (serves UI, orchestrates contract interactions)
– Backend #2: FastAPI (Python) for authentication & JWT, talking to MySQL
– Blockchain: Ethereum (Ganache local network), Truffle for compile/migrate, Web3.js & MetaMask
– Database: MySQL on port 3306
Main Components & Relationships
a. Frontend (Client Browser)
• HTML/CSS/JS bundles (login, admin, voter pages)
• MetaMask extension injects Web3 provider
• Interacts via HTTP(S) to Node.js server for static assets & any REST endpoints
• Interacts via Web3 calls to Ethereum network for voting transactions
b. Node.js Server (index.js)
• Serves frontend assets on port 8080
• May proxy or forward authentication requests to FastAPI
• Hosts any server-side logic (e.g., serve API keys, config)
c. Database API Service (FastAPI)
• Exposes REST endpoints for login/auth
• Validates credentials against MySQL, issues JWT tokens
d. MySQL Database
• Stores voter records (voter_id, role, password hash)
e. Ethereum Blockchain (Ganache local)
• Runs a local Ethereum node
• Hosts deployed Voting.sol contracts
• Listens on RPC (http://localhost:7545)
f. Truffle Suite
• Manages contract compilation & migrations
• Configuration via truffle-config.js
Architectural Patterns & Design Principles
– Microservices: Node.js web server separated from FastAPI auth service
– Decentralized layer: Client-side Web3 interactions with smart contracts
– Stateless JWT auth between client & DB API
– Clear separation of concerns: UI vs. business logic vs. data layer vs. blockchain layer