This repository contains the source code for the voting system used for DUCSS Elections 2023. It was built on top of the Next.js framework and uses Prisma as an ORM for the database. The databases used were PostgreSQL for deployed instances and SQLite for offline instances.
- Authentication using a list of email addresses in database
- Voting for candidates running for various posts
- Visualization results of the election
- Visualization of list of students who have voted
- Support for multiple courses and sections
- TODO: Support for multiple elections
- A voter can vote for only one candidate for a post
- A voter can vote only once and cannot change their vote
- The list of students who can vote is stored in the
User
table in the database - The list of candidates running for various posts is stored in the
Candidate
table in the database - The list of votes casted by students is stored in the
Vote
table in the database
These routes are accessible only when a secret
is provided as a query parameter defined in the environment variable NEXT_PUBLIC_SECRET
.
- The list of students who have voted can be viewed at
/list
route - The statistics of the election can be viewed at
/stats
route only when asecret
is provided as a query parameter defined in the environment variableNEXT_PUBLIC_SECRET
- Node.js v20+
- Yarn Package Manager
- PostgreSQL / SQLite
- Clone the repository and navigate to the directory
$ git clone https://github.com/sudiptog81/ducs-voting-system
$ cd ducs-voting-system
- Install dependencies
$ yarn install --include=dev
- Create a
.env
file in the root directory and add the following environment variables
DATABASE_URL="postgresql://<username>:<password>@<host>:<port>/<database>?schema=public" # For PostgreSQL
DATABASE_URL="file:./dev.db" # For SQLite
NEXT_PUBLIC_SECRET="...secret used for stats and list pages..."
NEXTAUTH_SECRET="...secret used for authentication..."
- Run the migrations
$ yarn prisma migrate reset
$ yarn prisma db push
- Run the development server
$ yarn dev
- Start the database interface
$ yarn prisma studio
- Build the application
$ yarn build
- Start the application
$ yarn start
-
Create a new project on Vercel and link it to the GitHub repository
-
Add the following environment variables
DATABASE_URL="postgresql://<user>:<pass>@<host>:<port>/<db>" # For PostgreSQL
NEXT_PUBLIC_SECRET="...secret used for stats and list pages..."
NEXTAUTH_SECRET="...secret used for authentication..."
- Redeploy the application on Vercel
Distributed under the MIT License. See LICENSE.md
for more information.
Sudipto Ghosh
Postgraduate Student
Department of Computer Science
Faculty of Mathematical Sciences
University of Delhi