0% found this document useful (0 votes)
13 views5 pages

Architecture

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

Architecture

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Voter_Service_Architecture_and_Design_Documentation

=====================================================

1. Introduction
===============

This document provides an overview of the architecture and design of the Voter
service. The service is designed to manage
candidate information, allow users to cast votes, and provide insights into voting
results.

2. Architecture Overview
========================

The Voter service follows a microservices architecture, with separate components


handling candidate-related operations,
vote processing, and result retrieval.

3. Components
=============

3.1. Voter Controller


-----------------------

- Responsible for handling HTTP requests and routing them to the appropriate
services.
- Implements the API endpoints for entering candidates, casting votes, counting
votes, listing votes, and retrieving
the winner.

3.2. Candidate Service


-----------------------

- Manages candidate information, including storing candidate names and their


respective vote counts.
- Exposes APIs for entering candidates and retrieving the list of candidates.

3.3. Vote Service


------------------

- Handles the logic for casting votes, counting votes, and determining the
winner.
- Ensures data consistency and integrity during the voting process.

4. Database Schema
===================

- Utilizes a simple schema with tables for candidates and votes.


- Candidate Table:
- Columns: `candidate_id` (Primary Key), `name`, `vote_count`.
- Vote Table:
- Columns: `vote_id` (Primary Key), `candidate_id` (Foreign Key), `voter_id`,
`timestamp`.

5. Sequence Diagrams
=====================

1. Enter Candidate Sequence Diagram:


+---------------------+ +-----------------------+ +----------------+
| Voter Controller | | Candidate Service | | Database |
+---------------------+ +-----------------------+ +----------------+
| | | | | |
| 1. Enter | | | | |
| Candidate | | | | |
|-------------------> | | | | |
| | | | | |
| | | 2. Validate Input | | |
| | |---------------------->| | |
| | | | | |
| | | | | |
| | | 3. Save Candidate | | |
| | |---------------------->| | |
| | | | | |
| | | | | 4. Save to DB |
| | | | |----------------|
| 5. Respond | | | | |
| Result | | | | |
|<------------------- | |<----------------------| | |
| | | | | |
+---------------------+ +-----------------------+ +----------------+

2. Cast Vote Sequence Diagram:


+---------------------+ +-----------------------+ +----------------+
| Voter Controller | | Vote Service | | Database |
+---------------------+ +-----------------------+ +----------------+
| | | | | |
| 1. Cast Vote | | | | |
|-------------------> | | | | |
| | | | | |
| | | 2. Validate Vote | | |
| | |---------------------->| | |
| | | | | |
| | | | | |
| | | 3. Update Vote Count | | |
| | |---------------------->| | |
| | | | | 4. Save to DB |
| | | | |----------------|
| 5. Respond | | | | |
| Result | | | | |
|<------------------- | |<----------------------| | |
| | | | | |
+---------------------+ +-----------------------+ +----------------+

3. Count Vote Sequence Diagram:


+---------------------+ +-----------------------+ +----------------+
| Voter Controller | | Vote Service | | Database |
+---------------------+ +-----------------------+ +----------------+
| | | | | |
| 1. Count Vote | | | | |
|-------------------> | | | | |
| | | | | |
| | | 2. Validate Candidate| | |
| | |---------------------->| | |
| | | | | |
| | | | | |
| | | 3. Retrieve Vote Count| | |
| | |---------------------->| | |
| 4. Respond | | | | |
| Result | | | | |
|<------------------- | |<----------------------| | |
| | | | | |
+---------------------+ +-----------------------+ +----------------+

4. List Votes Sequence Diagram:


+---------------------+ +-----------------------+ +----------------+
| Voter Controller | | Vote Service | | Database |
+---------------------+ +-----------------------+ +----------------+
| | | | | |
| 1. List Votes | | | | |
|-------------------> | | | | |
| | | | | |
| | | 2. Retrieve All Votes| | |
| | |---------------------->| | |
| 3. Respond | | | | |
| Result | | | | |
|<------------------- | |<----------------------| | |
| | | | | |
+---------------------+ +-----------------------+ +----------------+

5. Get Winner Sequence Diagram:


+---------------------+ +-----------------------+ +----------------+
| Voter Controller | | Vote Service | | Database |
+---------------------+ +-----------------------+ +----------------+
| | | | | |
| 1. Get Winner | | | | |
|-------------------> | | | | |
| | | | | |
| | | 2. Retrieve All Votes| | |
| | |---------------------->| | |
| | | | | |
| | | 3. Calculate Winner | | |
| | |---------------------->| | |
| 4. Respond | | | | |
| Result | | | | |
|<------------------- | |<----------------------| | |
| | | | | |
+---------------------+ +-----------------------+ +----------------+

6. Testing
===========
Overview:
The VotingControllerTest class is designed to test the functionalities of the
VotingController class in the Voting System project. The tests utilize the Spring
WebMvcTest annotation for testing the controller layer in isolation.

Test Methods:
1. testEnterCandidate:
Objective: Verify that the enterCandidate endpoint successfully adds a
candidate to the system.
Test Steps:
Perform a POST request to "/entercandidate" with the candidate name
parameter set to "ajay".
Expect an HTTP OK status (200).
2. testCastVoteValidCandidate:
Objective: Confirm that the castVote endpoint correctly registers a vote for
a valid candidate.
Test Steps:
Mock the votingService.castVote method to return 1 when called
with the name "ajay".
Perform a POST request to "/castvote" with the candidate name
parameter set to "ajay".
Expect an HTTP OK status (200) and response content "1".
3. testCastVoteInvalidCandidate:
Objective: Validate that the castVote endpoint handles invalid candidates and
returns the expected result.
Test Steps:
Mock the votingService.castVote method to return -1 when called
with the name "invalidCandidate".
Perform a POST request to "/castvote" with the candidate name
parameter set to "invalidCandidate".
Expect an HTTP OK status (200) and response content "-1".
4. testCountVote:
Objective: Ensure that the countVote endpoint retrieves the correct vote
count for a specific candidate.
Test Steps:
Mock the votingService.countVote method to return 3 when called with
the name "ajay".
Perform a GET request to "/countvote" with the candidate name parameter
set to "ajay".
Expect an HTTP OK status (200) and response content "3".
5. testListVote:
Objective: Validate that the listVotes endpoint returns the expected
JSON response for a list of candidates and their vote counts.
Test Steps:
Mock the votingService.listVotes method to return a map with
candidate names and respective vote counts.
Perform a GET request to "/listvote".
Expect an HTTP OK status (200) and JSON response with the correct
candidate names and vote counts.
6. testGetWinner:
Objective: Confirm that the getWinner endpoint returns the correct
winner.
Test Steps:
Mock the votingService.getWinner method to return "ajay".
Perform a GET request to "/getwinner".
Expect an HTTP OK status (200) and response content "ajay".
Conclusion:
The unit tests for the VotingController have been designed to ensure the
correct behavior of the various endpoints
in the Voting System project. These tests cover scenarios such as candidate
entry, vote casting, vote counting, and
winner determination.

7. Deployment
==============
i.Prerequisites
Before deploying the Voter service, make sure you have the following
prerequisites installed:
Java Development Kit (JDK)
Git
ii.Clone the Repository
git clone --depth 1 --branch master
https://github.com/jayaprakash9603/VotingSystem.git
cd voter-service
iii.API Usage
You can now use the provided APIs to interact with the Voter service. Example
API usage:

Enter Candidate: http://localhost:8080/entercandidate?name=ajay


Cast Vote: http://localhost:8080/castvote?name=ajay
Count Vote: http://localhost:8080/countvote?name=ajay
List Vote: http://localhost:8080/listvote
Get Winner: http://localhost:8080/getwinner

You might also like