How nirvik-alpha/snapbuy works
1. Project type and runtime
- SnapBuy is a Spring Boot / Maven backend application. The main entry point is SnapBuyApplication, and the code is organized as a classic layered Java backend for an e-commerce domain.
2. Primary request boundary
- Incoming traffic is handled through controller classes: Auth, Product, Category, Cart, Order, Address, and Analytics.
- These controllers expose the REST API surface and are the first stop for HTTP requests.
3. Security boundary
- Authentication and authorization are centralized under security.
- The app uses JWT-based security (JwtUtils, AuthTokenFilter, AuthEntryPointJwt) and Spring Security configuration (WebSecurityConfig, WebConfig).
- Login/signup requests and identity responses are separated into dedicated request/response payloads, indicating token-based auth rather than session-based auth.
4. Service layer as business logic
- Each domain area has a matching service interface and implementation, such as ProductServiceImpl, CartServiceImpl, OrderServiceImpl, and AuthServiceImpl.
- Controllers should delegate to services; services encapsulate validation, orchestration, and cross-entity workflows.
5. Persistence boundary
- Data access is handled by Spring Data repository interfaces in repositories.
- Repositories map to the core persisted entities in model: User, Role, Product, Category, Cart, CartItem, Order, OrderItem, Payment, and Address.
- This suggests a relational database-backed domain model with JPA-style entity relationships.
6. Domain structure
- The model is strongly e-commerce oriented:
- Catalog: products and categories
- Customer account: users, roles, addresses
- Shopping flow: cart and cart items
- Checkout: orders, order items, payment
- This separation is important for drawing the architecture diagram because it shows distinct bounded contexts within one backend.
7. DTO / payload layer
- The payload package contains DTOs and API response shapes such as ProductDTO, CartDTO, OrderRequestDTO, OrderResponse, AuthenticationResult, and AnalyticsResponse.
- These objects form the contract between controllers and clients, keeping API shapes separate from persistence entities.
8. Cross-cutting concerns
- exceptions contains a global exception handler plus custom exception types (APIException, ResourceNotFoundException).
- This indicates centralized error translation from service/repository failures into API responses.
9. File and media handling
- There is a dedicated FileService and FileServiceImpl, which likely handles product or asset uploads.
- Even without implementation details, this is a distinct subsystem that probably interacts with the catalog flow rather than core persistence directly.
10. Analytics and reporting
- AnalyticsController and AnalyticsService suggest a read-only reporting path over order/product/user data.
- This is likely a secondary consumer of the same persistence layer, optimized for aggregate metrics rather than transactional updates.
11. Configuration and API documentation
- config includes application-level settings, MVC setup, constants, and SwaggerConfig.
- Swagger/OpenAPI support matters architecturally because it documents the REST boundary and helps define the external API contract.
12. Typical data flow
- The main flow is: client request → security filter → controller → service → repository/database → DTO/response.
- For authenticated operations, the JWT layer is part of the request path before business logic executes.
- For order/payment flows, data likely traverses cart, order, order item, and payment entities in one transaction-oriented service path.
Main entry points: OrderRequestDTO.java API DTOs · AuthServiceImpl.java Auth service · AnalyticsServiceImpl.java Analytics service · OrderServiceImpl.java Order service
Components 22
API surface
REST controllers and request/response contracts
- Auth API · Login and signup endpoints
snap-buy/src/main/java/com/snapBuy/project/controller/AuthController.java - Catalog API · Products and categories endpoints
snap-buy/src/main/java/com/snapBuy/project/controller/ProductController.java - Cart API · Shopping cart endpoints
snap-buy/src/main/java/com/snapBuy/project/controller/CartController.java - Order API · Checkout and order endpoints
snap-buy/src/main/java/com/snapBuy/project/controller/OrderController.java - Address API · Customer address endpoints
snap-buy/src/main/java/com/snapBuy/project/controller/AddressController.java - Analytics API · Reporting endpoints
snap-buy/src/main/java/com/snapBuy/project/controller/AnalyticsController.java - API DTOs · Request and response contracts
snap-buy/src/main/java/com/snapBuy/project/payload/OrderRequestDTO.java
Security
JWT auth and Spring Security boundary
- JWT security · Token filter, entry point, and JWT utilities
snap-buy/src/main/java/com/snapBuy/project/security/jwt/JwtUtils.java - Security config · HTTP security and web configuration
snap-buy/src/main/java/com/snapBuy/project/security/WebSecurityConfig.java
Domain & data
Business services, entities, and repositories
- Auth service · Authentication and user registration logic
snap-buy/src/main/java/com/snapBuy/project/service/AuthServiceImpl.java - Catalog service · Product, category, and file flows
snap-buy/src/main/java/com/snapBuy/project/service/ProductServiceImpl.java - Cart service · Cart and cart-item orchestration
snap-buy/src/main/java/com/snapBuy/project/service/CartServiceImpl.java - Order service · Order, item, and payment workflow
snap-buy/src/main/java/com/snapBuy/project/service/OrderServiceImpl.java - Address service · Address management logic
snap-buy/src/main/java/com/snapBuy/project/service/AddressServiceImpl.java - Analytics service · Aggregate reporting and metrics
snap-buy/src/main/java/com/snapBuy/project/service/AnalyticsServiceImpl.java - Identity data · Users, roles, and addresses persistence
snap-buy/src/main/java/com/snapBuy/project/model/User.java - Catalog data · Products and categories persistence
snap-buy/src/main/java/com/snapBuy/project/model/Product.java - Cart data · Cart and cart-item persistence
snap-buy/src/main/java/com/snapBuy/project/model/Cart.java - Order data · Orders, items, and payments persistence
snap-buy/src/main/java/com/snapBuy/project/model/Order.java
Cross-cutting
Configuration and exception handling
- SnapBuy · Application entry point
snap-buy/src/main/java/com/snapBuy/project/SnapBuyApplication.java - Errors · Global exception translation
snap-buy/src/main/java/com/snapBuy/project/exceptions/MyGlobalExceptionHandler.java - App config · MVC, Swagger, and constants
snap-buy/src/main/java/com/snapBuy/project/config/SwaggerConfig.java
Connections 23
- SnapBuy → Security config: boots with · Application startup wires security and web configuration
- SnapBuy → App config: loads · Core application configuration
- Security config → JWT security: uses · Security configuration depends on JWT components
- Auth API → Auth service: delegates · Authentication requests are handled in service layer
- Auth API → API DTOs: maps to · Login/signup payloads and auth responses
- Catalog API → Catalog service: delegates · Catalog endpoints call catalog services
- Catalog API → API DTOs: maps to · Product and category response shapes
- Cart API → Cart service: delegates · Cart endpoints call cart workflows
- Order API → Order service: delegates · Checkout endpoints call order workflows
- Address API → Address service: delegates · Address endpoints call address service
- Analytics API → Analytics service: delegates · Reporting endpoints call analytics service
- Auth service → Identity data: reads/writes · User and role persistence
- Catalog service → Catalog data: reads/writes · Product and category persistence
- Cart service → Cart data: reads/writes · Cart state persistence
- Order service → Order data: reads/writes · Orders, items, and payments persistence
- Address service → Identity data: reads/writes · Address data is attached to customer accounts
- Analytics service → Order data: reads · Analytics aggregates order-side data
- Analytics service → Catalog data: reads · Analytics can summarize catalog data
- Auth service → JWT security: issues tokens · Authentication service cooperates with JWT utilities
- Errors → Auth service: handles failures · Service and repository errors become API responses
- Errors → Order service: handles failures · Transactional errors are translated centrally
- API DTOs → Identity data: separates from · API contracts are distinct from entities
- API DTOs → Catalog data: separates from · DTOs shield persistence models from clients