# antonbas/sushi-shop architecture

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

- Interactive diagram: https://gitdiagram.com/antonbas/sushi-shop
- Repository: https://github.com/antonbas/sushi-shop

## Overview

#### Purpose and Entry Points
Sushi Shop is a Docker-deployable full-stack monolith for catalog browsing, checkout, Stripe payment, and role-based order delivery tracking. The React SPA starts at `frontend/src/main.tsx` and composes routes in `frontend/src/App.tsx`. The Java 21 Spring Boot API starts at `backend/src/main/java/com/sushishop/BackendApplication.java`. Deployment topology is defined by `compose.yaml`, with monitoring configuration in `prometheus.yml`.

#### Frontend Application and Client Boundaries
The React/TypeScript client separates storefront, profile, and administrative workflows, including cart state and protected routes. Authentication, cart, and notification state are application contexts in `frontend/src/context/AuthContext.tsx`, `frontend/src/context/CartContext.tsx`, and `frontend/src/context/NotificationContext.tsx`. REST calls are centralized under `frontend/src/api/client.ts` and domain API modules such as `frontend/src/api/orders.ts`; real-time order updates are consumed through `frontend/src/hooks/features/useWebSocket.ts`.

#### API, Security, and Identity
Feature controllers expose the server API; services enforce domain workflows; repositories persist JPA entities; DTOs/mappers bound external payloads to the domain. Spring Security applies JWT authentication and role access control through `backend/src/main/java/com/sushishop/shared/config/SecurityConfig.java` and `backend/src/main/java/com/sushishop/shared/security/jwt/JwtAuthenticationFilter.java`. Auth supports registration/login, verification and reset tokens, plus Google OAuth2 via `backend/src/main/java/com/sushishop/auth/AuthService.java`, `backend/src/main/java/com/sushishop/token/TokenService.java`, and `backend/src/main/java/com/sushishop/shared/security/oauth2/OAuth2AuthenticationSuccessHandler.java`.

#### Catalog, Promotions, and Reviews
Products are the storefront’s core read/write aggregate, with separate query, mutation, enrichment, and image-management responsibilities: `backend/src/main/java/com/sushishop/product/ProductService.java`, `backend/src/main/java/com/sushishop/product/ProductQueryService.java`, and `backend/src/main/java/com/sushishop/product/ProductImageService.java`. Specifications support filtered catalog queries, while enrichment supplies display-facing details. Promotions are independently managed and validated to avoid conflicting active product assignments in `backend/src/main/java/com/sushishop/promotion/PromotionService.java` and `backend/src/main/java/com/sushishop/promotion/PromotionValidator.java`. Reviews and replies attach customer feedback to products through `backend/src/main/java/com/sushishop/review/ReviewService.java`.

#### Order-to-Payment Lifecycle
Checkout sends cart/address/order-item data to the order boundary. `backend/src/main/java/com/sushishop/order/OrderCreationService.java` creates orders and items; `backend/src/main/java/com/sushishop/order/OrderService.java` manages status transitions; `backend/src/main/java/com/sushishop/order/OrderQueryService.java` supplies role-appropriate retrieval. Payments are persisted separately and delegated to Stripe through `backend/src/main/java/com/sushishop/payment/PaymentService.java` and `backend/src/main/java/com/sushishop/payment/StripeService.java`. `backend/src/main/java/com/sushishop/payment/PaymentConfirmedEvent.java` is the internal event boundary for confirmed-payment follow-on behavior.

#### Real-Time and Cross-Cutting Controls
Order status changes are broadcast using Spring WebSocket/STOMP configured in `backend/src/main/java/com/sushishop/shared/config/WebSocketConfig.java`, reaching the SPA’s WebSocket hook. Audit logging is AOP-driven rather than embedded in each domain workflow: `backend/src/main/java/com/sushishop/audit/AuditAspect.java` records annotated actions into the audit domain. Rate limiting is likewise aspect/service based in `backend/src/main/java/com/sushishop/shared/ratelimit/RateLimitAspect.java` and `backend/src/main/java/com/sushishop/shared/ratelimit/RateLimitService.java`; scheduled cleanup maintains expired tokens and rate-limit state.

#### Persistence and External Infrastructure
PostgreSQL is the authoritative relational store, versioned with Flyway migrations rooted at `backend/src/main/resources/db/migration/V1__init_schema.sql`. Redis is configured as shared cache/state infrastructure in `backend/src/main/java/com/sushishop/shared/config/RedisConfig.java`. Other external boundaries are Stripe, Google OAuth2, SMTP mail (`backend/src/main/java/com/sushishop/mail/MailService.java`), file storage (`backend/src/main/java/com/sushishop/file/FileStorageService.java`), and Prometheus/Grafana monitoring. Runtime profiles and service integration settings live in `backend/src/main/resources/application.yaml` and `backend/src/main/resources/application-docker.yml`.

Main entry points: [`backend/src/main/java/com/sushishop/BackendApplication.java`](https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/BackendApplication.java) (Spring Boot API), [`backend/src/main/resources/db/migration/V1__init_schema.sql`](https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/resources/db/migration/V1__init_schema.sql) (PostgreSQL), [`backend/src/main/java/com/sushishop/order/OrderService.java`](https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/order/OrderService.java) (Order lifecycle), [`backend/src/main/java/com/sushishop/auth/AuthService.java`](https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/auth/AuthService.java) (Auth & token workflows)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React SPA"]
  node_spa_entry["SPA entry &amp; routes<br/>React entry<br/>[main.tsx]"]
  node_client_state["Auth, cart &amp; notifications<br/>React contexts<br/>[AuthContext.tsx]"]
  node_rest_client["REST API client<br/>TypeScript API<br/>[client.ts]"]
  node_order_updates_client["Order update hook<br/>WebSocket client<br/>[useWebSocket.ts]"]
end

subgraph group_backend["Spring Boot API"]
  node_api_entry["Spring Boot API<br/>application entry"]
  node_security["JWT &amp; role security<br/>security filter chain"]
  node_identity["Auth &amp; token workflows<br/>identity service<br/>[AuthService.java]"]
  node_catalog["Catalog &amp; product media<br/>product services"]
  node_promotions_reviews["Promotions &amp; reviews<br/>domain services"]
  node_orders["Order lifecycle<br/>order services<br/>[OrderService.java]"]
  node_payments["Payment orchestration<br/>payment services"]
  node_realtime["STOMP order broadcasts<br/>WebSocket config"]
  node_audit_ratelimit["Audit &amp; rate limiting<br/>AOP controls<br/>[AuditAspect.java]"]
end

subgraph group_data["Data &amp; infrastructure"]
  node_postgres[("PostgreSQL<br/>relational database")]
  node_redis[("Redis<br/>cache and state<br/>[RedisConfig.java]")]
  node_docker_topology["Docker Compose<br/>deployment topology<br/>[compose.yaml]"]
end

subgraph group_external["External services"]
  node_stripe["Stripe<br/>payment provider"]
  node_google["Google OAuth2<br/>identity provider"]
  node_mail["SMTP mail<br/>mail delivery<br/>[MailService.java]"]
  node_storage["File storage<br/>media storage"]
  node_monitoring["Prometheus &amp; Grafana<br/>monitoring<br/>[prometheus.yml]"]
end

node_spa_entry -->|"uses"| node_client_state
node_spa_entry -->|"calls through"| node_rest_client
node_spa_entry -->|"subscribes"| node_order_updates_client
node_rest_client -->|"REST"| node_api_entry
node_order_updates_client -->|"STOMP"| node_realtime
node_api_entry -->|"secured by"| node_security
node_security -->|"authenticates via"| node_identity
node_api_entry -->|"catalog API"| node_catalog
node_api_entry -->|"promotion and review API"| node_promotions_reviews
node_api_entry -->|"checkout and order API"| node_orders
node_orders -->|"initiates payment"| node_payments
node_payments -->|"charges via"| node_stripe
node_payments -.->|"payment confirmed"| node_orders
node_orders -->|"status changes"| node_realtime
node_identity -->|"OAuth2"| node_google
node_identity -->|"sends verification/reset"| node_mail
node_catalog -->|"stores images"| node_storage
node_identity -->|"persists"| node_postgres
node_catalog -->|"persists"| node_postgres
node_promotions_reviews -->|"persists"| node_postgres
node_orders -->|"persists orders"| node_postgres
node_payments -->|"persists payments"| node_postgres
node_api_entry -->|"cache and shared state"| node_redis
node_audit_ratelimit -->|"writes audit data"| node_postgres
node_api_entry -.->|"cross-cutting controls"| node_audit_ratelimit
node_docker_topology -->|"deploys"| node_api_entry
node_docker_topology -->|"runs"| node_postgres
node_docker_topology -->|"runs"| node_redis
node_monitoring -.->|"scrapes metrics"| node_api_entry

click node_spa_entry "https://github.com/antonbas/sushi-shop/blob/master/frontend/src/main.tsx"
click node_client_state "https://github.com/antonbas/sushi-shop/blob/master/frontend/src/context/AuthContext.tsx"
click node_rest_client "https://github.com/antonbas/sushi-shop/blob/master/frontend/src/api/client.ts"
click node_order_updates_client "https://github.com/antonbas/sushi-shop/blob/master/frontend/src/hooks/features/useWebSocket.ts"
click node_api_entry "https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/BackendApplication.java"
click node_security "https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/shared/config/SecurityConfig.java"
click node_identity "https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/auth/AuthService.java"
click node_catalog "https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/product/ProductService.java"
click node_promotions_reviews "https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/promotion/PromotionService.java"
click node_orders "https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/order/OrderService.java"
click node_payments "https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/payment/PaymentService.java"
click node_realtime "https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/shared/config/WebSocketConfig.java"
click node_audit_ratelimit "https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/audit/AuditAspect.java"
click node_postgres "https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/resources/db/migration/V1__init_schema.sql"
click node_redis "https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/shared/config/RedisConfig.java"
click node_docker_topology "https://github.com/antonbas/sushi-shop/blob/master/compose.yaml"
click node_mail "https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/mail/MailService.java"
click node_storage "https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/file/FileStorageService.java"
click node_monitoring "https://github.com/antonbas/sushi-shop/blob/master/prometheus.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_spa_entry,node_client_state,node_rest_client,node_order_updates_client toneBlue
class node_api_entry,node_security,node_identity,node_catalog,node_promotions_reviews,node_orders,node_payments,node_realtime,node_audit_ratelimit toneAmber
class node_postgres,node_redis,node_docker_topology toneMint
class node_stripe,node_google,node_mail,node_storage,node_monitoring toneRose
```

## Components

### React SPA

- [SPA entry & routes](https://github.com/antonbas/sushi-shop/blob/master/frontend/src/main.tsx): React entry · `frontend/src/main.tsx`
- [Auth, cart & notifications](https://github.com/antonbas/sushi-shop/blob/master/frontend/src/context/AuthContext.tsx): React contexts · `frontend/src/context/AuthContext.tsx`
- [REST API client](https://github.com/antonbas/sushi-shop/blob/master/frontend/src/api/client.ts): TypeScript API · `frontend/src/api/client.ts`
- [Order update hook](https://github.com/antonbas/sushi-shop/blob/master/frontend/src/hooks/features/useWebSocket.ts): WebSocket client · `frontend/src/hooks/features/useWebSocket.ts`

### Spring Boot API

- [Spring Boot API](https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/BackendApplication.java): application entry · `backend/src/main/java/com/sushishop/BackendApplication.java`
- [JWT & role security](https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/shared/config/SecurityConfig.java): security filter chain · `backend/src/main/java/com/sushishop/shared/config/SecurityConfig.java`
- [Auth & token workflows](https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/auth/AuthService.java): identity service · Registration, login, verification, reset, and OAuth identity flows. · `backend/src/main/java/com/sushishop/auth/AuthService.java`
- [Catalog & product media](https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/product/ProductService.java): product services · Queries, mutations, enrichment, and image management. · `backend/src/main/java/com/sushishop/product/ProductService.java`
- [Promotions & reviews](https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/promotion/PromotionService.java): domain services · `backend/src/main/java/com/sushishop/promotion/PromotionService.java`
- [Order lifecycle](https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/order/OrderService.java): order services · Creates orders, transitions status, and provides role-scoped queries. · `backend/src/main/java/com/sushishop/order/OrderService.java`
- [Payment orchestration](https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/payment/PaymentService.java): payment services · Persists payments and handles confirmed-payment events. · `backend/src/main/java/com/sushishop/payment/PaymentService.java`
- [STOMP order broadcasts](https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/shared/config/WebSocketConfig.java): WebSocket config · `backend/src/main/java/com/sushishop/shared/config/WebSocketConfig.java`
- [Audit & rate limiting](https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/audit/AuditAspect.java): AOP controls · Cross-cutting aspects record actions and limit requests. · `backend/src/main/java/com/sushishop/audit/AuditAspect.java`

### Data & infrastructure

- [PostgreSQL](https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/resources/db/migration/V1__init_schema.sql): relational database · Authoritative JPA store, initialized by Flyway. · `backend/src/main/resources/db/migration/V1__init_schema.sql`
- [Redis](https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/shared/config/RedisConfig.java): cache and state · `backend/src/main/java/com/sushishop/shared/config/RedisConfig.java`
- [Docker Compose](https://github.com/antonbas/sushi-shop/blob/master/compose.yaml): deployment topology · `compose.yaml`

### External services

- **Stripe**: payment provider
- **Google OAuth2**: identity provider
- [SMTP mail](https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/mail/MailService.java): mail delivery · `backend/src/main/java/com/sushishop/mail/MailService.java`
- [File storage](https://github.com/antonbas/sushi-shop/blob/master/backend/src/main/java/com/sushishop/file/FileStorageService.java): media storage · `backend/src/main/java/com/sushishop/file/FileStorageService.java`
- [Prometheus & Grafana](https://github.com/antonbas/sushi-shop/blob/master/prometheus.yml): monitoring · `prometheus.yml`

## Connections

- SPA entry & routes → Auth, cart & notifications: uses
- SPA entry & routes → REST API client: calls through
- SPA entry & routes → Order update hook: subscribes
- REST API client → Spring Boot API: REST
- Order update hook → STOMP order broadcasts: STOMP
- Spring Boot API → JWT & role security: secured by
- JWT & role security → Auth & token workflows: authenticates via
- Spring Boot API → Catalog & product media: catalog API
- Spring Boot API → Promotions & reviews: promotion and review API
- Spring Boot API → Order lifecycle: checkout and order API
- Order lifecycle → Payment orchestration: initiates payment
- Payment orchestration → Stripe: charges via
- Payment orchestration → Order lifecycle: payment confirmed
- Order lifecycle → STOMP order broadcasts: status changes
- Auth & token workflows → Google OAuth2: OAuth2
- Auth & token workflows → SMTP mail: sends verification/reset
- Catalog & product media → File storage: stores images
- Auth & token workflows → PostgreSQL: persists
- Catalog & product media → PostgreSQL: persists
- Promotions & reviews → PostgreSQL: persists
- Order lifecycle → PostgreSQL: persists orders
- Payment orchestration → PostgreSQL: persists payments
- Spring Boot API → Redis: cache and shared state
- Audit & rate limiting → PostgreSQL: writes audit data
- Spring Boot API → Audit & rate limiting: cross-cutting controls
- Docker Compose → Spring Boot API: deploys
- Docker Compose → PostgreSQL: runs
- Docker Compose → Redis: runs
- Prometheus & Grafana → Spring Boot API: scrapes metrics
