Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 Microservices Quiz Application

A fully backend Quiz Application built with Java Spring Boot following a Microservices Architecture. The application is decomposed into independently deployable services that communicate via REST, are discovered through a Eureka Service Registry, and are accessed through an API Gateway.


πŸ“ Architecture Overview

Client
  β”‚
  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      API Gateway      β”‚  ← Port 8765
β”‚  (Spring Cloud GW)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚  Routes requests
    β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”
    β–Ό             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Quiz       β”‚  β”‚  Question   β”‚
β”‚  Service    β”‚  β”‚  Service    β”‚
β”‚  (Port 8090)β”‚  β”‚  (Port 8080)β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚  Feign Client  β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β–²       β–²
           β”‚       β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”
    β”‚    Service Registry  β”‚  ← Port 8761 (Eureka)
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ—‚οΈ Project Structure

Microservices-QuizApplication/
β”œβ”€β”€ GateWay/             # API Gateway (Spring Cloud Gateway)
β”œβ”€β”€ QuestionService/     # Manages quiz questions (CRUD)
β”œβ”€β”€ QuizService/         # Manages quizzes, generation, and scoring
└── Service-registry/    # Eureka Service Discovery Server

πŸ› οΈ Tech Stack

Technology Purpose
Java 17+ Core language
Spring Boot Microservices framework
Spring Cloud Gateway API Gateway and request routing
Spring Cloud Netflix Eureka Service Discovery & Registration
Spring Data JPA Data persistence / ORM
OpenFeign Inter-service HTTP communication
PostgreSQL / MySQL Relational database
Maven Build tool
Postman API testing

πŸ“¦ Services

1. πŸ” Service Registry (/Service-registry) β€” Port 8761

The Eureka Server acts as the service registry. All other services register themselves here, enabling dynamic service discovery without hardcoded URLs.

  • Built with spring-cloud-starter-netflix-eureka-server
  • Dashboard available at: http://localhost:8761

2. ❓ Question Service (/QuestionService) β€” Port 8080

Responsible for all CRUD operations on quiz questions. Each question has a category, difficulty level, and multiple-choice options.

Key Endpoints:

Method Endpoint Description
GET /question/allQuestions Fetch all questions
GET /question/category/{category} Fetch questions by category
POST /question/add Add a new question
DELETE /question/delete/{id} Delete a question by ID
GET /question/generate Generate questions for a quiz
POST /question/getScore Calculate score from responses

3. πŸ“ Quiz Service (/QuizService) β€” Port 8090

Orchestrates quiz creation and scoring by calling the Question Service via Feign Client.

Key Endpoints:

Method Endpoint Description
POST /quiz/create Create a quiz (category + limit)
GET /quiz/get/{id} Get quiz questions by quiz ID
POST /quiz/submit/{id} Submit answers and get score

4. 🌐 API Gateway (/GateWay) β€” Port 8765

The single entry point for all client requests. Routes incoming requests to the appropriate microservice based on path predicates.

Route Configuration:

/question-service/**  β†’  Question Service
/quiz-service/**      β†’  Quiz Service

πŸš€ Getting Started

Prerequisites

  • Java 17+
  • Maven 3.6+
  • PostgreSQL or MySQL running locally
  • Git

Setup & Run

Important: Services must be started in this exact order.

Step 1 β€” Clone the Repository

git clone https://github.com/Sathish292004/Microservices-QuizApplication.git
cd Microservices-QuizApplication

Step 2 β€” Configure the Database

In both QuestionService and QuizService, update src/main/resources/application.properties:

spring.datasource.url=jdbc:postgresql://localhost:5432/quizdb
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.jpa.hibernate.ddl-auto=update

Step 3 β€” Start Service Registry (Eureka)

cd Service-registry
mvn spring-boot:run

Visit: http://localhost:8761 to confirm Eureka is running.

Step 4 β€” Start Question Service

cd ../QuestionService
mvn spring-boot:run

Step 5 β€” Start Quiz Service

cd ../QuizService
mvn spring-boot:run

Step 6 β€” Start API Gateway

cd ../GateWay
mvn spring-boot:run

All services should now be registered and visible in the Eureka dashboard.


πŸ“¬ Sample API Requests

All requests go through the API Gateway at http://localhost:8765.

Add a Question

POST http://localhost:8765/question-service/question/add
Content-Type: application/json

{
  "questionTitle": "What is JVM?",
  "option1": "Java Virtual Machine",
  "option2": "Java Verified Module",
  "option3": "Java Visual Manager",
  "option4": "None of the above",
  "rightAnswer": "Java Virtual Machine",
  "difficultyLevel": "Easy",
  "category": "Java"
}

Create a Quiz

POST http://localhost:8765/quiz-service/quiz/create
Content-Type: application/json

{
  "category": "Java",
  "numQuestions": 5,
  "title": "Java Basics Quiz"
}

Get Quiz Questions

GET http://localhost:8765/quiz-service/quiz/get/{quizId}

Submit Quiz & Get Score

POST http://localhost:8765/quiz-service/quiz/submit/{quizId}
Content-Type: application/json

[
  { "id": 1, "response": "Java Virtual Machine" },
  { "id": 2, "response": "Compile time" }
]

πŸ”„ Inter-Service Communication

The Quiz Service communicates with the Question Service using OpenFeign, a declarative REST client. Service discovery is handled automatically by Eureka β€” no hardcoded URLs are needed.

@FeignClient("QUESTION-SERVICE")
public interface QuizInterface {
    @GetMapping("/question/generate")
    ResponseEntity<List<Integer>> getQuestionsForQuiz(
        @RequestParam String categoryName,
        @RequestParam Integer numQuestions
    );
}

πŸ“Œ Key Concepts Demonstrated

  • βœ… Microservices Architecture with Spring Boot
  • βœ… Service Discovery with Eureka Server
  • βœ… API Gateway with Spring Cloud Gateway
  • βœ… Declarative REST Client with OpenFeign
  • βœ… Inter-service Communication
  • βœ… RESTful API Design with ResponseEntity
  • βœ… JPA-based data persistence
  • βœ… Separation of concerns across services

πŸ§ͺ Testing

Use Postman or cURL to test the APIs. Import the endpoints listed above and ensure all four services are running before making requests.


πŸ™Œ Author

Sathish Kumar B β€” @Sathish292004


πŸ“„ License

This project is licensed under an Educational Use Only License. See the LICENSE file for details.

Β© 2026 Sathish Kumar B. All rights reserved.

About

🧠 A backend Quiz Application built with Java Spring Boot using Microservices Architecture β€” featuring Eureka Service Discovery, API Gateway, and Feign Client.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages