How to Build a DDD‑Based Maven Archetype for a Scalable CMS

This article guides you through refining a classic three‑layer architecture into a domain‑driven design, structuring the project with Maven Archetype, and implementing a simple CMS with both backend (Spring Boot) and frontend (Vue) components, complete with step‑by‑step setup instructions.

JD Cloud Developers
JD Cloud Developers
JD Cloud Developers
How to Build a DDD‑Based Maven Archetype for a Scalable CMS

Introduction

There are many common DDD implementation architectures such as classic four‑layer, hexagonal (ports‑and‑adapters), Clean Architecture, and CQRS. All are suitable if mastered. This article starts from a three‑layer architecture, refines it into a custom application architecture, implements it as a Maven Archetype, and demonstrates it with a simple CMS project.

Application Architecture Evolution

Step 1 – Merge Data Model and DAO Layer

The data model is a anemic model that only holds properties and maps one‑to‑one with database tables. It is tightly coupled with ORM annotations, making it effectively the DAO layer.

Step 2 – Extract Business Logic from Service Layer

Typical Service methods become bulky transaction scripts. By moving business rules into a domain model, the Service only coordinates loading the domain, invoking its logic, and persisting the result.

public class Service {
    @Transactional
    public void bizLogic(Param param) {
        checkParam(param);
        Domain domain = loadDomain(param);
        SomeValue someValue = this.getSomeValueFromOtherService(param.getProperty2());
        domain.doBusinessLogic(param.getProperty1(), someValue);
        saveDomain(domain);
    }
}

Step 3 – Maintain Domain Object Lifecycle

Loading and saving domain objects are handled by a Repository component that abstracts persistence details from the upper layers.

public interface DomainRepository {
    void save(AggregateRoot root);
    AggregateRoot load(EntityId id);
}

Step 4 – Generalize and Abstract Layers

Infrastructure : rename Repository to infrastructure‑persistence; add packages like infrastructure‑cache or infrastructure‑gateway as needed.

User Interface : the Controller layer becomes ui‑web; other protocols become ui‑provider, ui‑subscriber, etc.

Application : Service layer becomes Application Service, containing only coordination logic.

Step 5 – Complete Package Structure

A dedicated launcher module holds the main class, keeping it separate from any UI module.

Reflections

After five refinement steps, the resulting diagram resembles both classic four‑layer and hexagonal architectures because they all describe the same input‑process‑output system.

Maven Archetype Introduction

Maven Archetype is a plugin that quickly generates a project’s skeleton, ensuring consistent structure and reducing manual setup.

Using ddd‑archetype

Clone the repository: git clone https://github.com/feiniaojin/ddd-archetype.git Run

archetype:create-from-project -Darchetype.properties=archetype.properties

in IDEA.

Install the generated archetype with mvn install.

Crawl the archetype catalog with mvn archetype:crawl.

Initialize a Project

Add the local archetype catalog to IDEA, select ddd‑archetype, fill in project information, and generate the project.

Code Example

Backend

The backend, created with the ddd‑archetype, uses Spring Boot, H2 in‑memory database, and Spring Data JDBC. It implements DDD concepts such as Entity, Value Object, Aggregate Root, Factory, Repository, and CQRS.

GitHub: https://github.com/feiniaojin/ddd-example-cms

Frontend

The frontend is built with vue‑element‑admin. Installation details are in the repository README.

GitHub: https://github.com/feiniaojin/ddd-example-cms-front

Conclusion

By refining an anemic three‑layer architecture, we derived a practical DDD‑oriented application structure and packaged it as a Maven Archetype for rapid project bootstrapping. Fully mastering DDD still requires deeper study of bounded contexts, context mapping, rich models, factories, repositories, and related patterns.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaBackend DevelopmentmavenSpring BootDDDArchetype
JD Cloud Developers
Written by

JD Cloud Developers

JD Cloud Developers (Developer of JD Technology) is a JD Technology Group platform offering technical sharing and communication for AI, cloud computing, IoT and related developers. It publishes JD product technical information, industry content, and tech event news. Embrace technology and partner with developers to envision the future.

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.