How mehtaansh/blockchainvoting works
Project type and purpose
• This is a full-stack, blockchain-enabled E-voting system.
• Frontend: Next.js + Semantic UI React pages/components.
• Backend: Express.js + MongoDB + Mongoose models + controllers + routes.
• Blockchain: Solidity smart contracts deployed to an Ethereum network (e.g., Rinkeby) and accessed via Web3/MetaMask.
• File storage: IPFS for images.
• External services: Email (via SMTP credentials in ENV).
a. Client Browser
• Houses the Next.js React UI and the MetaMask extension.
b. Frontend Server (Next.js)
• Renders pages under /pages and uses components under /components.
• next.config.js configures it.
c. Backend API Server (Express)
• Defined in server.js, controllers/, routes/, models/.
• Exposes REST endpoints for candidate, company, voter (routes/candidate.js, etc.).
d. Database (MongoDB)
• Configured in config/database.js
• Stores user records, company data, voter data.
e. Blockchain Network (Ethereum)
• Smart contracts (Election.sol, ElectionFact.sol → compiled artifacts in Ethereum/Build).
• Deployment and interaction scripts: Ethereum/compile.js, deploy.js, election.js, election_factory.js, web3.js.
f. IPFS Network
• ipfs.js handles file uploads to IPFS.
g. Email Service
• External SMTP (EMAIL, PASSWORD from .env) used by controllers to notify candidates/voters.
Relationships and data flows
• Client → Next.js Frontend: HTTP(S) request for UI pages.
• Frontend → Express API: AJAX/Fetch calls to endpoints defined in routes.js.
• Frontend → Ethereum Network: Web3 calls through MetaMask for voting transactions (vote(), getResults(), etc.).
• Express API → MongoDB: Mongoose models perform CRUD on company, voter, candidate collections.
• Express API → IPFS: Upload candidate images or other assets.
• Express API → Email Service: Send registration and result notifications.
• Express API (optional) → Ethereum Network: Administrative functions (election creation/deployment via deployment scripts).
Architectural patterns and principles
• MVC-style backend: models/ → controllers/ → routes/ → server.js.
• Separation of concerns:
• Presentation (Next.js)
• API/Business Logic (Express)
• Data Layer (MongoDB)
• Blockchain Layer (Solidity contracts + Web3)
• Storage Layer (IPFS)
• External Integrations (SMTP email)
• Hybrid deployment: Next.js and Express run in a single Node process (server.js loads both).
• Smart contract code is decoupled in its own directory (Ethereum/).