Skip to content

mbags-playground/cms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Car Management & Fuel Tracking System

A full-stack system for tracking vehicle fleet data and fuel consumption statistics. This project uses a Spring Boot backend and a Java CLI client, organized within a multi-module Maven build.

Module Overview

  • server: The core application logic.
    • Framework: Spring Boot 3.x
    • Features: REST API, Servlet support (/servlet/*), In-Memory Persistence.
  • client: A dedicated command-line interface tool.
    • Framework: Native Java + Picocli.
    • Features: User-friendly commands, HTTP API integration.

📂 Project Structure

Here is the directory layout:

├── pom.xml                   # Parent Maven descriptor
├── server/
│   ├── pom.xml
│   └── src/main/java/com/aem/car/
│       ├── controller/       # REST Controllers (API endpoints)
│       ├── model/            # Domain entities (Car, FuelEntry)
│       ├── repository/       # Data access layer
│       ├── service/          # Business logic
│       ├── servlet/          # Manual HttpServlet implementations
│       └── ServerApplication.java
└── client/
    ├── pom.xml
    └── src/main/java/com/aem/client/
        ├── api/              # HTTP Client wrapper
        └── CliApp.java       # Main class & Picocli commands

🚀 Getting Started

Prerequisites

  • Java 17 (Required): Ensure java -version shows 17.
  • Maven 3.6+: Ensure mvn -version is installed.

📦 Build & Installation

To build the solution and generate the executable JARs, run:

mvn clean install

Artifacts generated:

  • Server: server/target/server-1.0.jar
  • Client: client/target/client-1.0.jar

🛠️ Development Workflow

Running the Server

For rapid development, run the server using the Spring Boot plugin:

mvn spring-boot:run -pl server

Running the Client

Run the client directly from source without packaging:

mvn clean compile exec:java -pl client \
    -Dexec.mainClass="com.aem.client.CliApp" \
    -Dexec.args="create-car --brand Tesla --model Model3 --year 2024"

🖥️ Production Usage

1. Start the Server

Deploy the server application:

java -jar server/target/server-1.0.jar

The server listens on port 8080.

2. Use the CLI

Open a new terminal to interact with the system via the generated client JAR.

Register a New Car

java -jar client/target/client-1.0.jar create-car --brand Toyota --model Corolla --year 2018

Add Fuel Entry

java -jar client/target/client-1.0.jar add-fuel --carId 1 --liters 40 --price 52.5 --odometer 45000

View Statistics

java -jar client/target/client-1.0.jar fuel-stats --carId 1

🔌 API Reference

REST Endpoints

Defined in CarController.

Method Endpoint Description
POST /api/cars Create a new car entity.
GET /api/cars List all registered cars.
POST /api/cars/{id}/fuel Record a fuel transaction.
GET /api/cars/{id}/fuel/stats Retrieve aggregated fuel statistics.

Swagger API Documentation

The API documentation is automatically generated by SpringDoc (OpenAPI). Once the server is running, you can access the interactive UI at:

Legacy Servlet

Defined in FuelStatsServlet.

Method Endpoint Description
GET /servlet/fuel-stats?carId={id} Manual HttpServlet returning JSON stats.

⚖️ Technical Decisions

  • Maven Multi-Module Architecture:
    • Separation of Concerns: Enforces a strict boundary between the backend service and the client application, preventing accidental coupling of logic.
    • Independent Dependency Management: Allows the server to manage Spring Boot dependencies independently from the client's lightweight CLI requirements.
    • Unified Build Lifecycle: Facilitates a single command (mvn clean install) to build, test, and package the entire distributed system, streamlining the CI/CD pipeline.
  • Spring Boot 3.2: Selected for the backend to leverage its production-ready features, including robust REST API support and embedded servlet container, while maintaining the flexibility to register legacy HttpServlet components manually.
  • Picocli: Chosen for the CLI to provide a professional, type-safe user experience with automatic help generation, argument validation, and ANSI color support, superior to manual array parsing.
  • Concurrent In-Memory Storage: Implemented using ConcurrentHashMap to ensure thread safety for concurrent API requests without introducing the operational overhead of an external database for this specific scope.

About

cms

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages