Skip to content

uddishasinghh31/PRODIGY_BWD_04

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

15 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš€ Spring Boot User Management REST API

Java Spring Boot Spring Security JWT Redis Docker MySQL Flyway Maven

Secure User Management REST API using Spring Boot

A production-style REST API built using Spring Boot, Spring Security, JWT Authentication, Redis Caching, MySQL, Flyway Database Migration, and Docker.


๐Ÿ“Œ Project Overview

This project demonstrates how modern backend applications are built using Spring Boot with secure authentication, database persistence, caching, and database version control.

The application follows a clean layered architecture:

  • Controller
  • Service
  • Repository
  • Database

The project secures all protected endpoints using JWT Authentication and improves performance using Redis Cache running inside a Docker container.


โœจ Features

  • ๐Ÿ” JWT Authentication
  • ๐Ÿ‘ค User Registration
  • ๐Ÿ”‘ User Login
  • ๐Ÿ›ก Spring Security
  • ๐Ÿ“ฆ CRUD Operations
  • ๐Ÿ—„ MySQL Database
  • โšก Redis Cache
  • ๐Ÿณ Dockerized Redis
  • ๐Ÿ”„ Flyway Database Migration
  • ๐Ÿ“‘ Request Validation
  • โŒ Global Exception Handling
  • ๐Ÿงฉ Layered Architecture
  • ๐Ÿš€ Maven Build
  • ๐Ÿ“ฌ API Testing using Postman

๐Ÿ›  Tech Stack

Technology Used
Java 25 โœ…
Spring Boot โœ…
Spring Security โœ…
JWT โœ…
Spring Data JPA โœ…
Hibernate โœ…
MySQL โœ…
Redis โœ…
Docker โœ…
Flyway โœ…
Maven โœ…
IntelliJ IDEA โœ…
Postman โœ…

๐Ÿ— Project Architecture

                Client (Postman)

                       โ”‚
                       โ–ผ

              Spring Security

                       โ”‚
                       โ–ผ

             JWT Authentication

                       โ”‚
                       โ–ผ

              User Controller

                       โ”‚
                       โ–ผ

               Service Layer

              โ†™              โ†˜

        Redis Cache      JPA Repository

              โ”‚               โ”‚

           Docker        Hibernate ORM

                              โ”‚

                              โ–ผ

                       MySQL Database

๐Ÿ“‚ Project Structure

basic-rest-api
โ”‚
โ”œโ”€โ”€ docs
โ”‚   โ””โ”€โ”€ screenshots
โ”‚
โ”œโ”€โ”€ src
โ”‚   โ”œโ”€โ”€ main
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ java
โ”‚   โ”‚     โ””โ”€โ”€ com.example.basic_rest_api
โ”‚   โ”‚
โ”‚   โ”‚          โ”œโ”€โ”€ config
โ”‚   โ”‚          โ”œโ”€โ”€ controller
โ”‚   โ”‚          โ”œโ”€โ”€ dto
โ”‚   โ”‚          โ”œโ”€โ”€ exception
โ”‚   โ”‚          โ”œโ”€โ”€ model
โ”‚   โ”‚          โ”œโ”€โ”€ repository
โ”‚   โ”‚          โ”œโ”€โ”€ security
โ”‚   โ”‚          โ”œโ”€โ”€ service
โ”‚   โ”‚          โ””โ”€โ”€ BasicRestApiApplication
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ resources
โ”‚        โ”œโ”€โ”€ application.properties
โ”‚        โ””โ”€โ”€ db
โ”‚             โ””โ”€โ”€ migration
โ”‚
โ”œโ”€โ”€ pom.xml
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ .gitignore

๐Ÿ”— REST API Endpoints

Authentication APIs

Method Endpoint Description
POST /auth/register Register User
POST /auth/login Login User

User APIs

Method Endpoint Description
GET /users Get All Users
GET /users/{id} Get User by ID
PUT /users/{id} Update User
DELETE /users/{id} Delete User

๐Ÿ”’ All User APIs require a valid JWT Token.


๐Ÿ” JWT Authentication Flow

Register User
      โ”‚
      โ–ผ
Login
      โ”‚
      โ–ผ
JWT Token Generated
      โ”‚
      โ–ผ
Authorization Header

Bearer <JWT Token>

      โ”‚
      โ–ผ
Spring Security Filter
      โ”‚
      โ–ผ
Protected APIs

โšก Redis Cache Flow

Client

   โ”‚

GET /users

   โ”‚

   โ–ผ

Redis Cache ?

YES โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ Return Cached Response

NO

 โ”‚

 โ–ผ

MySQL Database

 โ”‚

 โ–ผ

Store Data in Redis

 โ”‚

 โ–ผ

Return Response

Redis is used to cache frequently requested user data to reduce unnecessary database queries and improve response time.


๐Ÿณ Docker

Redis runs inside a Docker container.

Run Redis

docker run -d --name redis-server -p 6379:6379 redis

Start Existing Container

docker start redis-server

Verify Running Containers

docker ps

๐Ÿ—„ Flyway Database Migration

Database schema is managed automatically using Flyway.

V1__create_users_table.sql

โ†“

V2__insert_initial_data.sql

โ†“

Executed Automatically
During Application Startup

๐Ÿš€ Getting Started

Clone Repository

git clone https://github.com/uddishasinghh31/YOUR_REPOSITORY_NAME.git

Open Project

Open the project using IntelliJ IDEA.


Configure MySQL

Update your application.properties.

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

Start Redis

docker start redis-server

Run Application

mvn spring-boot:run

or run

BasicRestApiApplication.java

Application starts on:

http://localhost:8080

๐Ÿ“ฎ Testing with Postman

  1. Register a new user.
  2. Login using registered credentials.
  3. Copy the generated JWT Token.
  4. Add it to the Authorization Header.
Authorization

Bearer your_jwt_token
  1. Access all protected APIs.

๐Ÿ“ธ Project Screenshots

๐Ÿ“‚ Project Structure


๐ŸŽซ Postman Working


๐ŸŽซ JWT Token Generated


โšก Redis Cache


๐Ÿณ Docker Redis Container


๐ŸŽฅ Project Demo

โ–ถ๏ธ Click here to watch the demo video

---

๐Ÿš€ Future Improvements

  • ๐Ÿ“„ Swagger / OpenAPI Documentation
  • ๐Ÿ‘ฅ Role-Based Authentication
  • ๐Ÿ”„ Refresh Tokens
  • ๐Ÿ“Š Pagination & Sorting
  • ๐Ÿ” Search APIs
  • ๐Ÿงช Unit Testing
  • โ˜ Cloud Deployment
  • โš™ CI/CD Pipeline
  • ๐Ÿ“ˆ Monitoring using Prometheus & Grafana

๐Ÿ‘ฉโ€๐Ÿ’ป Developed By

Udisha

Aspiring Java Backend Developer

Skills

  • โ˜• Java
  • ๐ŸŒฑ Spring Boot
  • ๐Ÿ” Spring Security
  • ๐ŸŽซ JWT Authentication
  • ๐Ÿ—„ MySQL
  • โšก Redis
  • ๐Ÿณ Docker
  • ๐Ÿš€ REST APIs

Linkedin: https://www.linkedin.com/in/udisha-singh-47170b338


---

# โญ Support

If you found this project useful,

โญ Consider giving this repository a **Star**!

<div align="center">

## Made with โค๏ธ using Spring Boot

</div>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages