Skip to content

Latest commit

 

History

History
271 lines (198 loc) · 7.15 KB

File metadata and controls

271 lines (198 loc) · 7.15 KB

Project Logo

E-Commerce / Loan Management System - Spring Boot

A comprehensive Spring Boot learning project covering JPA, REST, Validation, Caching, Kafka, Async, and more.

Java Spring Boot Maven MySQL Redis Kafka License


📑 Table of Contents

  1. About the Project
  2. Tech Stack
  3. Project Structure
  4. Getting Started
  5. Feature Highlights
  6. API Endpoints & cURL
  7. Configuration
  8. Database & Caching
  9. Testing
  10. Roadmap
  11. Contributions & License

📘 About the Project

This project serves as a reference architecture for a modern Spring Boot application. It simulates an e-commerce + loan management system with realistic concerns:

  • Entity relationships with validation
  • Database persistence (MySQL)
  • Performance tuning via Redis caching
  • Async and concurrent workflows
  • Distributed communication using Kafka
  • Robust configuration across environments
  • Developer productivity with Dockerized infrastructure

The intent is educational depth - so learners see not only how things work, but how they interlock in a production-like environment.


🛠️ Tech Stack

  • Language: Java 11+
  • Framework: Spring Boot (Web, Data JPA, Validation, Cache, Actuator)
  • Database: MySQL
  • Cache: Redis
  • Messaging: Apache Kafka
  • Build Tool: Maven
  • Containerization: Docker & Docker Compose
  • Logging: Log4j + reload4j
  • Testing: JUnit 5, Spring Boot Test

📁 Project Structure

src/
  main/java/com/example/ecommercesystem/
    config/        # Redis, Kafka, Logging, Security
    controller/    # REST endpoints
    service/       # Business logic, caching, async
    repository/    # Spring Data JPA repositories
    model/         # Entities, validation, serialization
    kafka/         # Producer & Consumer services
  main/resources/
    application.properties
    application-dev.properties
    log4j.properties
    reload4j.properties

amit/              # Infrastructure scripts
  mysqldockercompose/      # MySQL docker-compose
  redis_docker_compose/    # Redis docker-compose
  kafka_docker_compose/    # Kafka docker-compose

test/
  java/            # JUnit 5 tests

🚀 Getting Started

Prerequisites

  • Java 11+ (Java 17 compatible)
  • Maven (or use ./mvnw)
  • Docker & Docker Compose

Setup & Run Locally

  1. Start dependencies (run in separate terminals):
docker-compose -f amit/mysqldockercompose/docker-compose.yaml up
docker-compose -f amit/redis_docker_compose/docker-compose.yaml up
docker-compose -f amit/kafka_docker_compose/docker-compose.yaml up
  1. Build and run the app:
./mvnw clean install
./mvnw spring-boot:run
  1. Access the app:

http://localhost:8080


✨ Feature Highlights

  • Entity modeling with advanced javax.validation constraints
  • REST API design with validation and unified error handling
  • Repository layer powered by Spring Data JPA (custom queries, pagination, sorting)
  • Service layer with Redis caching (@Cacheable, @CacheEvict)
  • Async workflows using ExecutorService, Futures, and CompletableFuture
  • Kafka messaging with producer/consumer scaffolding
  • Observability with Spring Actuator, console + file logging

🔌 API Endpoints & cURL

Products

# Get all products
curl -X GET http://localhost:8080/api/products

# Get paged products
curl -X GET "http://localhost:8080/api/products/pagelist?page=0&size=12"

# Get by ID
curl -X GET http://localhost:8080/api/products/1

# Search
curl -X GET "http://localhost:8080/api/products/search?name=Laptop&description=gaming"

# Create product
curl -X POST http://localhost:8080/api/products \
  -H "Content-Type: application/json" \
  -d '{ "name":"Laptop","description":"Gaming","price":1299.99,"contactEmail":"support@example.com","quantityAvailable":10 }'

Async

curl -X POST http://localhost:8080/api/products/process
curl -X POST http://localhost:8080/api/products/process-async-with-futures
curl -X POST http://localhost:8080/api/products/process-async-with-cf

Kafka

curl -X POST http://localhost:8080/api/products/send-test-message \
  -H "Content-Type: application/json" \
  -d '{ "message":"hello" }'

⚙️ Configuration

  • MySQL: jdbc:mysql://0.0.0.0:3306/loan_management (user: mysqluser, pass: mysqlpass)
  • Redis: host localhost, port 6379
  • Kafka: localhost:9092, consumer group myGroup
  • Profiles: dev by default; switch via SPRING_PROFILES_ACTIVE
  • Logging: Console + ./logs/app.log

Environment override example (PowerShell):

$env:SPRING_PROFILES_ACTIVE = "dev"
$env:SPRING_DATASOURCE_URL = "jdbc:mysql://localhost:3306/loan_management"
$env:SPRING_DATASOURCE_USERNAME = "mysqluser"
$env:SPRING_DATASOURCE_PASSWORD = "mysqlpass"
./mvnw spring-boot:run

🗄️ Database & Caching

  • Entities: Product, Category, Loan
  • Relationships: One-to-Many, Many-to-One with cascading
  • Indexes: product(name), product(price), category(name)
  • Batching: Consider effects of GenerationType.IDENTITY
  • Caching (Redis):
    • Cache names: products, product
    • Keys: product::id, products::SimpleKey[]
    • Eviction: Auto on save/update
    • Serialization: JSON with GenericJackson2JsonRedisSerializer

🧪 Testing

Run all tests:

./mvnw test

Run a specific test:

./mvnw -Dtest=ProductTest test

Skip tests during build:

./mvnw -DskipTests clean install

🗺️ Roadmap

  • Redis caching
  • Kafka producer/consumer
  • REST endpoints & pagination
  • Async workflows
  • Dockerized infrastructure
  • JUnit scaffolding
  • Dev profile configs

Planned:

  • WebSocket integration
  • Security (roles & JWT auth)
  • MongoDB integration
  • Connection pooling improvements
  • Decorator patterns
  • DB migrations instead of Hibernate DDL

🤝 Contributions & License

Contributions are welcome. Please fork and submit pull requests for improvements.

License: MIT (add a LICENSE file if missing)

Happy learning - may this repository be your forge of architectural mastery.