How swirl86/springboot-ecommerce-api works
1. Overall shape
- This is a single Spring Boot 3.2.5 backend monolith called ecom-engine.
- It follows a strict layered style: HTTP controllers at the edge, service classes for business rules, Spring Data JPA repositories for persistence, and DTO/mapper classes to keep API contracts separate from database entities.
2. Main domain modules
- The codebase is split into feature packages rather than generic layers only: product, category, cart, order, orderhistory, user, address, and auth.
- Each domain usually contains its own entity, repository, service, controller, DTOs, mapper, and domain-specific exceptions, which makes each area diagrammable as an independent vertical slice.
3. Request/response flow
- Incoming HTTP traffic enters a domain controller, which validates the request and delegates to the domain service.
- Services coordinate repositories and any related domains, then use mapper classes to convert entities into response DTOs.
- This pattern is consistent across Product, Category, Cart, Order, Address, and User APIs.
4. Persistence boundary
- Persistence is handled with Spring Data JPA repositories over JPA entities.
- The architecture is relational and normalized enough to model separate tables for users, products, categories, carts, cart items, orders, order items, addresses, and order history entries.
- The README indicates H2 is used for dev/test, with PostgreSQL planned for production, so the repo is currently optimized for local/test database portability.
5. Catalog subsystem
- product and category are the catalog core.
- ProductService supports CRUD plus search/filtering; ProductSpecifications suggests dynamic query composition for category, price range, and text search.
- CategoryService provides category CRUD and is a dependency of product filtering and product creation/update rules.
6. Cart and checkout flow
- cart is a separate module with both Cart and CartItem as distinct entities.
- Cart operations are stateful and user-scoped: add, update, remove, fetch, and empty.
- Checkout bridges cart to order: an authenticated user’s cart is transformed into an order, then the cart is cleared after successful order creation.
7. Order and history subsystem
- order contains the order aggregate and OrderItem line items, plus an OrderStatus lifecycle.
- OrderService enforces status transitions and access rules, while OrderController exposes order management endpoints.
- orderhistory is a separate audit/timeline subsystem that records status changes as OrderHistoryEntry objects and exposes a timeline view, so history is modeled as append-only tracking rather than embedded order state.
8. Authentication and security boundary
- Authentication is custom JWT-based rather than session-based.
- auth handles registration and login, while security/jwt contains token generation/validation and the filter that authenticates requests.
- security/config, SecurityRules, and the custom handlers centralize authorization, CORS/Web configuration, and JSON error responses for unauthorized/forbidden requests.
- security/user and the @AuthenticatedUser resolver provide a typed way to inject the current principal into controllers/services.
9. User and profile data
- user models account identity and role-based access control.
- The presence of profile DTOs and service/controller layers shows this module is intended to support user profile access and updates independently from authentication.
- address is its own bounded area, likely linked to the user domain and used for delivery/shipping data.
10. Cross-cutting concerns
- common/exception defines a shared API error model and a GlobalExceptionHandler, giving the whole backend a consistent error-response contract.
- config/OpenApiConfig enables Swagger/OpenAPI documentation, and SwaggerSecurityConfig restricts it to development.
- DataSeeder is profile-based, meaning development-only bootstrapping is isolated from test and production runs.
11. Testing strategy
- The repo is heavily test-driven at multiple levels: unit tests for services and mappers, controller tests with MockMvc, and full integration tests with Spring Boot and H2.
- The testsupport package contains shared fixtures, configs, and helpers, indicating tests are intentionally standardized across domains.
- This suggests the architecture is designed to keep domain logic testable without needing the web layer or a real external database in most cases.
12. Delivery and tooling
- Maven is the build system, and GitHub Actions provides CI for build/test/coverage checks.
- Java 17 and Spring Boot are the runtime foundation, with Spring Security, Spring Web MVC, Spring Data JPA, Lombok, and Springdoc OpenAPI as the main architectural dependencies.
- The repo is structured as a conventional backend service, not a multi-service distributed system; the main boundaries are internal modules and the database.
Main entry points: EcomEngineApplication.java Ecom Engine · OrderService.java Order svc · CartService.java Cart svc · ProductService.java Product svc
Components 34
Application
Spring Boot entrypoint and runtime wiring
- Ecom Engine · Application bootstrap and component scanning
ecom-engine/src/main/java/com/swirl/ecomengine/EcomEngineApplication.java
Domain modules
Feature slices for catalog, commerce, identity, and fulfillment
- Products · Product API edge
ecom-engine/src/main/java/com/swirl/ecomengine/product/controller/ProductController.java - Product svc · Catalog CRUD and search orchestration
ecom-engine/src/main/java/com/swirl/ecomengine/product/ProductService.java - Product repo · Product persistence access
ecom-engine/src/main/java/com/swirl/ecomengine/product/ProductRepository.java - Product map · Entity to response conversion
ecom-engine/src/main/java/com/swirl/ecomengine/product/ProductMapper.java - Categories · Category API edge
ecom-engine/src/main/java/com/swirl/ecomengine/category/controller/CategoryController.java - Category svc · Category CRUD and validation
ecom-engine/src/main/java/com/swirl/ecomengine/category/service/CategoryService.java - Category repo · Category persistence access
ecom-engine/src/main/java/com/swirl/ecomengine/category/CategoryRepository.java - Category map · Entity to response conversion
ecom-engine/src/main/java/com/swirl/ecomengine/category/CategoryMapper.java - Cart · User cart API edge
ecom-engine/src/main/java/com/swirl/ecomengine/cart/controller/CartController.java - Cart svc · Cart mutation and checkout bridge
ecom-engine/src/main/java/com/swirl/ecomengine/cart/service/CartService.java - Cart repo · Cart aggregate persistence
ecom-engine/src/main/java/com/swirl/ecomengine/cart/CartRepository.java - Cart items · Cart item persistence
ecom-engine/src/main/java/com/swirl/ecomengine/cart/item/CartItemRepository.java - Cart map · Cart entity to response conversion
ecom-engine/src/main/java/com/swirl/ecomengine/cart/CartMapper.java - Orders · Order management API edge
ecom-engine/src/main/java/com/swirl/ecomengine/order/controller/OrderController.java - Order svc · Order lifecycle and access rules
ecom-engine/src/main/java/com/swirl/ecomengine/order/service/OrderService.java - Order repo · Order aggregate persistence
ecom-engine/src/main/java/com/swirl/ecomengine/order/OrderRepository.java - Order items · Order line item persistence
ecom-engine/src/main/java/com/swirl/ecomengine/order/item/OrderItemRepository.java - Order map · Entity to response conversion
ecom-engine/src/main/java/com/swirl/ecomengine/order/OrderMapper.java - History · Order timeline API edge
ecom-engine/src/main/java/com/swirl/ecomengine/orderhistory/controller/OrderHistoryController.java - History svc · Append-only order status timeline
ecom-engine/src/main/java/com/swirl/ecomengine/orderhistory/service/OrderHistoryService.java - History repo · Order history persistence
ecom-engine/src/main/java/com/swirl/ecomengine/orderhistory/OrderHistoryRepository.java - History map · Timeline response conversion
ecom-engine/src/main/java/com/swirl/ecomengine/orderhistory/OrderHistoryMapper.java - Auth · Registration and login edge
ecom-engine/src/main/java/com/swirl/ecomengine/auth/controller/AuthController.java - Auth svc · Registration, login, and token issuance
ecom-engine/src/main/java/com/swirl/ecomengine/auth/AuthService.java - Users · Profile and account API edge
ecom-engine/src/main/java/com/swirl/ecomengine/user/controller/UserController.java - User svc · Profile and role-aware user operations
ecom-engine/src/main/java/com/swirl/ecomengine/user/service/UserService.java - User repo · User identity persistence
ecom-engine/src/main/java/com/swirl/ecomengine/user/UserRepository.java - Addresses · Address API edge
ecom-engine/src/main/java/com/swirl/ecomengine/address/controller/AddressController.java - Address svc · Address CRUD and ownership rules
ecom-engine/src/main/java/com/swirl/ecomengine/address/service/AddressService.java - Address repo · Address persistence
ecom-engine/src/main/java/com/swirl/ecomengine/address/AddressRepository.java - Address map · Entity to response conversion
ecom-engine/src/main/java/com/swirl/ecomengine/address/AddressMapper.java
Security
JWT authentication, authorization, and web security boundary
- JWT · Token generation and validation
ecom-engine/src/main/java/com/swirl/ecomengine/security/jwt/JwtService.java - JWT filter · Authenticates incoming requests
ecom-engine/src/main/java/com/swirl/ecomengine/security/jwt/JwtAuthenticationFilter.java
Connections 38
- Ecom Engine → Products: wires · Application loads product API
- Ecom Engine → Categories: wires · Application loads category API
- Ecom Engine → Cart: wires · Application loads cart API
- Ecom Engine → Orders: wires · Application loads order API
- Ecom Engine → History: wires · Application loads order history API
- Ecom Engine → Auth: wires · Application loads auth API
- Ecom Engine → Users: wires · Application loads user API
- Ecom Engine → Addresses: wires · Application loads address API
- Products → Product svc: calls · Validates requests then delegates
- Product svc → Product repo: uses · Persists and queries products
- Product svc → Product map: maps · Builds response DTOs
- Product svc → Category repo: reads · Resolves category constraints
- Categories → Category svc: calls · Delegates category operations
- Category svc → Category repo: uses · Persists categories
- Category svc → Category map: maps · Builds response DTOs
- Cart → Cart svc: calls · Delegates cart operations
- Cart svc → Cart repo: uses · Loads and saves cart state
- Cart svc → Cart items: uses · Manages cart items
- Cart svc → Cart map: maps · Builds cart responses
- Cart svc → Order svc: checkout · Transforms cart into order then clears cart
- Orders → Order svc: calls · Delegates order management
- Order svc → Order repo: uses · Persists order aggregate
- Order svc → Order items: uses · Persists line items
- Order svc → Order map: maps · Builds order responses
- Order svc → History svc: records · Emits status change history
- History → History svc: calls · Delegates timeline queries
- History svc → History repo: uses · Stores history entries
- History svc → History map: maps · Builds timeline responses
- Auth → Auth svc: calls · Delegates registration and login
- Auth svc → JWT: issues · Creates and validates access tokens
- Auth svc → User repo: uses · Creates and authenticates users
- Users → User svc: calls · Delegates profile operations
- User svc → User repo: uses · Persists and fetches users
- Addresses → Address svc: calls · Delegates address operations
- Address svc → Address repo: uses · Persists addresses
- Address svc → Address map: maps · Builds address responses
- JWT filter → JWT: validates · Authenticates bearer tokens
- JWT filter → User repo: loads · Builds authenticated principal