# pychand/scalerbackendproject architecture

> Architecture diagram of the GitHub repository pychand/scalerbackendproject, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pychand/scalerbackendproject
- Repository: https://github.com/pychand/scalerbackendproject

## Overview

1. **Overall shape**
   - This is a single Spring Boot backend monolith for an e-commerce domain.
   - The package root is `com.scalers.productserviceebatch`.
   - The code is organized in the standard layered flow: **controllers → services → repositories → JPA entities/models**, with a few cross-cutting config and advice packages.

2. **Primary domain boundaries**
   - The main business areas are **products**, **categories**, and **payments**.
   - Product and category data are persisted locally through JPA.
   - Payment processing is separated behind an abstraction, so the app can switch between different gateways without changing controller code.

3. **Request entry points**
   - `ProductController`, `CategoryController`, and `PaymentController` are the external HTTP entry points.
   - They expose the REST API described in the README: product CRUD-ish operations, category creation/lookup, payment link creation, and webhook callbacks.
   - Controllers should be treated as thin adapters: they accept DTOs, call service interfaces, and return response data or errors.

4. **Service layer as the orchestration boundary**
   - `ProductService`, `CategoryService`, and `PaymentService` define the main service contracts.
   - The concrete service classes split into two styles:
     - `SelfProductService` / `SelfCategoryService` for local, repository-backed behavior.
     - `FakeStoreProductService` / `FakeStoreCategoryService` for delegating to an external FakeStore API.
   - This suggests the service layer is also a strategy boundary between local data and external-source data.

5. **Persistence layer**
   - `ProductRepository` and `CategoryRepository` are the JPA data access layer.
   - Domain models live under `models/`, including `Product`, `Category`, and `BaseModel`.
   - `BaseModel` likely provides shared auditing fields, backed by `configs/AuditConfig.java`.
   - There is also a `repository/projections/ProductProjection.java`, indicating at least some read paths use optimized partial selects rather than full entities.

6. **External API integration**
   - `configs/RestTemplateConfig.java` indicates the app uses `RestTemplate` for outbound HTTP calls.
   - The `FakeStore*DTO` classes and the `FakeStore*Service` implementations show that external product/category data can be fetched and mapped into local DTOs/models.
   - This is an adapter boundary: the app isolates third-party API schemas from its own entities.

7. **Payment subsystem**
   - `paymentgateway/PaymentGateway.java` is the abstraction for payment processing.
   - `StripePaymentGateway` and `RazorpayPaymentGateway` are concrete implementations.
   - `PaymentService` likely selects the correct gateway and coordinates payment request creation using `PaymentRequestDTO`.
   - `PaymentController` also exposes a webhook endpoint, so payment completion can be confirmed asynchronously from the gateway side.

8. **Caching and infrastructure configuration**
   - `configs/RedisTemplateConfig.java` shows Redis is part of the runtime architecture, likely for caching or short-lived state.
   - The repository README explicitly calls out Redis caching, so this is a meaningful non-relational subsystem rather than just a utility.
   - `RestTemplateConfig` and `AuditConfig` are supporting infrastructure beans for outbound calls and entity auditing.

9. **Error and exception handling**
   - Domain-specific exceptions live in `exceptions/`:
     - `ProductNotFoundException`
     - `CategoryNotFoundException`
   - `advice/ControllerAdvice.java` centralizes exception translation into `ErrorDTO` responses.
   - This means error handling is a global cross-cutting layer, not duplicated in controllers.

10. **DTO boundary**
   - The app separates API payloads from persistence models using DTOs.
   - `PaymentRequestDTO` is the main request contract for payment creation.
   - `ErrorDTO` standardizes error responses.
   - The `FakeStore*DTO` classes isolate third-party schema from internal models.

11. **Data flow for product/category operations**
   - For local CRUD-style operations, the flow is:
     - HTTP request → controller → service → repository → MySQL/H2 → entity/model → response.
   - For external-source operations, the flow is:
     - HTTP request → controller → fake-store service → external API via RestTemplate → mapped DTO/model → response.
   - Category existence is a business constraint for product updates, so product operations depend on category data integrity.

12. **Data flow for payments**
   - Payment requests enter via `PaymentController`.
   - `PaymentService` routes the request to the appropriate `PaymentGateway` implementation.
   - The gateway-specific adapter talks to Stripe or Razorpay.
   - A webhook callback endpoint is present for gateway-initiated status updates, meaning payment completion is not purely synchronous.

13. **Runtime and deployment characteristics**
   - The project is Maven-based with the Maven wrapper included, so it is intended to build consistently across environments.
   - The README indicates Java 17+/18, Spring Boot, JPA/Hibernate, MySQL in production, H2 for tests, and Redis for caching.
   - This is a conventional service backend, not a frontend or batch-only project, though the package name suggests it may have evolved from an earlier “batch” exercise.

14. **Testing boundary**
   - There is a Spring Boot test class under `src/test/java`, indicating integration-style bootstrapping tests.
   - The README suggests H2 for isolated test execution, so the test runtime boundary is separate from production MySQL.
   - This repo is therefore best diagrammed with distinct production and test persistence targets.

15. **What to draw in an architecture diagram**
   - Show a single Spring Boot application at the center.
   - Draw inbound REST controllers for products, categories, and payments.
   - From there, show service interfaces/implementations branching to:
     - JPA repositories and relational DB
     - Redis cache
     - outbound FakeStore API via RestTemplate
     - payment gateway adapters for Stripe and Razorpay
   - Add a global exception/advice layer and auditing as cross-cutting concerns.

Main entry points: [`src/main/java/com/scalers/productserviceebatch/services/ProductService.java`](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/services/ProductService.java) (Product Service), [`src/main/java/com/scalers/productserviceebatch/services/CategoryService.java`](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/services/CategoryService.java) (Category Service), [`src/main/java/com/scalers/productserviceebatch/ProductServiceEBatchApplication.java`](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/ProductServiceEBatchApplication.java) (App), [`src/main/java/com/scalers/productserviceebatch/advice/ControllerAdvice.java`](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/advice/ControllerAdvice.java) (Advice)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_app["Spring Boot App"]
  node_app(("App<br/>spring-boot entrypoint"))
  node_product_controller["Products<br/>REST controller"]
  node_category_controller["Categories<br/>REST controller"]
  node_payment_controller["Payments<br/>REST controller"]
  node_product_service["Product Service<br/>service contract"]
  node_category_service["Category Service<br/>service contract"]
  node_payment_service["Payment Service<br/>service orchestration"]
  node_self_product_service["Self Product<br/>local product service"]
  node_self_category_service["Self Category<br/>local category service"]
  node_fakestore_product_service["FakeStore Product<br/>external product service"]
  node_fakestore_category_service["FakeStore Category<br/>external category service"]
end

subgraph group_grp_domain["Domain Layer"]
  node_product_repo["Product Repo<br/>JPA repository"]
  node_category_repo["Category Repo<br/>JPA repository"]
  node_product_model["Product<br/>JPA entity<br/>[Product.java]"]
  node_category_model["Category<br/>JPA entity<br/>[Category.java]"]
  node_base_model["Base Model<br/>audited base entity<br/>[BaseModel.java]"]
  node_mysql[("MySQL<br/>production db")]
  node_h2[("H2<br/>test db")]
end

subgraph group_grp_infra["Infrastructure"]
  node_payment_gateway["Gateway API<br/>payment abstraction"]
  node_stripe_gateway["Stripe<br/>payment adapter"]
  node_razorpay_gateway["Razorpay<br/>payment adapter"]
  node_controller_advice["Advice<br/>global exception handler"]
  node_audit_config["Audit Config<br/>spring config<br/>[AuditConfig.java]"]
  node_redis_config["Redis Config<br/>spring config"]
  node_rest_config["Rest Config<br/>spring config"]
  node_redis[("Redis<br/>cache")]
  node_fakestore_api["FakeStore API<br/>external api"]
end

node_app -->|"hosts"| node_product_controller
node_app -->|"hosts"| node_category_controller
node_app -->|"hosts"| node_payment_controller
node_product_controller -->|"uses"| node_product_service
node_category_controller -->|"uses"| node_category_service
node_payment_controller -->|"uses"| node_payment_service
node_product_service -->|"local strategy"| node_self_product_service
node_product_service -->|"external strategy"| node_fakestore_product_service
node_category_service -->|"local strategy"| node_self_category_service
node_category_service -->|"external strategy"| node_fakestore_category_service
node_self_product_service -->|"reads/writes"| node_product_repo
node_self_category_service -->|"reads/writes"| node_category_repo
node_product_repo -->|"maps"| node_product_model
node_category_repo -->|"maps"| node_category_model
node_product_model -->|"extends"| node_base_model
node_category_model -->|"extends"| node_base_model
node_payment_service -->|"routes to"| node_payment_gateway
node_payment_gateway -->|"implements"| node_stripe_gateway
node_payment_gateway -->|"implements"| node_razorpay_gateway
node_fakestore_product_service -->|"uses"| node_rest_config
node_fakestore_category_service -->|"uses"| node_rest_config
node_fakestore_product_service -->|"calls"| node_fakestore_api
node_fakestore_category_service -->|"calls"| node_fakestore_api
node_controller_advice -.->|"handles errors"| node_product_controller
node_controller_advice -.->|"handles errors"| node_category_controller
node_controller_advice -.->|"handles errors"| node_payment_controller
node_audit_config -->|"supports"| node_base_model
node_redis_config -->|"configures"| node_redis
node_product_service -.->|"caches"| node_redis
node_category_service -.->|"caches"| node_redis
node_self_product_service -->|"persists to"| node_mysql
node_self_category_service -->|"persists to"| node_mysql
node_product_repo -.->|"tests on"| node_h2
node_category_repo -.->|"tests on"| node_h2

click node_app "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/ProductServiceEBatchApplication.java"
click node_product_controller "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/controllers/ProductController.java"
click node_category_controller "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/controllers/CategoryController.java"
click node_payment_controller "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/controllers/PaymentController.java"
click node_product_service "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/services/ProductService.java"
click node_category_service "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/services/CategoryService.java"
click node_payment_service "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/services/PaymentService.java"
click node_self_product_service "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/services/SelfProductService.java"
click node_self_category_service "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/services/SelfCategoryService.java"
click node_fakestore_product_service "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/services/FakeStoreProductService.java"
click node_fakestore_category_service "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/services/FakeStoreCategoryService.java"
click node_product_repo "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/repository/ProductRepository.java"
click node_category_repo "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/repository/CategoryRepository.java"
click node_product_model "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/models/Product.java"
click node_category_model "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/models/Category.java"
click node_base_model "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/models/BaseModel.java"
click node_payment_gateway "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/paymentgateway/PaymentGateway.java"
click node_stripe_gateway "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/paymentgateway/StripePaymentGateway.java"
click node_razorpay_gateway "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/paymentgateway/RazorpayPaymentGateway.java"
click node_controller_advice "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/advice/ControllerAdvice.java"
click node_audit_config "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/configs/AuditConfig.java"
click node_redis_config "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/configs/RedisTemplateConfig.java"
click node_rest_config "https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/configs/RestTemplateConfig.java"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_product_controller,node_category_controller,node_payment_controller,node_product_service,node_category_service,node_payment_service,node_self_product_service,node_self_category_service,node_fakestore_product_service,node_fakestore_category_service toneBlue
class node_product_repo,node_category_repo,node_product_model,node_category_model,node_base_model,node_mysql,node_h2 toneAmber
class node_payment_gateway,node_stripe_gateway,node_razorpay_gateway,node_controller_advice,node_audit_config,node_redis_config,node_rest_config,node_redis,node_fakestore_api toneMint
```

## Components

### Spring Boot App

Main application and request handling

- [App](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/ProductServiceEBatchApplication.java): spring-boot entrypoint · Main Spring Boot application · `src/main/java/com/scalers/productserviceebatch/ProductServiceEBatchApplication.java`
- [Products](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/controllers/ProductController.java): REST controller · HTTP entry point for product operations · `src/main/java/com/scalers/productserviceebatch/controllers/ProductController.java`
- [Categories](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/controllers/CategoryController.java): REST controller · HTTP entry point for category operations · `src/main/java/com/scalers/productserviceebatch/controllers/CategoryController.java`
- [Payments](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/controllers/PaymentController.java): REST controller · HTTP entry point for payment links and webhooks · `src/main/java/com/scalers/productserviceebatch/controllers/PaymentController.java`
- [Product Service](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/services/ProductService.java): service contract · Main product orchestration interface · `src/main/java/com/scalers/productserviceebatch/services/ProductService.java`
- [Category Service](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/services/CategoryService.java): service contract · Main category orchestration interface · `src/main/java/com/scalers/productserviceebatch/services/CategoryService.java`
- [Payment Service](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/services/PaymentService.java): service orchestration · Coordinates payment requests and gateway selection · `src/main/java/com/scalers/productserviceebatch/services/PaymentService.java`
- [Self Product](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/services/SelfProductService.java): local product service · Repository-backed product behavior · `src/main/java/com/scalers/productserviceebatch/services/SelfProductService.java`
- [Self Category](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/services/SelfCategoryService.java): local category service · Repository-backed category behavior · `src/main/java/com/scalers/productserviceebatch/services/SelfCategoryService.java`
- [FakeStore Product](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/services/FakeStoreProductService.java): external product service · Fetches product data from FakeStore · `src/main/java/com/scalers/productserviceebatch/services/FakeStoreProductService.java`
- [FakeStore Category](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/services/FakeStoreCategoryService.java): external category service · Fetches category data from FakeStore · `src/main/java/com/scalers/productserviceebatch/services/FakeStoreCategoryService.java`

### Domain Layer

Products, categories, and persistence models

- [Product Repo](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/repository/ProductRepository.java): JPA repository · Product persistence and query access · `src/main/java/com/scalers/productserviceebatch/repository/ProductRepository.java`
- [Category Repo](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/repository/CategoryRepository.java): JPA repository · Category persistence and query access · `src/main/java/com/scalers/productserviceebatch/repository/CategoryRepository.java`
- [Product](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/models/Product.java): JPA entity · Persistent product domain model · `src/main/java/com/scalers/productserviceebatch/models/Product.java`
- [Category](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/models/Category.java): JPA entity · Persistent category domain model · `src/main/java/com/scalers/productserviceebatch/models/Category.java`
- [Base Model](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/models/BaseModel.java): audited base entity · Shared entity fields and auditing support · `src/main/java/com/scalers/productserviceebatch/models/BaseModel.java`
- **MySQL**: production db · Primary relational data store
- **H2**: test db · Isolated test persistence store

### Infrastructure

Cross-cutting config, advice, and integrations

- [Gateway API](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/paymentgateway/PaymentGateway.java): payment abstraction · Common interface for payment providers · `src/main/java/com/scalers/productserviceebatch/paymentgateway/PaymentGateway.java`
- [Stripe](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/paymentgateway/StripePaymentGateway.java): payment adapter · Stripe payment implementation · `src/main/java/com/scalers/productserviceebatch/paymentgateway/StripePaymentGateway.java`
- [Razorpay](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/paymentgateway/RazorpayPaymentGateway.java): payment adapter · Razorpay payment implementation · `src/main/java/com/scalers/productserviceebatch/paymentgateway/RazorpayPaymentGateway.java`
- [Advice](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/advice/ControllerAdvice.java): global exception handler · Maps exceptions to standardized error responses · `src/main/java/com/scalers/productserviceebatch/advice/ControllerAdvice.java`
- [Audit Config](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/configs/AuditConfig.java): spring config · Enables entity auditing · `src/main/java/com/scalers/productserviceebatch/configs/AuditConfig.java`
- [Redis Config](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/configs/RedisTemplateConfig.java): spring config · Redis runtime configuration · `src/main/java/com/scalers/productserviceebatch/configs/RedisTemplateConfig.java`
- [Rest Config](https://github.com/pychand/scalerbackendproject/blob/main/src/main/java/com/scalers/productserviceebatch/configs/RestTemplateConfig.java): spring config · Outbound HTTP client configuration · `src/main/java/com/scalers/productserviceebatch/configs/RestTemplateConfig.java`
- **Redis**: cache · Cache or short-lived state store
- **FakeStore API**: external api · Third-party product and category source

## Connections

- App → Products: hosts · Application exposes product endpoints
- App → Categories: hosts · Application exposes category endpoints
- App → Payments: hosts · Application exposes payment endpoints
- Products → Product Service: uses · Delegates product requests to service layer
- Categories → Category Service: uses · Delegates category requests to service layer
- Payments → Payment Service: uses · Delegates payment requests and callbacks
- Product Service → Self Product: local strategy · Repository-backed product behavior
- Product Service → FakeStore Product: external strategy · FakeStore-backed product behavior
- Category Service → Self Category: local strategy · Repository-backed category behavior
- Category Service → FakeStore Category: external strategy · FakeStore-backed category behavior
- Self Product → Product Repo: reads/writes · Persists and queries products
- Self Category → Category Repo: reads/writes · Persists and queries categories
- Product Repo → Product: maps · Repository manages product entity
- Category Repo → Category: maps · Repository manages category entity
- Product → Base Model: extends · Shared auditing fields
- Category → Base Model: extends · Shared auditing fields
- Payment Service → Gateway API: routes to · Selects a payment provider implementation
- Gateway API → Stripe: implements · Stripe adapter
- Gateway API → Razorpay: implements · Razorpay adapter
- FakeStore Product → Rest Config: uses · Outbound HTTP client configuration
- FakeStore Category → Rest Config: uses · Outbound HTTP client configuration
- FakeStore Product → FakeStore API: calls · Fetches remote product data
- FakeStore Category → FakeStore API: calls · Fetches remote category data
- Advice → Products: handles errors · Translates product exceptions into responses
- Advice → Categories: handles errors · Translates category exceptions into responses
- Advice → Payments: handles errors · Translates payment errors into responses
- Audit Config → Base Model: supports · Enables auditing on entities
- Redis Config → Redis: configures · Redis runtime connection
- Product Service → Redis: caches · Product reads may use Redis
- Category Service → Redis: caches · Category reads may use Redis
- Self Product → MySQL: persists to · Production relational storage
- Self Category → MySQL: persists to · Production relational storage
- Product Repo → H2: tests on · Test-time relational store
- Category Repo → H2: tests on · Test-time relational store
