A comprehensive microservices-based electronic voting system built with Ballerina and Next.js, featuring real-time monitoring, census management, and AI-powered support.
This system follows a microservices architecture with the following components:
- API Gateway - Central routing and authentication hub
- Auth Service - User authentication and authorization
- Election Service - Election and candidate management
- Voter Service - Voting operations and voter check-in
- Support Service - AI-powered chatbot support
- Census Service - Population census management
- Client Application - Next.js frontend with real-time UI
- Ballerina (Swan Lake Update 8 or later)
- Node.js (20+ recommended)
- npm or yarn
- Docker (optional, for containerized deployment)
git clone https://github.com/PS3stack/ps3stack-ballerina-competition.git
cd ps3stack-ballerina-competition# Start all microservices (run each in a separate terminal)
# Auth Service
cd ../services/auth_service
bal run
# Election Service
cd ../election_service
bal run
# Voter Service
cd ../voter_service
bal run
# Support Service
cd ../support_service
bal run
# Census Service
cd ../census_service
bal run
# API Gateway
cd api_gateway
bal run
# After running the API Gateway you can see the microservices are up and running.cd client
npm install
npm run dev- Frontend: http://localhost:3000
- API Gateway: http://localhost:8080
- Individual Services: See service-specific README files
The Support Service requires an OpenAI API key for AI-powered chatbot functionality:
-
Obtain OpenAI API Key:
- Visit OpenAI Platform
- Create an account or sign in
- Navigate to "API Keys" section
- Click "Create new secret key"
- Copy the generated key (starts with
sk-)
-
Configure the Key:
- Navigate to
services/support_service/ - Copy
Config.toml.exampletoConfig.toml - Replace the placeholder with your actual API key:
HTTP_PORT = 8083 OPENAI_API_KEY = "your-actual-openai-api-key-here"
- Navigate to
Each service includes .toml.example files with placeholder values. Copy these to the actual config files and replace placeholders with real values:
api_gateway/Config.toml.exampleβConfig.tomlservices/*/Config.toml.exampleβConfig.tomlclient/.env.exampleβ.env.local
Important: Never commit actual API keys to version control. The .example files are safe to commit as they contain only placeholders.
This project includes a pre-configured database dump with sample data including elections, candidates, and user accounts.
Database Dump Location: database/database.bak
To repopulate your Neon database with the sample data:
pg_restore -v -d "<neon_database_connection_string>" database/database.bakExample:
pg_restore -v -d "postgresql://username:password@host:5432/database?sslmode=require" database/database.bakThe database dump includes:
- Sample Elections: Pre-configured elections with candidates and photos
- User Accounts: Demo accounts for all user roles (admin, observer, field staff, polling staff, voters)
- Census Data: Sample population and household records
- System Configuration: Initial setup for all microservices
If you prefer to set up the database manually, each service includes:
- Schema definitions in service README files
- Migration scripts in
database_migration.sqlfiles - Sample data creation in service initialization code
Note: The database connection strings are configured in each service's Config.toml file.
| Component | Port | Description |
|---|---|---|
| API Gateway | 8080 | Central routing, authentication, CORS handling |
| Auth Service | 8085 | JWT authentication, role-based access |
| Election Service | 8082 | Election management, candidates, observers |
| Voter Service | 8084 | Voting operations, voter check-in |
| Support Service | 8083 | AI chatbot, help system |
| Census Service | 8081 | Population census, household management |
| Client App | 3000 | Next.js frontend application |
- Full system access
- Election management
- User management
- System monitoring
- Demo Login: admin@test.com / password123
- Election monitoring
- Results viewing
- Report generation
- Census data collection
- Household surveys
- Area assignments
- Voting operations
- Voter check-in
- Ballot management
- JWT Authentication with secure token validation
- Role-based Access Control (RBAC)
- CORS Protection for cross-origin requests
- Input Validation and sanitization
- Secure Cookie handling
- API Rate Limiting (configurable)
POST /api/auth/admin/login # Admin authentication
POST /api/auth/observer/login # Observer authentication
POST /api/auth/field_staff/login # Field staff authentication
POST /api/auth/polling_staff/login # Polling staff authentication
GET /api/election # List elections
POST /api/election # Create election
GET /api/election/{id} # Get election details
POST /api/voters/cast # Cast vote
POST /api/voters/check-in # Voter check-in
POST /api/support/chat # AI chatbot
GET /api/support/health # Service health
GET /api/census # Census projects
POST /api/census # Create census project
See individual service README files for complete API documentation.
| Role | Password | Access Level | |
|---|---|---|---|
| Admin | admin@test.com | password123 | Full system access |
| Observer | observer@test.com | password123 | Read-only monitoring |
| Field Staff | field@test.com | password123 | Census operations |
| Polling Staff | polling@test.com | password123 | Voting operations |
# Check all services
curl http://localhost:8080/health
# Individual service health
curl http://localhost:8085/auth/health
curl http://localhost:8082/election/health
curl http://localhost:8084/voters/health
curl http://localhost:8083/support/health
curl http://localhost:8081/census/healthps3stack-ballerina-competition/
βββ api_gateway/ # API Gateway service
βββ services/ # Microservices
β βββ auth_service/ # Authentication service
β βββ election_service/ # Election management
β βββ voter_service/ # Voting operations
β βββ support_service/ # AI support system
β βββ census_service/ # Census management
βββ client/ # Next.js frontend
βββ docs/ # Documentation
- Backend Development: Modify Ballerina services in
services/orapi_gateway/ - Frontend Development: Work in
client/directory - Testing: Use the demo accounts for end-to-end testing
- API Testing: Use tools like Postman or curl for API testing
All services use Config.toml files for configuration:
- Copy
.toml.examplefiles toConfig.toml - Set appropriate values for your environment
- Never commit actual API keys or sensitive data
# Build and run with Docker Compose
docker-compose up --build- Build each Ballerina service:
cd services/auth_service && bal build
cd ../election_service && bal build
# ... repeat for each service- Build frontend:
cd client && npm run build- Deploy to your hosting platform of choice
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- AI Support: Use the built-in chatbot (accessible after login)
- Issues: Create a GitHub issue for bugs or feature requests
- Documentation: Check individual service README files
- Community: Join our development community
- Built for the Ballerina Programming Competition
- Powered by Ballerina Swan Lake
- Frontend built with Next.js and Tailwind CSS
- AI features powered by OpenAI
PS3Stack Team - Building the future of democratic technology

