Designing a Modular Spring Boot Backend Project: Principles, Module Structure, and Maven Configuration
This article presents a comprehensive guide to building a Spring Boot backend system by outlining essential design principles, detailing a multi‑module architecture with clear responsibilities, and providing complete Maven POM configurations for each module to enable scalable and maintainable development.
The author, identified as "Guide Master," shares a personal experience of starting a backend management project named Xiaole and reflects on the challenges of designing a satisfactory architecture, ultimately proposing a self‑crafted model design based on common best practices.
Key design principles for a robust Spring Boot module are enumerated, including:
Single Responsibility Principle – each module should focus on one well‑defined function.
High Cohesion – related classes and components stay together to improve understandability.
Low Coupling – dependencies between modules are minimized to allow independent changes.
Reusability – modules are built as reusable components for future projects.
Clear Boundaries and Interfaces – explicit interfaces make inter‑module interactions obvious.
Moderate Modularity – group related functionality without over‑fragmentation.
Layered Architecture – separate layers such as controller, service, and data access.
Dependency Inversion – depend on abstractions rather than concrete implementations.
Testability – design modules to be easily unit‑tested and integration‑tested.
Adaptability for Future Extension – anticipate future feature growth.
The article then walks through creating the project in IntelliJ IDEA, showing a high‑level architecture diagram (image omitted) and presenting the overall directory layout:
├─.idea
├─le-admin
│ └─src
│ ├─main
│ │ ├─java
│ │ │ └─com
│ │ │ └─le
│ │ │ └─admin
│ │ └─resources
│ │ └─META-INF
│ └─test
│ └─java
│ └─com
│ └─le
│ └─test
├─le-business
│ └─src
│ └─main
│ └─java
│ └─com
│ └─le
│ └─business
├─le-common
│ └─src
│ └─main
│ └─java
│ └─com
│ └─le
│ └─common
├─le-core
│ └─src
│ └─main
│ └─java
│ └─com
│ └─le
│ └─core
├─le-gen-code
│ └─src
│ └─main
│ ├─java
│ │ └─com
│ │ └─le
│ │ └─code
│ │ ├─config
│ │ ├─controller
│ │ ├─domain
│ │ ├─mapper
│ │ ├─service
│ │ └─util
│ └─resources
│ ├─mapper
│ └─vm
└─le-tripartite
└─src
└─main
└─java
└─com
└─le
└─tripartiteEach module is described in detail:
core – provides common configuration, interceptors, and global exception handling without business logic.
common – houses utility classes, constants, and shared configurations.
gen‑code – a helper module for code generation, using Velocity templates.
business – contains actual business services, domain logic, and data access (MyBatis, Redis, etc.).
tripartite – integrates third‑party services such as payment gateways.
admin – the management UI for monitoring and user administration.
For each module, the article supplies the corresponding Maven pom.xml snippet. Example for the core module:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.xiaole</groupId>
<artifactId>XiaoLe</artifactId>
<version>1.0.0</version>
</parent>
<groupId>com.le</groupId>
<artifactId>le-core</artifactId>
<name>le-core</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<!-- MyBatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<!-- MySQL driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.le</groupId>
<artifactId>le-business</artifactId>
</dependency>
</dependencies>
</project>Similar pom snippets are provided for common , gen‑code , business , tripartite , and admin modules, as well as the parent pom that aggregates all sub‑modules and defines shared properties such as Spring Boot version, Velocity version, and MyBatis version.
The article also explains why the import scope is used in Maven: it allows a parent pom to import dependencyManagement sections from other Maven projects, enabling modular project management, version control, and unified dependency handling across multiple modules.
Finally, a source code repository link ( https://gitee.com/paper_cup_cake/xiao-le ) is provided for readers to explore the full implementation.
Architect's Guide
Dedicated to sharing programmer-architect skills—Java backend, system, microservice, and distributed architectures—to help you become a senior architect.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.