# codefarm0/price-aggregator architecture

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

- Interactive diagram: https://gitdiagram.com/codefarm0/price-aggregator
- Repository: https://github.com/codefarm0/price-aggregator

## Overview

#### Purpose and Runtime
This repository is a Java 25/Spring Boot price-aggregation microservice. It exposes a REST API that retrieves a product’s prices from Amazon, Walmart, and Flipkart, then returns an aggregated result with resilience, Redis caching, trace propagation, and structured logging.

Application bootstrap: `src/main/java/in/codefarm/price/aggregator/PriceAggregatorApplication.java`. It runs on port 8080; container deployment is defined by `Dockerfile` and `docker-compose.yml`.

#### HTTP Entry and Request Context
`PriceController` owns `GET /api/prices/{productId}` and accepts `X-Refresh-Cache: true` to bypass cache reads:
- `src/main/java/in/codefarm/price/aggregator/controller/PriceController.java`
- `src/main/java/in/codefarm/price/aggregator/dto/PriceResponse.java`

`TraceIdFilter` establishes or accepts `X-Trace-Id`, places it into MDC, and returns it in the response. This is the request boundary for end-to-end correlation:
- `src/main/java/in/codefarm/price/aggregator/config/TraceIdFilter.java`
- `src/main/resources/logback-spring.xml`

#### Orchestration and Response Model
`PriceService` is the main control-flow coordinator: controller request → cache decision → vendor aggregation → cache write → API response. The result DTOs model vendor-level outcomes and the aggregate response:
- `src/main/java/in/codefarm/price/aggregator/service/PriceService.java`
- `src/main/java/in/codefarm/price/aggregator/dto/PriceResult.java`
- `src/main/java/in/codefarm/price/aggregator/dto/PriceSource.java`

#### External Retailer Boundary
Vendor-specific WebClient adapters isolate HTTP integration with the three independently deployed mock retailer services. `PriceAggregator` is the shared aggregation abstraction/coordinator at this boundary:
- `src/main/java/in/codefarm/price/aggregator/external/PriceAggregator.java`
- `src/main/java/in/codefarm/price/aggregator/external/AmazonClient.java`
- `src/main/java/in/codefarm/price/aggregator/external/FlipkartClient.java`

Walmart follows the same adapter pattern in `src/main/java/in/codefarm/price/aggregator/external/WalmartClient.java`. External mocks are not implemented in this repository; their URLs and service topology are configured for local or Docker execution.

#### Resilience and Async Execution
Resilience4j patterns—circuit breaker, bulkhead, retry, and time limiter—protect vendor calls, preventing individual retailer failures from taking down aggregation. Request-scoped MDC context must cross asynchronous work; `MdcTaskDecorator` provides that propagation. Relevant configuration is centralized in:
- `src/main/java/in/codefarm/price/aggregator/config/PriceConfig.java`
- `src/main/java/in/codefarm/price/aggregator/config/MdcTaskDecorator.java`
- `src/main/resources/application.yaml`

#### Cache and Infrastructure
`PriceCacheService` encapsulates Redis-backed cached price responses, forming the persistence boundary between orchestration and Redis. `RedisConfig` configures the Redis integration:
- `src/main/java/in/codefarm/price/aggregator/service/PriceCacheService.java`
- `src/main/java/in/codefarm/price/aggregator/config/RedisConfig.java`
- `docker-compose.yml`

`WebClientConfig` defines the outbound HTTP client infrastructure:
- `src/main/java/in/codefarm/price/aggregator/config/WebClientConfig.java`

#### Included Local Mock Surface
`MockVendorController` exists within this service’s source tree, while the documented distributed mock vendors are separate repositories. Treat it as an internal/local mock surface rather than the production vendor integration path:
- `src/main/java/in/codefarm/price/aggregator/mock/MockVendorController.java`
- `src/main/java/in/codefarm/price/aggregator/external/WalmartClient.java`

Main entry points: [`src/main/java/in/codefarm/price/aggregator/external/PriceAggregator.java`](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/external/PriceAggregator.java) (Price aggregator), [`src/main/java/in/codefarm/price/aggregator/service/PriceService.java`](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/service/PriceService.java) (Price service), [`src/main/java/in/codefarm/price/aggregator/external/WalmartClient.java`](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/external/WalmartClient.java) (Walmart client), [`docker-compose.yml`](https://github.com/codefarm0/price-aggregator/blob/main/docker-compose.yml) (Docker deployment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP boundary"]
  node_trace_filter["Trace ID filter<br/>servlet filter<br/>[TraceIdFilter.java]"]
  node_price_controller["Price controller<br/>REST controller"]
  node_price_response["API response<br/>response DTO<br/>[PriceResponse.java]"]
end

subgraph group_core["Aggregation core"]
  node_price_service["Price service<br/>orchestrator<br/>[PriceService.java]"]
  node_price_result["Aggregate price result<br/>domain DTOs<br/>[PriceResult.java]"]
  node_price_source["Price source<br/>vendor DTO<br/>[PriceSource.java]"]
  node_price_cache["Price cache service<br/>cache gateway"]
end

subgraph group_integration["Vendor integration"]
  node_price_aggregator["Price aggregator<br/>aggregation boundary"]
  node_amazon_client["Amazon client<br/>WebClient adapter<br/>[AmazonClient.java]"]
  node_walmart_client["Walmart client<br/>WebClient adapter<br/>[WalmartClient.java]"]
  node_flipkart_client["Flipkart client<br/>WebClient adapter"]
  node_retailer_mocks{{"Retailer mock services<br/>external services"}}
  node_local_mock["Local mock vendor API<br/>mock controller"]
end

subgraph group_platform["Platform services"]
  node_app{{"Spring Boot application<br/>bootstrap"}}
  node_resilience_async["Resilience and async execution<br/>execution infrastructure<br/>[PriceConfig.java]"]
  node_redis[("Redis<br/>cache store")]
  node_redis_config["Redis configuration<br/>infrastructure config<br/>[RedisConfig.java]"]
  node_webclient_config["WebClient configuration<br/>HTTP client config"]
  node_deployment["Docker deployment<br/>container topology<br/>[docker-compose.yml]"]
end

node_app -->|"starts HTTP pipeline"| node_trace_filter
node_trace_filter -->|"correlated request"| node_price_controller
node_price_controller -->|"productId + refresh flag"| node_price_service
node_price_service -->|"read/write cached response"| node_price_cache
node_price_service -->|"cache miss or refresh"| node_price_aggregator
node_price_service -->|"builds"| node_price_result
node_price_result -->|"contains vendor outcomes"| node_price_source
node_price_service -->|"maps to"| node_price_response
node_price_aggregator -->|"protected async calls"| node_resilience_async
node_price_aggregator -->|"delegates"| node_amazon_client
node_price_aggregator -->|"delegates"| node_walmart_client
node_price_aggregator -->|"delegates"| node_flipkart_client
node_amazon_client -->|"Amazon endpoint"| node_retailer_mocks
node_walmart_client -->|"Walmart endpoint"| node_retailer_mocks
node_flipkart_client -->|"Flipkart endpoint"| node_retailer_mocks
node_price_cache -->|"cache operations"| node_redis
node_redis_config -.->|"configures connection"| node_redis
node_webclient_config -.->|"provides HTTP clients"| node_price_aggregator
node_deployment -.->|"runs container"| node_app
node_deployment -.->|"runs cache"| node_redis
node_local_mock -.->|"local development surface"| node_walmart_client

click node_app "https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/PriceAggregatorApplication.java"
click node_trace_filter "https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/config/TraceIdFilter.java"
click node_price_controller "https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/controller/PriceController.java"
click node_price_response "https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/dto/PriceResponse.java"
click node_price_service "https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/service/PriceService.java"
click node_price_result "https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/dto/PriceResult.java"
click node_price_source "https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/dto/PriceSource.java"
click node_price_cache "https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/service/PriceCacheService.java"
click node_price_aggregator "https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/external/PriceAggregator.java"
click node_amazon_client "https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/external/AmazonClient.java"
click node_walmart_client "https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/external/WalmartClient.java"
click node_flipkart_client "https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/external/FlipkartClient.java"
click node_local_mock "https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/mock/MockVendorController.java"
click node_resilience_async "https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/config/PriceConfig.java"
click node_redis_config "https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/config/RedisConfig.java"
click node_webclient_config "https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/config/WebClientConfig.java"
click node_deployment "https://github.com/codefarm0/price-aggregator/blob/main/docker-compose.yml"

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_trace_filter,node_price_controller,node_price_response toneBlue
class node_price_service,node_price_result,node_price_source,node_price_cache toneAmber
class node_price_aggregator,node_amazon_client,node_walmart_client,node_flipkart_client,node_retailer_mocks,node_local_mock toneMint
class node_app,node_resilience_async,node_redis,node_redis_config,node_webclient_config,node_deployment toneRose
```

## Components

### HTTP boundary

- [Trace ID filter](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/config/TraceIdFilter.java): servlet filter · Establishes MDC trace context and returns X-Trace-Id. · `src/main/java/in/codefarm/price/aggregator/config/TraceIdFilter.java`
- [Price controller](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/controller/PriceController.java): REST controller · Serves GET /api/prices/{productId} and cache-refresh requests. · `src/main/java/in/codefarm/price/aggregator/controller/PriceController.java`
- [API response](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/dto/PriceResponse.java): response DTO · `src/main/java/in/codefarm/price/aggregator/dto/PriceResponse.java`

### Aggregation core

- [Price service](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/service/PriceService.java): orchestrator · Coordinates cache lookup, vendor aggregation, cache write, and response creation. · `src/main/java/in/codefarm/price/aggregator/service/PriceService.java`
- [Aggregate price result](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/dto/PriceResult.java): domain DTOs · Models aggregate and vendor-level price outcomes. · `src/main/java/in/codefarm/price/aggregator/dto/PriceResult.java`
- [Price source](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/dto/PriceSource.java): vendor DTO · `src/main/java/in/codefarm/price/aggregator/dto/PriceSource.java`
- [Price cache service](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/service/PriceCacheService.java): cache gateway · Encapsulates Redis-backed cached price responses. · `src/main/java/in/codefarm/price/aggregator/service/PriceCacheService.java`

### Vendor integration

- [Price aggregator](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/external/PriceAggregator.java): aggregation boundary · Coordinates vendor-specific price retrieval. · `src/main/java/in/codefarm/price/aggregator/external/PriceAggregator.java`
- [Amazon client](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/external/AmazonClient.java): WebClient adapter · `src/main/java/in/codefarm/price/aggregator/external/AmazonClient.java`
- [Walmart client](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/external/WalmartClient.java): WebClient adapter · `src/main/java/in/codefarm/price/aggregator/external/WalmartClient.java`
- [Flipkart client](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/external/FlipkartClient.java): WebClient adapter · `src/main/java/in/codefarm/price/aggregator/external/FlipkartClient.java`
- **Retailer mock services**: external services · Independently deployed Amazon, Walmart, and Flipkart mock endpoints.
- [Local mock vendor API](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/mock/MockVendorController.java): mock controller · Internal development-only mock surface. · `src/main/java/in/codefarm/price/aggregator/mock/MockVendorController.java`

### Platform services

- [Spring Boot application](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/PriceAggregatorApplication.java): bootstrap · Runs the price aggregation service on port 8080. · `src/main/java/in/codefarm/price/aggregator/PriceAggregatorApplication.java`
- [Resilience and async execution](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/config/PriceConfig.java): execution infrastructure · Applies circuit breaking, bulkheads, retry, time limits, and MDC propagation. · `src/main/java/in/codefarm/price/aggregator/config/PriceConfig.java`
- **Redis**: cache store
- [Redis configuration](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/config/RedisConfig.java): infrastructure config · `src/main/java/in/codefarm/price/aggregator/config/RedisConfig.java`
- [WebClient configuration](https://github.com/codefarm0/price-aggregator/blob/main/src/main/java/in/codefarm/price/aggregator/config/WebClientConfig.java): HTTP client config · `src/main/java/in/codefarm/price/aggregator/config/WebClientConfig.java`
- [Docker deployment](https://github.com/codefarm0/price-aggregator/blob/main/docker-compose.yml): container topology · Defines local service and Redis deployment. · `docker-compose.yml`

## Connections

- Spring Boot application → Trace ID filter: starts HTTP pipeline
- Trace ID filter → Price controller: correlated request
- Price controller → Price service: productId + refresh flag
- Price service → Price cache service: read/write cached response
- Price service → Price aggregator: cache miss or refresh
- Price service → Aggregate price result: builds
- Aggregate price result → Price source: contains vendor outcomes
- Price service → API response: maps to
- Price aggregator → Resilience and async execution: protected async calls
- Price aggregator → Amazon client: delegates
- Price aggregator → Walmart client: delegates
- Price aggregator → Flipkart client: delegates
- Amazon client → Retailer mock services: Amazon endpoint
- Walmart client → Retailer mock services: Walmart endpoint
- Flipkart client → Retailer mock services: Flipkart endpoint
- Price cache service → Redis: cache operations
- Redis configuration → Redis: configures connection
- WebClient configuration → Price aggregator: provides HTTP clients
- Docker deployment → Spring Boot application: runs container
- Docker deployment → Redis: runs cache
- Local mock vendor API → Walmart client: local development surface
