How kimh4nkyul/coffee-shop works
Project Type and Purpose
• This is a backend service – a Spring Boot-based coffee shop ordering system.
• Its purpose is to manage operations such as placing orders, managing user points (charging, point transactions), retrieving menus (including popular menus), and ensuring consistency even under high concurrency.
• It also integrates with external platforms for data collection via Kafka and leverages Redis for caching to improve performance.
Analyzing the File Structure
• Top-level directories and files indicate a standard Gradle-based Spring Boot project.
• The main application code is located under src/main/java with clearly divided packages:
• common: contains shared components like exception handling, Kafka message publishing, distributed locks, and transactional handling.
• menu, order, user: separate bounded contexts handling your core business areas.
• The presence of configuration files (e.g., application.yml, SwaggerConfig, QueryDslConfig) implies API documentation (via Swagger) and custom query configuration.
• Additional build and deployment files (Dockerfile, GitHub Actions workflows, gradle wrapper) suggest CI/CD and containerization aspects.
• SQL scripts (ddl.sql, init_menu.sql) indicate that there is a standardized database schema initialization and migration process.
Components and Their Interactions
a. Main Components to Include:
• Client/API Layer:
• Represented by REST controllers (e.g., MenuController, OrderController, UserController).
• An entry point for API consumers documented by Swagger.
• Service / Business Logic Layer:
• Contains service classes (MenuService, OrderService, UserPointService) that encapsulate business logic.
• Implements functionality for order processing, menu retrieval, and point transactions.
• Data Access Layer:
• JPA repositories (MenuRepository, OrderRepository, UserRepository, etc.) connecting to a MySQL database.
• SQL initialization scripts ensure proper schema setup.
• Event Processing:
• Kafka integration for publishing order events (e.g., OrderCreatedEvent, KafkaMessagePublisher).
• Utilizes @TransactionalEventListener to publish only after database transactions have committed.
• Caching Layer:
• Redis is used to cache frequently accessed data such as popular menu queries.
• Concurrency & Transaction Management:
• Use of distributed locks (seen in DistributedLockAop) and transaction handlers ensures data consistency under concurrent order submissions.
• Error Handling & Cross-Cutting Concerns:
• Global exception handling (ControllerAdvice) ensures consistent API responses.
• Custom exception classes for domain-specific error responses.
b. Relationships and Interactions:
• API calls from clients enter through controllers and are routed to service layers.
• Services interact with the database via repositories; for read-heavy operations, they also interact with Redis for caching.
• After successful order transactions, an event is published via Kafka to external systems for real-time data collection.
• Distributed locks and transaction handlers enforce consistency, especially in scenarios where simultaneous orders might affect points balance.
• The configuration modules (e.g., SwaggerConfig, QueryDslConfig) tie into everything by providing cross-cutting settings.
c. Architectural Patterns and Design Principles:
• Layered Architecture: The project follows a clear separation between controllers, services, and repositories.
• Domain-Driven Design: Division into modules such as order, menu, and user reflects separation of business concerns.
• Event-driven Architecture: Using Kafka for asynchronous event processing once transactions are completed.
• Transactional Integrity: Use of transactional event listeners and distributed locks to manage concurrent operations.
d. Relevant Technologies:
• Spring Boot with Java 17, JPA, and MySQL for core backend.
• Redis for caching selected queries.
• Kafka for event messaging.
• Swagger for API documentation.
• Gradle for build automation and Docker for containerization.