상품 및 재고 시스템 구조도

flowchart TD
GW["API Gateway<br>JWT 인증 · Routing"]

subgraph PS["Product Service"]

subgraph CL["Controller Layer"]
PC["ProductController"]
IC["InventoryController"]
end

subgraph SL["Service Layer"]
PSvc["ProductService<br>상품 관리<br>Cache 무효화"]
ISvc["InventoryService<br>재고 선점<br>재고 차감 · TTL 관리"]
end

subgraph RL["Repository Layer"]
PR["ProductRepository"]
IR["InventoryRepository"]
end

OEP["Outbox Publisher"]
KC["Kafka Consumer<br>PAYMENT_DONE 소비 <br>→ 멱등성 확인 <br>→ 확정 차감 트리거"]
end

subgraph INFRA["Infrastructure"]
DB["MySQL"]
RD["Redis"]
OT["Outbox Tables"]
FL["Failed Event Logs"]
end

%% Request Flow
GW --> PC
GW --> IC

PC --> PSvc
IC --> ISvc

PSvc --> PR
ISvc --> IR

%% Redis
PSvc -. Cache .-> RD
ISvc -. Reserve .-> RD

%% Event
PR --> OEP
IR --> OEP

IR --> KC
KC --> OEP

%% DB
PR --> DB
IR --> DB

%% Infra
OEP --> OT

KC --> DB
KC --> FL

%% Styles
classDef gateway fill:#dbeafe,stroke:#2563eb,stroke-width:2px
classDef controller fill:#dbeafe,stroke:#3b82f6,stroke-width:2px
classDef service fill:#dcfce7,stroke:#16a34a,stroke-width:2px
classDef repository fill:#fef3c7,stroke:#ca8a04,stroke-width:2px
classDef event fill:#ede9fe,stroke:#7c3aed,stroke-width:2px
classDef infra fill:#f3f4f6,stroke:#6b7280,stroke-width:2px

class GW gateway
class PC,IC controller
class PSvc,ISvc service
class PR,IR repository
class OEP,KC,OT event
class DB,RD,FL infra