Skip to content

oghacker001/AGORA-PROXIMA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎉 AGORA - Blockchain Voting Platform - COMPLETE

✅ Project Status: FULLY FUNCTIONAL

Your blockchain-powered voting platform is now complete with full integration between frontend, backend, and blockchain!

🏗️ System Architecture

Components

  1. Frontend (Next.js) - Port 3000
  2. Backend (Express + TypeScript) - Port 5000
  3. Database (MongoDB Atlas)
  4. Blockchain (Hardhat Local Network) - Port 8545

🔑 Pre-configured Admin Accounts

Admin Account

  • Unique ID: ADMIN-AGR-001
  • Phone: 8888888001
  • MPIN: 1234
  • Role: Admin (can verify users)

Election Commission Account

  • Unique ID: EC-AGR-001
  • Phone: 7777777001
  • MPIN: 1234
  • Role: Election Commission (can create elections)

🚀 How to Run

1. Start Hardhat Blockchain Node

cd blockchain
npx hardhat node

Keep this terminal running. It provides the local Ethereum network.

2. Start Backend Server

cd server
npm run dev

Backend runs on http://localhost:5000

3. Start Frontend

cd client
npm run dev

Frontend runs on http://localhost:3000

📋 Complete User Flows

Flow 1: Admin Login

  1. Go to http://localhost:3000/auth
  2. Enter Unique ID: ADMIN-AGR-001
  3. Click "Request OTP"
  4. Check backend console for OTP (6-digit code)
  5. Enter OTP and MPIN: 1234
  6. ✅ Logged in as Admin

Flow 2: Voter Registration

  1. Click "Register" tab on auth page
  2. Fill registration form with:
    • Full name
    • Phone (10 digits)
    • Email
    • Aadhaar (12 digits)
    • Address
    • Age
    • Voter ID
  3. Upload Aadhaar Card PDF
  4. Upload Voter ID Card PDF
  5. Submit registration
  6. ✅ Registration pending admin approval

Flow 3: Admin Verifies User

  1. Login as Admin
  2. Go to Admin Dashboard → Pending Users
  3. Review user documents
  4. Click "Verify User"
  5. Set initial MPIN for user (4 digits)
  6. ✅ User verified, SBT token issued on blockchain
  7. User receives unique ID (format: AGR-XXXXXXX)

Flow 4: Election Commission Creates Election

  1. Login as EC (EC-AGR-001)
  2. Go to EC Dashboard → Create Election
  3. Fill election details:
    • Title
    • Description
    • Start Date
    • End Date
    • Parties (name, symbol, manifesto)
  4. Click "Create Election"
  5. ✅ Election created in MongoDB AND blockchain

Flow 5: Verified User Votes

  1. User logs in with their unique ID
  2. See active elections
  3. Select an election
  4. Review party manifestos
  5. Cast vote for preferred party
  6. ✅ Vote recorded in MongoDB AND blockchain (immutable)

🔐 Blockchain Integration Points

1. User Verification (SBT Issuance)

When: Admin verifies a user What Happens:

  • User gets blockchain wallet address
  • Non-transferable SBT (Soulbound Token) issued
  • Token stored in User document
  • Contract: 0x5FbDB2315678afecb367f032d93F642f64180aa3

2. Election Creation

When: EC creates election What Happens:

  • Election details stored on blockchain
  • Transaction hash saved in MongoDB
  • Immutable record of election parameters
  • Contract: 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512

3. Vote Casting

When: User votes in election What Happens:

  • Vote recorded in MongoDB (fast query)
  • Vote recorded on blockchain (immutable proof)
  • Double-vote prevention at both layers
  • Transaction hash stored with vote

🔍 Verify Blockchain Data

Check Contract Addresses

// In Node.js console or browser console
const deployments = require('./blockchain/deployments/localhost.json')
console.log('SBT Contract:', deployments.contracts.SBT)
console.log('Voting Contract:', deployments.contracts.VotingContract)

Verify Vote on Blockchain

// Using ethers.js
const { ethers } = require('ethers')
const provider = new ethers.JsonRpcProvider('http://127.0.0.1:8545')
const votingContract = new ethers.Contract(
  '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512',
  VotingABI,
  provider
)

// Check total votes
const totalVotes = await votingContract.getTotalVotes(electionId)
console.log('Total votes on blockchain:', totalVotes.toString())

📊 Database Schema

Users Collection

{
  "uniqueId": "AGR-XXXX",
  "fullName": "string",
  "phone": "string",
  "aadhaar": "string",
  "role": "user|admin|election_commission|voter",
  "mpin": "hashed",
  "walletAddress": "0x...",
  "sbtTokenId": "string",
  "isVerified": true
}

Elections Collection

{
  "title": "string",
  "description": "string",
  "startDate": "Date",
  "endDate": "Date",
  "status": "draft|active|ended",
  "parties": [...],
  "blockchainTxHash": "0x..."
}

Votes Collection

{
  "electionId": "ObjectId",
  "userId": "uniqueId",
  "partyId": "string",
  "votedAt": "Date",
  "blockchainTxHash": "0x..."
}

🎯 Key Features Implemented

✅ Role-based authentication (Admin, EC, Voter) ✅ OTP-based login with MPIN ✅ Document upload for user verification ✅ Blockchain wallet generation per user ✅ Soulbound Token (SBT) for identity ✅ Election creation with blockchain storage ✅ Vote casting with blockchain immutability ✅ Double-vote prevention (DB + Blockchain) ✅ Real-time vote counting ✅ Audit trail via blockchain ✅ Responsive UI with animations

🔧 Environment Variables

Server (.env)

PORT=5000
MONGODB_URI=mongodb+srv://...
JWT_SECRET=your-secret
BLOCKCHAIN_RPC_URL=http://127.0.0.1:8545
SBT_CONTRACT_ADDRESS=0x5FbDB2315678afecb367f032d93F642f64180aa3
VOTING_CONTRACT_ADDRESS=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
ADMIN_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

Client (.env.local)

NEXT_PUBLIC_API_URL=http://localhost:5000/api
NEXT_PUBLIC_DEV_MODE=true
NEXT_PUBLIC_DEV_KEY=agora_dev_2024

🐛 Troubleshooting

Backend Issues

  • Problem: Contract not initialized
  • Solution: Ensure Hardhat node is running and contracts are deployed

Frontend Issues

  • Problem: API calls failing
  • Solution: Check NEXT_PUBLIC_API_URL points to correct backend

Blockchain Issues

  • Problem: Transactions failing
  • Solution: Restart Hardhat node and redeploy contracts

📈 Next Steps (Optional Enhancements)

  1. Email/SMS Services: Real OTP delivery (currently console)
  2. Results Visualization: Charts and graphs for election results
  3. Vote Verification: Let users verify their vote on blockchain
  4. Multiple Elections: Support concurrent elections
  5. Proposal System: Implement proposal voting
  6. Deploy to Testnet: Move from local to Sepolia/Mumbai
  7. Mobile App: React Native version
  8. Advanced Security: Encryption, rate limiting, etc.

🎓 How to Demo

  1. Show Admin Flow: Register → Verify → Show SBT on blockchain
  2. Show EC Flow: Create election → Show on blockchain
  3. Show Voter Flow: Login → Vote → Show vote on blockchain
  4. Show Immutability: Try to vote twice (prevented)
  5. Show Transparency: Query blockchain for vote counts

📞 Support

If you encounter any issues:

  1. Check all three services are running (Frontend, Backend, Blockchain)
  2. Verify environment variables are correct
  3. Check console logs for errors
  4. Ensure MongoDB connection is active

About

PROJECT

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors