Skip to content

ChanfeiLi/jaxrs-beverage-store

Repository files navigation

🍻 Beverage Store Microservices API

🌟 Project Overview

This project implements a comprehensive Beverage Store system, initially designed as a JAX-RS REST API and subsequently refactored into a Microservices Architecture deployed via Docker and Kubernetes.

The system is designed to handle inventory management, order processing, and user interactions from both Customer and Employee perspectives.


🛠️ Phase 1: JAX-RS REST API Implementation

The initial phase focused on building a fully RESTful API following best practices and comprehensive requirements.

Technical Stack & Standards

Category Technology/Standard Notes
Backend Java / Jakarta EE Core language and enterprise framework.
REST Framework JAX-RS (Jakarta RESTful Web Services) Used for building REST endpoints.
Build Tool Gradle Used for dependency management and build automation.
API Contract OpenAPI Specification (OAS) Defines the contract in openapi.yaml.
Documentation Swagger UI Integrated for interactive API documentation and testing.
Data Transfer DTOs (Data Transfer Objects) Custom-designed for specific resource needs.

Core RESTful Design Principles Applied

  • Resource Modeling: Clear separation between Customer and Employee domain logic.
  • URI Design: Follows REST standards (URIs use only nouns, versioned via /v1).
  • Data Handling: Implements Pagination for collection resources, proper DTO design, and HATEOAS-like links for single resources.
  • Robustness: Features proper Parameter Validation, Customized Error Messages with appropriate HTTP status codes, and comprehensive Logging.
  • Order Workflow: Manages a transactional lifecycle (SUBMITTED $\rightarrow$ PROCESSED), including stock reduction and restricted modification/cancellation based on status.

☁️ Phase 2: Microservices & Containerization

The original monolith was refactored into a layered microservice architecture and deployed using container technology for scalability and resilience.

Application Architecture

Microservice Role & Responsibility External Port
Beverage Service Customer-Facing API. Provides read-only access to the beverage list. Calls the DB-Handler internally. 8080
Management Service Employee-Facing API. Handles CRUD (Create, Read, Update, Delete) operations for inventory. Calls the DB-Handler internally. 8090
DB-Handler Service Data Access Layer. Single-instance service for reading/writing data files. Accessible only within the Docker/K8s internal network (at db:9999/v1). N/A

Containerization & Deployment

Technology Implementation Detail Purpose
Containerization Docker Each Java service is packaged into a standalone Docker image.
Local Orchestration Docker Compose (docker-compose.yml) Defines services, network, and volumes for simplified local deployment and testing. Manages service dependencies.
Persistence Docker Volumes / K8s Persistent Volumes Used to ensure data persistence for the DB - File System, decoupling data from the container lifecycle.
Configuration Environment Variables / ConfigMaps Service connectivity (e.g., Management $\rightarrow$ DB-Handler URL) is dynamically managed via environment variables and deployed using Kubernetes ConfigMaps.
Deployment Kubernetes (K8s) Uses built images from Docker phase, managing deployments, services, and configuration without rebuilding images.

🚀 Getting Started

1. Prerequisites

  • Java JDK (Version 17+)
  • Docker & Docker Compose
  • Kubernetes Cluster Access (e.g., Minikube or Docker Desktop K8s)

2. Building

# Build all services (using the provided Gradle wrapper)
./gradlew build

3. Deployment

Option A: Docker Compose (Local Testing)

# Start all services (handles network and volume setup)
docker-compose up --build

Option B: Kubernetes

# 1. Apply Kubernetes configuration (ConfigMaps, Deployments, Services)
kubectl apply -f k8s/configmap.yaml
kubectl apply -f k8s/deployment.yaml
# ... (continue with other necessary Kubernetes YAML files)

4. API Access

Once deployed, the primary services are accessible at:

Service Local Docker URL (External)
Beverage Service http://localhost:8080/v1/beverages
Management Service http://localhost:8090/v1/management/beverages
Swagger UI Access via the deployed Service URL (e.g., http://localhost:8080/swagger-ui).

📦 Artifacts

  • Source Code
  • OpenAPI Specification (openapi.yaml)
  • Bruno Collection (bruno.json / bruno/) for complete API testing.
  • Docker Compose (docker-compose.yml) and Kubernetes configuration files.

About

This project implements a comprehensive Beverage Store REST API built with JAX-RS, designed to manage beverage inventory and order processing. It serves as an implementation of core Service-Oriented Architecture (SOA) principles.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors