Skip to content

Architecture Overview

Mason Batchelor edited this page Mar 6, 2026 · 1 revision

Architecture Overview

Four-Layer DDD Design

The backend is organized into four strict layers:

api → application → core ← infrastructure

API Layer (io.spring.api)

HTTP controllers (REST) and GraphQL DGS components. Thin adapters with no business logic. Controllers validate input, delegate to application services, and format responses.

Application Layer (io.spring.application)

CQRS services split into command (write) and query (read) paths:

  • ArticleCommandService — creates and updates articles
  • ArticleQueryService — fetches articles with pagination (offset and cursor)
  • UserService — user registration and profile updates
  • ProfileQueryService — user profiles with follow state

Core Layer (io.spring.core)

Domain entities and repository interfaces. Zero framework dependencies. This layer defines:

  • User, Article, Comment, Tag entities
  • UserRepository, ArticleRepository, CommentRepository interfaces
  • FollowRelation, ArticleFavorite value objects

Infrastructure Layer (io.spring.infrastructure)

Technical implementations:

  • MyBatis repository implementations
  • DefaultJwtService — JWT signing and parsing
  • NaiveEncryptService — password hashing
  • MyBatis type handlers (DateTimeHandler)

CQRS Pattern

Reads and writes are separated:

  • Write path: Controllers → CommandService → Core Repository Interface → MyBatis Implementation
  • Read path: Controllers → QueryService → MyBatis XML Mappers (direct SQL)

The read path bypasses domain entities entirely, querying directly into *Data DTOs for performance.

Authentication Flow

  1. Client sends Authorization: Token <jwt> header
  2. JwtTokenFilter extracts and validates the token via JwtService
  3. User is loaded from UserRepository and set in SecurityContextHolder
  4. WebSecurityConfig defines which routes require authentication

Clone this wiki locally