Skip to content

Yahan-Botheju/autocare-service-engine-RESTAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

233 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš— Vehicle Service Management System

Java Spring Boot Gradle PostgreSQL H2


πŸ“Œ Overview

This project is a Spring Boot REST API designed using Clean Architecture principles.

It manages vehicle service operations including customers, vehicles, and service tracking.

The system demonstrates:

  • Layered architecture (Domain β†’ UseCase β†’ Infrastructure β†’ Web)
  • DTO + MapStruct mapping
  • Role-based authorization via interceptors
  • Business rule enforcement in domain models
  • Exception handling with centralized handler
  • Pagination support

πŸ“Œ Features

  • Customer management (CRUD)
  • Vehicle management (CRUD)
  • Vehicle service tracking (PENDING β†’ IN_PROGRESS β†’ COMPLETED)
  • Automatic next service date calculation
  • Soft delete support using Hibernate
  • Pagination support
  • Role-based access control (ADMIN)
  • Global exception handling
  • Standard API response structure
  • Clean Architecture implementation
  • Swagger API documentation
  • Rich Domain Models

πŸ› οΈ Tech Stack

Category Technology
Language Java 21
Framework Spring Boot 3.4
Build Tool Gradle
Database PostgreSQL / H2
ORM Spring Data JPA / Hibernate
Mapping MapStruct
API Docs Springdoc OpenAPI
Security Spring Security
Boilerplate Lombok
Architecture Clean Architecture
Code Analysis SonarQube

πŸ—οΈ Architecture Overview

The project follows Clean Architecture:

Controller β†’ UseCase β†’ Domain β†’ Repository Interface
                                 ↓
                          Infrastructure (JPA)

πŸ”§ Dependency Injection Strategy (Loose Coupling)

This project uses explicit Bean Configuration classes instead of relying only on annotations like @Service or @Repository.

This ensures the system remains:

  • Loosely coupled
  • Easily testable
  • Fully aligned with Clean Architecture principles

πŸ“Œ Why This Approach?

Dependencies are wired manually using:

  • @Configuration
  • @Bean

This allows:

  • UseCase layer to depend only on interfaces
  • Infrastructure layer to provide implementations
  • Easy replacement of components (e.g., switching database)

πŸ—οΈ Bean Wiring Example


πŸ‘€ Customer Module

  • customer usecase bean config
@Configuration
class CustomerBeanConfig {

    @Bean
    CustomerUseCase customerUseCase(CustomerRepository customerRepository) {
        return new CustomerUseCaseImpl(customerRepository);
    }
}
  • customer persistence bean config
@Configuration
class CustomerPersistenceBeanConfig {

    @Bean
    CustomerRepository customerRepository(
            JpaCustomerRepository jpaCustomerRepository,
            CustomerPersistenceMapper customerPersistenceMapper
    ) {
        return new CustomerRepositoryImpl(jpaCustomerRepository, customerPersistenceMapper);
    }
}

πŸš— Vehicle Module

  • vehicle usecase bean config
@Configuration
class VehicleBeanConfig {

    @Bean
    VehicleUseCase vehicleUseCase(
            VehicleRepository vehicleRepository,
            CustomerRepository customerRepository) {
        return new VehicleUseCaseImpl(vehicleRepository, customerRepository);
    }
}
  • vehicle persistence bean config
@Configuration
class VehiclePersistenceBeanConfig {

    @Bean
    VehicleRepository vehicleRepository(
            JpaVehicleRepository jpaVehicleRepository,
            VehiclePersistenceMapper vehiclePersistenceMapper
    ) {
        return new VehicleRepositoryImpl(jpaVehicleRepository, vehiclePersistenceMapper);
    }
}

🧠 Dependency Flow

UseCase (Business Logic)
        ↓ depends on
Repository Interface
        ↓ implemented by
Infrastructure (JPA)

πŸš€ Advantages

  • Framework-independent business logic
  • Easier unit testing (mock interfaces)
  • Flexible implementation replacement
  • Strong separation of concerns

πŸ’‘ Design Note

  • The UseCase layer avoids using @Service to remain framework-independent.

πŸ”„ Request Flow

Client
 ↓
Controller (DTO)
 ↓
Mapper β†’ Domain
 ↓
UseCase
 ↓
Repository Interface
 ↓
Infrastructure (JPA)
 ↓
Database
 ↓
Response (DTO)


πŸ“‚ Layers Explanation

πŸ“Œ Domain Layer

Contains core business logic.

Models

  • Customer
  • Vehicle
  • VehicleFuelType (Enum)
  • VehicleServiceStatus (Enum)
  • VehicleUpdateResult

Key Business Logic

  • Next service date = lastServiceDate + 6 months
  • Default vehicle status = PENDING
  • Prevent update if service is COMPLETED

Repositories

  • CustomerRepository
  • VehicleRepository

πŸ“Œ UseCase Layer

Handles application logic.

CustomerUseCase

  • Get all customers
  • Save customer
  • Update customer
  • Delete customer

VehicleUseCase

  • Get all vehicles
  • Register vehicle
  • Update vehicle
  • Delete vehicle

Rules

  • Customer must exist before assigning vehicle
  • Inprogress or Completed vehicles cannot be updated or deleted
  • Service date auto-calculated
  • Default update vehicle service status as PENDING
  • Register new vehicle should have customer ID along with registration

πŸ“Œ Infrastructure Layer

Handles database operations.

Customer

  • CustomerEntity
  • JpaCustomerRepository
  • CustomerRepositoryImpl
  • CustomerPersistenceMapper

Vehicle

  • VehicleEntity
  • JpaVehicleRepository
  • VehicleRepositoryImpl
  • VehiclePersistenceMapper

πŸ“Œ Web Layer

Handles HTTP requests.

Controllers

  • CustomerController
  • VehicleController

DTOs

  • CustomerRequestDTO / CustomerResponseDTO
  • VehicleRequestDTO / VehicleResponseDTO / VehicleShortInfoDTO

Mappers

  • CustomerWebMapper
  • VehicleWebMapper

Interceptors

  • CustomerInterceptor
  • VehicleInterceptor

πŸ“Œ Security

  • Spring Security configured
  • CSRF disabled
  • Swagger endpoints allowed
  • Role-based control via interceptors

πŸ“Œ Global Handling

Exception Handling

Handled using:

- ResourceNotFoundException β†’ 404
- ServiceAlreadyCompletedException β†’ 409
- ForbiddenAccessException β†’ 403
- Generic Exception β†’ 500

Standard Response

Fields:

  • statusCode
  • message
  • timestamp
  • data

πŸš€ Features in Detail

  • Pagination using PageRequest
  • Soft delete using Hibernate
  • DTO mapping using MapStruct
  • Domain-driven business logic
  • Interceptor-based authorization
  • Automatic service scheduling

πŸ“‚ Project Structure

# πŸ“‚ Project Structure


   πŸ“ vehicle_service_system
    β”œβ”€β”€ πŸ“ domain                                       @Core Business Logic & Enterprise Rules
    β”‚   β”œβ”€β”€ πŸ“ models                                   @Pure Domain Entities (No Framework Logic)
    β”‚   β”‚   β”œβ”€β”€ Customer.java
    β”‚   β”‚   β”œβ”€β”€ Vehicle.java
    β”‚   β”‚   β”œβ”€β”€ VehicleFuelType.java
    β”‚   β”‚   β”œβ”€β”€ VehicleServiceStatus.java
    β”‚   β”‚   └── VehicleUpdateResult.java
    β”‚   └── πŸ“ repositories                             @Domain Repository Interfaces (Outbound Ports)
    β”‚       β”œβ”€β”€ CustomerRepository.java
    β”‚       └── VehicleRepository.java
    β”‚
    β”œβ”€β”€ πŸ“ usecase                                      @Application Specific Business Rules
    β”‚   β”œβ”€β”€ πŸ“ customer
    β”‚   β”‚   β”œβ”€β”€ CustomerUseCase.java                    @Inbound Port
    β”‚   β”‚   └── CustomerUseCaseImpl.java                @Business Logic Implementation
    β”‚   └── πŸ“ vehicle
    β”‚       β”œβ”€β”€ VehicleUseCase.java
    β”‚       └── VehicleUseCaseImpl.java
    β”‚
    β”œβ”€β”€ πŸ“ infrastructure                               @External Frameworks & Tools (Persistence)
    β”‚   β”œβ”€β”€ πŸ“ customer
    β”‚   β”‚   β”œβ”€β”€ πŸ“ config                               @Dependency Injection Configurations
    β”‚   β”‚   β”‚   β”œβ”€β”€ CustomerBeanConfig.java
    β”‚   β”‚   β”‚   └── CustomerPersistenceBeanConfig.java
    β”‚   β”‚   └── πŸ“ persistence
    β”‚   β”‚       β”œβ”€β”€ πŸ“ entity                           @Database Entities (JPA)
    β”‚   β”‚       β”‚   └── CustomerEntity.java
    β”‚   β”‚       β”œβ”€β”€ πŸ“ jpa                              @Spring Data Repositories
    β”‚   β”‚       β”‚   └── JpaCustomerRepository.java
    β”‚   β”‚       β”œβ”€β”€ πŸ“ mapper                           @Persistence Mapping (Domain <-> Entity)
    β”‚   β”‚       β”‚   └── CustomerPersistenceMapper.java
    β”‚   β”‚       └── CustomerRepositoryImpl.java         @Persistence Adapter
    β”‚   └── πŸ“ vehicle
    β”‚       β”œβ”€β”€ πŸ“ config
    β”‚       β”‚   β”œβ”€β”€ VehicleBeanConfig.java
    β”‚       β”‚   └── VehiclePersistenceBeanConfig.java
    β”‚       └── πŸ“ persistence
    β”‚           β”œβ”€β”€ πŸ“ entity
    β”‚           β”‚   └── VehicleEntity.java
    β”‚           β”œβ”€β”€ πŸ“ jpa
    β”‚           β”‚   └── JpaVehicleRepository.java
    β”‚           β”œβ”€β”€ πŸ“ mapper
    β”‚           β”‚   └── VehiclePersistenceMapper.java
    β”‚           └── VehicleRepositoryImpl.java
    β”‚
    β”œβ”€β”€ πŸ“ web                                          @Entry Points & Delivery (UI/API)
    β”‚   β”œβ”€β”€ πŸ“ config                                   @Web MVC Configurations
    β”‚   β”‚   └── WebConfig.java
    β”‚   β”œβ”€β”€ πŸ“ customer
    β”‚   β”‚   β”œβ”€β”€ πŸ“ controllers                          @REST API Controllers
    β”‚   β”‚   β”‚   └── CustomerController.java
    β”‚   β”‚   β”œβ”€β”€ πŸ“ DTOs                                 @Request/Response Data Objects
    β”‚   β”‚   β”‚   β”œβ”€β”€ CustomerRequestDTO.java
    β”‚   β”‚   β”‚   └── CustomerResponseDTO.java
    β”‚   β”‚   β”œβ”€β”€ πŸ“ interceptor                          @Request Pre-processing
    β”‚   β”‚   β”‚   └── CustomerInterceptor.java
    β”‚   β”‚   └── πŸ“ webMappers                           @Web Mapping (DTO <-> Domain)
    β”‚   β”‚       └── CustomerWebMapper.java
    β”‚   └── πŸ“ vehicle
    β”‚       β”œβ”€β”€ πŸ“ controllers
    β”‚       β”œβ”€β”€ πŸ“ DTOs
    β”‚       β”‚   β”œβ”€β”€ VehicleRequestDTO.java
    β”‚       β”‚   β”œβ”€β”€ VehicleResponseDTO.java
    β”‚       β”‚   └── VehicleShortInfoDTO.java
    β”‚       β”œβ”€β”€ πŸ“ interceptor
    β”‚       └── πŸ“ webMappers
    β”‚
    β”œβ”€β”€ πŸ“ GlobalExceptionHandler                       @Centralized Exception Management
    β”‚   β”œβ”€β”€ ErrorMessage.java
    β”‚   β”œβ”€β”€ ForbiddenAccessException.java
    β”‚   β”œβ”€β”€ GlobalExceptionHandler.java
    β”‚   β”œβ”€β”€ ResourceNotFoundException.java
    β”‚   └── ServiceAlreadyCompletedException.java
    β”‚
    β”œβ”€β”€ πŸ“ GlobalResponseHandler                        @Generic Response Wrapping
    β”‚   └── StandardResponse.java
    β”‚
    β”œβ”€β”€ πŸ“ spring_security                              @Security & Access Control
    β”‚   └── SecurityConfig.java
    β”‚
    └── VehicleServiceSystemApplication.java            @Spring Boot Bootstrap Class


βš™οΈ API Endpoints

πŸ‘€ Customer APIs

Method Endpoint Description
GET /api/v1/autocare/customers/all Get all customers
POST /api/v1/autocare/customers/register Register customer
PUT /api/v1/autocare/customers/{id} Update customer
DELETE /api/v1/autocare/customers/{id} Delete customer

πŸš— Vehicle APIs

Method Endpoint Description
GET /api/v1/autocare/vehicles/all Get all vehicles
POST /api/v1/autocare/vehicles/register Register vehicle
PUT /api/v1/autocare/vehicles/{id} Update vehicle
DELETE /api/v1/autocare/vehicles/{id} Delete vehicle

πŸ” Authorization

πŸ” Authorization

Action Access
View all customers ADMIN
Delete customer ADMIN
Manage vehicles ADMIN

Header required: role: ADMIN


πŸ“š API Documentation

Swagger UI:

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

OpenAPI JSON:

http://localhost:5000/v3/api-docs

πŸ‘€ Customer API Example

πŸ“₯ Sample Request

{
  "customerName": "James Smith",
  "customerPhone": "555-0101",
  "customerEmail": "james.smith@example.com"
}

πŸ“€ Sample Response

{
  "statusCode": 200,
  "message": "Customers details fetched successfully",
  "timestamp": "2026-04-27T19:05:11.8739514",
  "data": [
    {
      "customerId": 1,
      "customerName": "James Smith",
      "customerPhone": "555-0101",
      "customerEmail": "james.smith@example.com",
      "vehicles": [
        {
          "vehicleId": 1,
          "vehicleNumber": "NY-7829-K",
          "vehicleModel": "Ford F-150",
          "lastServiceDate": "2024-01-15",
          "nextServiceDate": "2024-07-15",
          "mileage": 15000
        }
      ]
    }
  ]
}

πŸš— Vehicle API Example

πŸ“₯ Sample Request

{
  "vehicleNumber": "CAB-1234",
  "vehicleModel": "Toyota Prius",
  "vehicleFuelType": "HYBRID",
  "mileage": 50000,
  "lastServiceDate": "2025-01-01",
  "customerId": 1
}

πŸ“€ Sample Response

{
  "statusCode": 200,
  "message": "Details fetched successfully",
  "timestamp": "2026-04-27T19:16:15.648869",
  "data": [
    {
      "vehicleId": 1,
      "vehicleNumber": "NY-7829-K",
      "vehicleModel": "Ford F-150",
      "vehicleFuelType": "PETROL",
      "lastServiceDate": "2024-01-15",
      "nextServiceDate": "2024-07-15",
      "mileage": 15000,
      "customerId": 1,
      "customerName": "James Smith",
      "vehicleServiceStatus": "COMPLETED"
    }
  ]
}

▢️ How to Run

1. Clone repository

git clone https://github.com/yahan-botheju/vehicle-service-system.git

2. Navigate to project

cd vehicle-service-system

3. Run application

./gradlew bootRun

πŸ‘¨β€πŸ’» Author

Developed as a Clean Architecture practice project focusing on:

  • Real-world backend structure
  • Scalable system design
  • Separation of concerns

⭐ Project Purpose

This project was built to practice:

  • Clean Architecture
  • Spring Boot advanced structuring
  • DTO & mapping strategies
  • Business rule implementation
  • API design best practices
  • Rich Domain Models
  • Standered Error Response

πŸ“Œ Note

  • This is a learning-focused project, but the architecture is strong enough to evolve into a production-ready system.

About

A Spring Boot REST API build with Clean Architecture to manage Customers, Vehicles and vehicle service process featuring role-based access control, DTO mapping, representing loose coupling, separation of concern and many other back end logices and calculations.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages