Building a DDD‑Based Four‑Layer Microservice Architecture with the D3boot Framework

The article walks through a DDD‑inspired four‑layer microservice architecture, explains how an application SDK enables RPC communication across services, details each architectural layer, and showcases the open‑source D3boot framework that bundles reusable base components, BOM management, and SaaS‑ready features for rapid backend development.

Architect's Journey
Architect's Journey
Architect's Journey
Building a DDD‑Based Four‑Layer Microservice Architecture with the D3boot Framework

Microservice Architecture Overview

Combines a DDD four‑layer structure for each service with a cross‑service Application SDK that provides RPC communication.

Application SDK Design

Implemented as a Maven sub‑module (similar to an RPC/API package). Contains Feign interfaces (e.g., service.XxxFeignService), DTOs ( contract.dto.XxxRequest, contract.dto.XxxResponse), and utility classes ( util.XxxUtil) that may wrap simple business logic. The SDK is built as a large‑scale independent aggregate; top‑level packages are isolated by internal business dimensions and the SDK is not a one‑to‑one mapping with a single business system.

Example: a company splits its top‑level systems into SaaS and PaaS. The PaaS side provides a PaaSSdk module that encapsulates external interfaces and simple logic for the message center, ChatAI, and app marketplace. SaaS services depend only on PaaSSdk, avoiding many JAR dependencies.

DDD Four‑Layer Service Structure

Access Layer : Controllers grouped by client type (mobile, admin, open).

Application Layer : Cross‑aggregate orchestration services ( service.XxxAppService), domain event listeners ( event.XxxListener), and factories ( factory.XxxFactory).

Domain Layer : Core business rules, aggregates, rich models, value objects, repository interfaces, domain services, and events. Contracts ( contract) contain DTOs, query parameters, and event definitions.

Infrastructure Layer : Technology‑specific implementations such as repository implementations ( repository.impl.XxxRepositoryImpl), external service adapters, and anti‑corruption layers.

D3boot Framework Integration

D3boot extends SpringBoot with reusable modules that implement the DDD four‑layer pattern and provide common infrastructure.

base‑core : Core context (SpringContext, ThreadContext, BaseContext), core contracts (R, Page, abstract events, exceptions, status codes), and utility classes (bean conversion, JSON handling, assertions).

base‑data : CRUD‑enabled rich models, MyBatis‑Plus repository implementations, type handlers, and @TenantId annotation for tenant data isolation.

base‑mq : Kafka integration with annotation‑driven consumers.

base‑kit : Utilities for caching, events, language helpers, threading, and web tools.

base‑monitor : Health checks, version printing, and log‑to‑robot alerting.

base‑web : CRUD controller base class ( CRUDControl), model controller interfaces, global exception handling, Feign fallback, interceptors, and basic authentication.

A Maven BOM ( base‑bom) centralises third‑party dependency versions, mirroring Spring’s BOM approach. Parent POMs ( base‑contract‑parent, base‑parent) accelerate SDK and business project setup. The demo project ddd‑demo illustrates the complete four‑layer structure.

Repository Links

Source code is hosted on Gitee:

https://gitee.com/jensvn/d3boot
JavaSDKArchitectureMicroservicesDDDSpringBoot
Architect's Journey
Written by

Architect's Journey

E‑commerce, SaaS, AI architect; DDD enthusiast; SKILL enthusiast

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.