# f-lab-edu/temm-server architecture

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

- Interactive diagram: https://gitdiagram.com/f-lab-edu/temm-server
- Repository: https://github.com/f-lab-edu/temm-server

## Overview

1. **Overall shape**
   - This is a **Spring Boot / Java** backend with a clear layered architecture: **API → application services → domain model/repositories → infrastructure**.
   - The codebase is centered on two implemented business areas: **social login / JWT authentication** and **product management**. The README also describes broader store/location/inventory workflows, but those subsystems are **not present in the current file tree**.

2. **Entry point and runtime**
   - `TemmApplication` is the application bootstrap.
   - `build.gradle.kts` and Gradle wrapper indicate a standard JVM service build.
   - `application.yaml` plus a separate test `application.yaml` provide environment-specific configuration.
   - `src/main/resources/static/login.html` and `index.html` suggest a small server-rendered/static front door used for login/demo flows, not a full SPA frontend.

3. **API layer**
   - HTTP endpoints live under `app/api/controller`.
   - `OauthController` handles social login-related requests.
   - `ProductController` exposes product CRUD/search endpoints.
   - Request/response boundary objects live in `app/api/dto`, so controllers do not directly expose domain entities.
   - `SocialTypeConverter` is a small API-adjacent adapter for translating incoming social provider values into domain types.

4. **Application service layer**
   - Business orchestration happens in `app/service`.
   - `OAuthLoginService` owns the login flow and token issuance.
   - Product use cases are split by responsibility:
     - `ProductRegisterService`
     - `ProductUpdateService`
     - `ProductLifecycleService`
     - `ProductQueryService`
   - `SocialUserProviderFinder` selects the correct social provider implementation based on login type.
   - The service layer uses command/DTO-style inputs such as `ProductRegisterCommand`, `ProductUpdateCommand`, and `LoginResult`, keeping the API layer decoupled from persistence details.

5. **Authentication and authorization flow**
   - The login flow is designed around **social OAuth + JWT**:
     - the client starts with OAuth login,
     - the backend exchanges/verifies social credentials,
     - the backend resolves or creates a local user,
     - `JwtTokenProvider` issues an application JWT.
   - Security is enforced by custom filters in `app/security`:
     - `JwtAuthenticationFilter` authenticates requests with JWTs,
     - `LoginCheckFilter` enforces login requirements,
     - `LoginContextHolderFilter` stores per-request authenticated user context,
     - `LoginContext` carries the current authenticated identity.
   - `SecurityConfig` wires these filters into the Spring Security chain.

6. **External identity integration**
   - Social login is abstracted through domain interfaces in `domain/provider`:
     - `SocialTokenProvider`
     - `SocialUserProvider`
   - Infrastructure implementations live in `app/infrastructure`:
     - `GoogleUserProvider`
     - `RestSocialTokenProvider`
   - This makes the social identity provider a replaceable boundary; the application layer depends on interfaces, not Google-specific code.

7. **Product domain model**
   - Core business entities live in `domain/model`:
     - `Product`
     - `Sku`
     - `Category`
     - `CategoryProduct`
     - `User`
     - `SocialInfo`
     - `Email`
     - `ProductStatus`
     - `SocialType`
   - The domain also contains validation and business exceptions such as `SkuNotValidException` and `EmailNotValidException`.
   - The model suggests that product/category relationships and user identity are enforced at the domain level rather than only at the database layer.

8. **Persistence boundaries**
   - Repository interfaces are in `domain/repository`:
     - `UserRepository`
     - `ProductRepository`
     - `CategoryRepository`
     - `ProductQueryRepository`
   - Query-heavy reads are separated into `ProductQueryRepository`, with a concrete QueryDSL-backed implementation in `app/infrastructure/ProductQueryDslRepository`.
   - `QueryDslConfig` indicates QueryDSL is used for more complex product search/filter queries beyond simple CRUD.
   - `JpaAuditingConfig` implies entity timestamps and audit metadata are managed automatically.

9. **Data flow for product use cases**
   - Product write operations typically flow:
     - controller request DTO → service command → domain aggregate/entity logic → repository save/update.
   - Product read/search operations flow:
     - controller search request → `ProductQueryService` → query repository / QueryDSL → domain result DTOs → API response DTOs.
   - Separate DTO sets exist for search, detail, status, and category views, which implies the API returns multiple projections rather than one generic product payload.

10. **Error handling and response normalization**
   - The API layer has centralized exception handling in `app/api/exception`.
   - `GlobalExceptionHandler`, `GlobalErrorCode`, and `ErrorResponse` standardize HTTP error output.
   - Domain/business exceptions are distinct from API-level errors, which helps keep validation and business-rule failures consistent across controllers.

11. **Infrastructure and integration config**
   - `OauthConfig`, `WebClientConfig`, and `SecurityConfig` are the main integration wiring points.
   - `WebClient` is used for outbound HTTP calls to social providers.
   - `JwtTokenProvider` is the application’s token infrastructure for stateless authentication.
   - `ProductQueryDslRepository` is the main persistence-side infrastructure adapter beyond standard JPA repositories.

12. **Database and schema management**
   - `src/main/resources/db/migration/V1__users_categories_products_ddl.sql` shows **Flyway**-style migration management.
   - The schema currently covers **users, categories, and products**, matching the implemented feature set.
   - The presence of `TestContainerForMySQL` indicates integration tests run against a real MySQL-compatible database environment rather than pure mocks.

13. **Testing and quality gates**
   - Tests mirror the production package structure, covering controllers, services, infrastructure, security, and domain models.
   - The repo includes a GitHub Actions workflow for **SonarCloud analysis**, indicating static quality checks are part of the delivery pipeline.
   - This test layout reinforces the architectural boundaries: each layer has its own verification scope.

14. **What is implemented vs. what is only in the README**
   - Implemented: **OAuth login, JWT security, product CRUD/search, category-related domain pieces**.
   - Not visible in this repo tree: **store management, location management, stock movement/adjustment workflows, alarms/notifications**.
   - So an architecture diagram for the current code should focus on the authentication and product subsystems, not the broader inventory operations described in the requirements.

15. **Key diagram boundaries**
   - The most important boundaries to draw are:
     - **HTTP/API boundary** at the controllers,
     - **security boundary** at the custom JWT/login filters,
     - **application orchestration boundary** at the service layer,
     - **domain boundary** around entities and business rules,
     - **persistence boundary** at repositories / QueryDSL / JPA,
     - **external identity boundary** at Google/WebClient-based social login.

Main entry points: [`src/main/java/io/github/ktg/temm/app/service/OAuthLoginService.java`](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/service/OAuthLoginService.java) (OAuth login), [`src/main/java/io/github/ktg/temm/app/config/SecurityConfig.java`](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/config/SecurityConfig.java) (App config), [`src/main/java/io/github/ktg/temm/app/api/controller/OauthController.java`](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/api/controller/OauthController.java) (OAuth API), [`src/main/java/io/github/ktg/temm/app/api/controller/ProductController.java`](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/api/controller/ProductController.java) (Product API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_temm_application(("TemmApplication<br/>Spring Boot entry"))
  node_static_frontdoor["Static front door<br/>HTML entry<br/>[index.html]"]
end

subgraph group_api["API"]
  node_oauth_controller["OAuth API<br/>REST controller"]
  node_product_controller["Product API<br/>REST controller"]
  node_api_dtos["API DTOs<br/>request/response models"]
  node_global_errors["API errors<br/>exception handler"]
end

subgraph group_service["Application"]
  node_oauth_login_service["OAuth login<br/>auth orchestration"]
  node_product_services["Product use cases<br/>application services"]
  node_social_finder["Social finder<br/>provider selector"]
end

subgraph group_domain["Domain"]
  node_product_domain{{"Product model<br/>aggregate<br/>[Product.java]"}}
  node_identity_domain{{"Identity model<br/>user/social model<br/>[User.java]"}}
  node_domain_ports["Domain ports<br/>repository/provider interfaces<br/>[TokenProvider.java]"]
  node_domain_rules["Domain rules<br/>business exceptions"]
end

subgraph group_infra["Infrastructure"]
  node_security_stack["Security stack<br/>filters/contexts"]
  node_app_config["App config<br/>Spring configuration"]
  node_jwt_provider["JWT provider<br/>token service"]
  node_social_integration["Social integration<br/>OAuth adapter"]
end

subgraph group_data["Persistence"]
  node_persistence_layer[("Persistence layer<br/>JPA/QueryDSL adapters")]
end

node_temm_application -->|"boots with"| node_app_config
node_temm_application -.->|"serves"| node_static_frontdoor
node_oauth_controller -->|"uses"| node_api_dtos
node_product_controller -->|"uses"| node_api_dtos
node_oauth_controller -->|"calls"| node_oauth_login_service
node_product_controller -->|"calls"| node_product_services
node_oauth_controller -.->|"handled by"| node_global_errors
node_product_controller -.->|"handled by"| node_global_errors
node_oauth_login_service -->|"selects"| node_social_finder
node_oauth_login_service -->|"verifies social login"| node_social_integration
node_oauth_login_service -->|"issues token"| node_jwt_provider
node_product_services -->|"mutates"| node_product_domain
node_product_services -->|"persists via"| node_persistence_layer
node_security_stack -->|"uses"| node_jwt_provider
node_app_config -->|"wires"| node_security_stack
node_app_config -->|"configures"| node_social_integration
node_app_config -->|"enables"| node_persistence_layer
node_product_domain -.->|"enforces"| node_domain_rules
node_identity_domain -.->|"depends on"| node_domain_ports
node_social_integration -->|"implements"| node_domain_ports
node_persistence_layer -->|"implements"| node_domain_ports

click node_temm_application "https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/TemmApplication.java"
click node_static_frontdoor "https://github.com/f-lab-edu/temm-server/blob/main/src/main/resources/static/index.html"
click node_oauth_controller "https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/api/controller/OauthController.java"
click node_product_controller "https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/api/controller/ProductController.java"
click node_api_dtos "https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/api/dto/ProductSearchRequest.java"
click node_global_errors "https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/api/exception/GlobalExceptionHandler.java"
click node_oauth_login_service "https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/service/OAuthLoginService.java"
click node_product_services "https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/service/ProductRegisterService.java"
click node_social_finder "https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/service/SocialUserProviderFinder.java"
click node_product_domain "https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/domain/model/Product.java"
click node_identity_domain "https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/domain/model/User.java"
click node_domain_ports "https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/domain/provider/TokenProvider.java"
click node_domain_rules "https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/domain/exception/BusinessException.java"
click node_security_stack "https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/security/JwtAuthenticationFilter.java"
click node_app_config "https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/config/SecurityConfig.java"
click node_jwt_provider "https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/infrastructure/JwtTokenProvider.java"
click node_social_integration "https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/infrastructure/GoogleUserProvider.java"
click node_persistence_layer "https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/domain/repository/ProductRepository.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_temm_application,node_static_frontdoor toneBlue
class node_oauth_controller,node_product_controller,node_api_dtos,node_global_errors toneAmber
class node_oauth_login_service,node_product_services,node_social_finder toneMint
class node_product_domain,node_identity_domain,node_domain_ports,node_domain_rules toneRose
class node_security_stack,node_app_config,node_jwt_provider,node_social_integration toneIndigo
class node_persistence_layer toneTeal
```

## Components

### Runtime

Application bootstrap and static entry resources.

- [TemmApplication](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/TemmApplication.java): Spring Boot entry · Application bootstrap and component scan root. · `src/main/java/io/github/ktg/temm/TemmApplication.java`
- [Static front door](https://github.com/f-lab-edu/temm-server/blob/main/src/main/resources/static/index.html): HTML entry · Minimal static/login pages used as a simple front entry. · `src/main/resources/static/index.html`

### API

HTTP controllers, request/response DTOs, and API error handling.

- [OAuth API](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/api/controller/OauthController.java): REST controller · Handles social login requests and token handoff. · `src/main/java/io/github/ktg/temm/app/api/controller/OauthController.java`
- [Product API](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/api/controller/ProductController.java): REST controller · Exposes product CRUD and search endpoints. · `src/main/java/io/github/ktg/temm/app/api/controller/ProductController.java`
- [API DTOs](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/api/dto/ProductSearchRequest.java): request/response models · Boundary objects for OAuth and product endpoints. · `src/main/java/io/github/ktg/temm/app/api/dto/ProductSearchRequest.java`
- [API errors](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/api/exception/GlobalExceptionHandler.java): exception handler · Normalizes controller failures into standard error responses. · `src/main/java/io/github/ktg/temm/app/api/exception/GlobalExceptionHandler.java`

### Application

Use-case orchestration for authentication and products.

- [OAuth login](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/service/OAuthLoginService.java): auth orchestration · Coordinates social login, user resolution, and JWT issuance. · `src/main/java/io/github/ktg/temm/app/service/OAuthLoginService.java`
- [Product use cases](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/service/ProductRegisterService.java): application services · Create, update, lifecycle, and query workflows for products. · `src/main/java/io/github/ktg/temm/app/service/ProductRegisterService.java`
- [Social finder](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/service/SocialUserProviderFinder.java): provider selector · Chooses the correct social user provider by login type. · `src/main/java/io/github/ktg/temm/app/service/SocialUserProviderFinder.java`

### Domain

Core business model, ports, and domain rules.

- [Product model](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/domain/model/Product.java): aggregate · Product, SKU, category linkage, and status rules. · `src/main/java/io/github/ktg/temm/domain/model/Product.java`
- [Identity model](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/domain/model/User.java): user/social model · User, social info, email, and social type concepts. · `src/main/java/io/github/ktg/temm/domain/model/User.java`
- [Domain ports](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/domain/provider/TokenProvider.java): repository/provider interfaces · Persistence and social integration contracts used by the application layer. · `src/main/java/io/github/ktg/temm/domain/provider/TokenProvider.java`
- [Domain rules](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/domain/exception/BusinessException.java): business exceptions · Validation and business-rule failures for email, SKU, and related invariants. · `src/main/java/io/github/ktg/temm/domain/exception/BusinessException.java`

### Infrastructure

Security, external identity, persistence adapters, and config.

- [Security stack](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/security/JwtAuthenticationFilter.java): filters/contexts · JWT authentication, login checks, and per-request login context. · `src/main/java/io/github/ktg/temm/app/security/JwtAuthenticationFilter.java`
- [App config](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/config/SecurityConfig.java): Spring configuration · Wires security, OAuth client access, QueryDSL, auditing, and WebClient. · `src/main/java/io/github/ktg/temm/app/config/SecurityConfig.java`
- [JWT provider](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/infrastructure/JwtTokenProvider.java): token service · Issues and validates application JWTs for stateless auth. · `src/main/java/io/github/ktg/temm/app/infrastructure/JwtTokenProvider.java`
- [Social integration](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/app/infrastructure/GoogleUserProvider.java): OAuth adapter · Google provider access and outbound token exchange via WebClient. · `src/main/java/io/github/ktg/temm/app/infrastructure/GoogleUserProvider.java`

### Persistence

Repository interfaces and query implementation boundary.

- [Persistence layer](https://github.com/f-lab-edu/temm-server/blob/main/src/main/java/io/github/ktg/temm/domain/repository/ProductRepository.java): JPA/QueryDSL adapters · Repository interfaces and QueryDSL-backed product reads. · `src/main/java/io/github/ktg/temm/domain/repository/ProductRepository.java`

## Connections

- TemmApplication → App config: boots with · Main application loads configuration and infrastructure beans.
- TemmApplication → Static front door: serves · Static pages provide a lightweight login/front door.
- OAuth API → API DTOs: uses · Maps HTTP payloads through request/response DTOs.
- Product API → API DTOs: uses · Maps product requests and responses through DTOs.
- OAuth API → OAuth login: calls · Delegates login orchestration to the application layer.
- Product API → Product use cases: calls · Delegates product workflows to application services.
- OAuth API → API errors: handled by · Controller failures are normalized into standard error responses.
- Product API → API errors: handled by · Controller failures are normalized into standard error responses.
- OAuth login → Social finder: selects · Resolves the provider implementation for a social login type.
- OAuth login → Social integration: verifies social login · Exchanges or validates external social credentials.
- OAuth login → JWT provider: issues token · Creates application JWTs after successful login.
- Product use cases → Product model: mutates · Applies product and category business rules.
- Product use cases → Persistence layer: persists via · Reads and writes through repository ports and query adapters.
- Security stack → JWT provider: uses · Security filters depend on token validation and creation logic.
- App config → Security stack: wires · Security configuration installs the custom filter chain.
- App config → Social integration: configures · OAuth and WebClient wiring support external identity calls.
- App config → Persistence layer: enables · JPA auditing and QueryDSL support persistence behavior.
- Product model → Domain rules: enforces · Business invariants raise domain-level exceptions.
- Identity model → Domain ports: depends on · Social and token abstractions stay at the domain boundary.
- Social integration → Domain ports: implements · Infrastructure provides concrete social provider adapters.
- Persistence layer → Domain ports: implements · Repository interfaces are backed by JPA and QueryDSL adapters.
