How atomfinger/javazone-2024 works
Project Type & Purpose
• This is a single “BookStoreService” microservice implemented as a multi‐module Gradle project that exposes a web API (module “web”), contains domain logic (“service”), persistence code (“persistence”), and integration glue (“integration”), plus a standalone Kafka listener service (“kafka”) and an example stub service for contract tests (“external_orderservice”). The service’s responsibility is to manage books: listing, adding, and integrating with inventory, ordering, and review systems.
Key Architectural Layers / Components
a. Web API Layer (“web” module)
• Spring Boot REST controllers handle HTTP requests (BookController).
• Exposes endpoints to clients (e.g., listBooks, addBook).
b. Domain Layer (“service” module)
• Business logic lives in BookService.
• Orchestrates calls to persistence and integration clients.
c. Persistence Layer (“persistence” module)
• JPA entities (Book) and Spring Data repository.
• Database migrations (Flyway or SQL scripts).
d. Integration Layer (“integration” module)
• HTTP clients for BestReads, InventoryService, OrderService.
• Kafka producer for BookCreated events.
• Configured via Spring Cloud Contract stubs for contract testing.
e. Kafka Listener Service (“kafka” module)
• Separate Spring Boot app that consumes AddBook messages.
• Demonstrates event-driven handling (AddBookListener).
f. External Order Service Stub (“external_orderservice” module)
• Provides contract stubs & generated tests for OrderService.
External Systems
• InventoryService (HTTP API)
• OrderService (HTTP API, stubbed locally via contract)
• BestReads (HTTP API)
• Kafka cluster
• SQL database (PostgreSQL via TestContainers in tests)
Interactions & Data Flow
• Client → Web API → Domain (BookService)
• Domain → Persistence → Database
• Domain → Integration HTTP clients → External services
• Domain → Kafka producer → Kafka topic “book‐created”
• Kafka listener (separate service) consumes “add_book” messages → persists to DB
• Contract test runner and TestContainers spin up stubbed services, DB, and Kafka for CI
Architectural Patterns & Principles
• Layered architecture (Presentation, Domain, Persistence, Integration)
• Hexagonal/Ports & Adapters: modules act as adapters to external systems
• Consumer/Producer event‐driven pattern via Kafka
• Contract testing with Spring Cloud Contract
• TestContainers for ephemeral dependencies
• ApprovalTests for API response validation