Skip to content

Repository files navigation

SalonSphere โ€” Stakeholder Service

A Spring Boot microservice responsible for stakeholder registration, authentication, authorization, profile management, and user administration in the SalonSphere platform.

๐Ÿ“Œ Module 1 โ€” Stakeholder Service

The Stakeholder Service is the first core microservice of the SalonSphere application.

๐Ÿš€ Features

Authentication & Security

  • User registration
  • User login
  • JWT-based authentication
  • JWT request filtering
  • Role-based authorization
  • @PreAuthorize method-level security
  • Secure password handling using Spring Security

User Management

  • Get user by email
  • Get currently authenticated user
  • Update user profile
  • Change password
  • Delete user
  • Search users by firstname

API Features

  • RESTful API architecture
  • DTO-based request and response handling
  • Standardized ApiResponse<T> structure
  • HTTP status codes using ResponseEntity
  • Bean Validation using @Valid
  • Global exception handling
  • Pagination
  • Sorting
  • Search functionality
  • Controller-level logging

Documentation

  • Swagger / OpenAPI documentation
  • Interactive API testing through Swagger UI

๐Ÿ› ๏ธ Tech Stack

Technology Usage
Java Programming Language
Spring Boot Application Framework
Spring MVC REST API Development
Spring Security Authentication & Authorization
JWT Token-Based Authentication
Spring Data JPA Database Access
Hibernate ORM
MySQL Database
Maven Build & Dependency Management
Swagger / OpenAPI API Documentation
SLF4J Application Logging
Jakarta Validation Request Validation

๐Ÿ—๏ธ Project Structure

src/main/java/com/project/stakeholders
โ”‚
โ”œโ”€โ”€ controller
โ”‚   โ””โ”€โ”€ StakeholderController.java
โ”‚
โ”œโ”€โ”€ dto
โ”‚   โ”œโ”€โ”€ ApiResponse.java
โ”‚   โ”œโ”€โ”€ ChangePasswordDTO.java
โ”‚   โ”œโ”€โ”€ LoginDTO.java
โ”‚   โ”œโ”€โ”€ LoginResponseDTO.java
โ”‚   โ”œโ”€โ”€ RegisterDTO.java
โ”‚   โ”œโ”€โ”€ ResponseDTO.java
โ”‚   โ””โ”€โ”€ UpdateDTO.java
โ”‚
โ”œโ”€โ”€ entity
โ”‚   โ””โ”€โ”€ Stakeholders.java
โ”‚
โ”œโ”€โ”€ exception
โ”‚   โ”œโ”€โ”€ GlobalExceptionHandler.java
โ”‚   โ””โ”€โ”€ UserNotFoundException.java
โ”‚
โ”œโ”€โ”€ jwt
โ”‚   โ”œโ”€โ”€ JwtAuthenticationFilter.java
โ”‚   โ””โ”€โ”€ JwtUtil.java
โ”‚
โ”œโ”€โ”€ repository
โ”‚   โ””โ”€โ”€ StakeholderRepository.java
โ”‚
โ”œโ”€โ”€ security
โ”‚   โ””โ”€โ”€ StakeholderUserDetailsService.java
โ”‚
โ””โ”€โ”€ service
    โ”œโ”€โ”€ StakeholderService.java
    โ””โ”€โ”€ StakeholderServiceImpl.java

๐Ÿ” Authentication Flow

Client
  โ”‚
  โ”‚ POST /stakeholders/login
  โ–ผ
Stakeholder Controller
  โ”‚
  โ–ผ
Stakeholder Service
  โ”‚
  โ–ผ
Spring Security Authentication
  โ”‚
  โ–ผ
JWT Token Generated
  โ”‚
  โ–ผ
Client

For protected APIs:

Client
  โ”‚
  โ”‚ Authorization: Bearer <JWT>
  โ–ผ
JwtAuthenticationFilter
  โ”‚
  โ”œโ”€โ”€ Extract JWT
  โ”‚
  โ”œโ”€โ”€ Validate JWT
  โ”‚
  โ”œโ”€โ”€ Extract User Email
  โ”‚
  โ”œโ”€โ”€ Load UserDetails
  โ”‚
  โ””โ”€โ”€ Set Authentication
          โ”‚
          โ–ผ
   Spring Security
          โ”‚
          โ–ผ
      Controller

๐ŸŒ API Endpoints

Authentication

Method Endpoint Description
POST /stakeholders/register Register a new user
POST /stakeholders/login Authenticate user and generate JWT

User Management

Method Endpoint Description
GET /stakeholders/email/{email} Get user by email
PUT /stakeholders/update/{email} Update user
DELETE /stakeholders/{email} Delete user
PUT /stakeholders/change-password Change password

Current User

Method Endpoint Description
GET /stakeholders/me Get authenticated user's profile
PUT /stakeholders/me Update authenticated user's profile

User Search & Pagination

Method Endpoint Description
GET /stakeholders/all Get users with pagination and sorting
GET /stakeholders/search Search users by firstname

๐Ÿ“„ Standard API Response

Successful responses use a common ApiResponse<T> structure.

Success

{
  "success": true,
  "message": "User retrieved successfully.",
  "data": {
    "id": 1,
    "firstname": "Kunal",
    "lastname": "Patil",
    "email": "kunal@example.com"
  }
}

Error

{
  "success": false,
  "message": "User not found.",
  "data": null
}

This keeps the API response format consistent for frontend and service consumers.


โš ๏ธ Exception Handling

The service uses a centralized GlobalExceptionHandler.

Currently handled:

Exception HTTP Status
UserNotFoundException 404 NOT FOUND
MethodArgumentNotValidException 400 BAD REQUEST
Generic Exception 500 INTERNAL SERVER ERROR

Validation errors are returned in a structured format:

{
  "success": false,
  "message": "Validation Failed",
  "data": {
    "email": "Invalid email format",
    "password": "Password must be at least 8 characters"
  }
}

๐Ÿ”’ Authorization

Administrative operations are protected using Spring Security method-level authorization.

Example:

@PreAuthorize("hasRole('ADMIN')")

Therefore, only users with the ADMIN role can access administrative operations such as deleting users.


๐Ÿ“‘ Pagination & Sorting

The /all endpoint supports pagination and sorting.

Example:

GET /stakeholders/all?page=0&size=5&sortBy=firstname

Default values:

page   = 0
size   = 5
sortBy = firstname

๐Ÿ”Ž Search

Users can be searched by firstname.

Example:

GET /stakeholders/search?firstname=Kunal

The search uses case-insensitive partial matching.

Example:

Kunal
kunal
KUNAL

can all match the appropriate records.


๐Ÿ“š Swagger / OpenAPI

Swagger UI is available during local development at:

http://localhost:8080/swagger-ui/index.html

Swagger provides an interactive interface for:

  • Viewing available APIs
  • Viewing request parameters
  • Sending API requests
  • Testing authentication
  • Inspecting responses
  • Testing HTTP status codes

โš™๏ธ Configuration

The application currently uses MySQL.

Example configuration:

spring.application.name=SalonSphere

spring.datasource.url=jdbc:mysql://localhost:3306/stakeholders_database spring.datasource.username=root spring.datasource.password=root

spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true


> For deployment, database credentials should be supplied through environment variables rather than committed directly to the repository.

(Currently using Embedded Database - H2 Database)

## โ–ถ๏ธ How to Run

### 1. Clone the repository

```bash
git clone <YOUR_REPOSITORY_URL>

2. Open the project

Open the project in:

  • IntelliJ IDEA
  • Eclipse
  • VS Code
  • Spring Tool Suite

3. Configure MySQL

Create the database:

CREATE DATABASE stakeholders_database;

Update the database credentials in:

application.properties

4. Build the project

mvn clean install

5. Run the application

mvn spring-boot:run

Or run the main Spring Boot application class from your IDE.

6. Open Swagger

http://localhost:8080/swagger-ui/index.html


๐Ÿงช Testing

The APIs can be tested using:

  • Swagger UI
  • Postman
  • IntelliJ HTTP Client

For protected endpoints, first authenticate using:

POST /stakeholders/login

Then use the returned JWT token:

Authorization: Bearer <JWT_TOKEN>


๐Ÿ“ˆ Module Status

Module 1 โ€” Stakeholder Service

Status: โœ… Completed

Implemented:

  • User registration
  • User login
  • JWT authentication
  • Role-based authorization
  • User profile management
  • Password change
  • User deletion
  • Current user API
  • Pagination
  • Sorting
  • Search
  • DTOs
  • Validation
  • Global exception handling
  • Standardized API responses
  • Controller logging
  • Swagger/OpenAPI

Upcoming Modules

Module 1 โ†’ Stakeholder Service โœ… Module 2 โ†’ Salon Service ๐Ÿ”œ Module 3 โ†’ Staff Service Module 4 โ†’ Booking Service Module 5 โ†’ Payment Service Module 6 โ†’ Review Service Module 7 โ†’ Notification Service Module 8 โ†’ API Gateway Module 9 โ†’ Service Discovery Module 10 โ†’ Distributed Tracing Module 11 โ†’ Docker & Deployment


๐Ÿ”ฎ Future Improvements

Planned improvements include:

  • Refresh token authentication
  • Advanced security exception handling
  • Unit and integration testing
  • Service-to-service communication
  • API Gateway
  • Eureka Service Discovery
  • Redis caching
  • Circuit Breaker
  • Distributed tracing
  • Docker containerization
  • CI/CD
  • Cloud deployment

Technologies: Java | Spring Boot | Spring Security | JWT REST APIs | JPA | Hibernate | MySQL React | Angular | Microservices


๐Ÿ“„ License

This project is developed for learning, portfolio development, and demonstrating practical Spring Boot and microservices development.

About

Enterprise-style stakeholder management system using Spring Boot, JPA, and MySQL with layered architecture and REST APIs.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages