Dec 1, 2026
Code Governance Across Architectural Styles with DDD
A practical account of code governance drawn from refactoring a product center: how governance differs from refactoring, where DDD code complexity comes from, how to govern code, and what to watch for from the Servlet/JSP era through microservices and mobile.
1. Background
1.1 Context
I have been refactoring my company’s product center as part of a broader move toward component-based services. We inherited it from another team: features were incomplete, several people had contributed, and coding styles were inconsistent. That made maintenance and componentization difficult.
I led the first two phases of the redesign, drawing on DDD and COLA. During that work, code governance began to look like a topic in its own right, rather than simply another name for refactoring. This chapter explores the relationship between governance, refactoring, and improving code smells.
1.2 Governance Versus Refactoring
Refactoring usually starts from a specific problem: existing code needs improvement, perhaps because it cannot support a new feature cleanly. Governance also covers the beginning of a project and its ongoing evolution.
Its scope includes code, scripts, comments, and closely related documentation. Refactoring improves something toward a particular goal; governance establishes conventions and practices intended to keep the project at a consistently high standard. In that sense, governance includes refactoring.
1.3 Governance and Coding Standards
Governance needs standards to work from, but not every convention must be mandatory in every situation. Some guidelines are advisory, while others require enforcement. Governance uses those conventions to improve both code and documentation. Without shared standards, the activity is closer to isolated refactoring or modification.
2. Software Complexity in DDD Code
2.1 Business Call Chains
- End-to-end call chains are too long.
- Internal calls take too much time.
- Similar capabilities repeat the same call chains.
- Call chains create performance or comprehension problems.
2.2 Code Layers
- Too many layers.
- Too few layers.
- A class or method is too long and carries too many responsibilities.
- Code freely references models and methods from other layers.
- Inconsistent styles undermine the layering and its management.
2.3 Models and Services
- Complex generalization, composition, and aggregation relationships.
- Multiple levels of service inheritance and scenario-specific logic.
- Model conversion between layers, such as BO/DO and BO/DTO.
- Serialization between database tables and DO/entity/RPC models.
- Models that are too minimal.
- Tight coupling to too many upstream, downstream, internal, or external systems.
2.4 Processes
- Interactions within a thread.
- Interactions with external business processes.
- Interactions with middleware processes.
3. Code Governance
3.1 What It Means
Code governance manages the code and scripts developers write, including test code. Think of organizing a room or kitchen: what should each item be called, how should it be used, where does it belong, how should it evolve, and how can it be moved without breaking its users?
It also covers coding style, names, service interfaces, packages, and modules.
3.2 Where Problems Arise
The following diagram collects lessons from the product-center refactoring and several years of development, including mistakes I have made and inconsistencies introduced through collaboration.

3.3 Benefits
What does governance improve, and where does the value come from? This mind map summarizes the benefits.

3.4 What to Govern
- By code type: enums, interfaces, constants, abstract classes, configuration, exceptions, and implementations.

- By framework: the classes, models, and entry points associated with each framework.

- By module responsibility: infrastructure, domain, RPC interface, HTTP interface, and application modules.

3.5 How to Govern Code

3.6 How This Relates to DDD
DDD introduces concepts and patterns that become confusing if their code representations are not maintained. Domain entity names and distinctions between entities and value objects are examples.
A project might represent domain entities with XXXBO, value objects with XXXEnum or XXXConfig, and infrastructure implementations with XXXAdapter, XXXMapper, or XXXRepoImpl. Under those conventions, a DTO appearing where a domain model is expected deserves scrutiny. If one developer calls a domain object a DTO and another calls the same kind of object a BO, the vocabulary becomes inconsistent.
DDD therefore needs code governance and coding conventions to remain effective in complex systems. Whatever the architectural style, modules and packages have responsibilities and dependency relationships. For large projects, I recommend repeated design reviews and code reviews at the implementation level.
4. Governance Across Development Styles
4.1 Servlet/JSP
In early web applications built with Servlets and JSP, filenames often reflected CRUD operations or modules. Business logic and call chains could be tangled; a JSP might query a database directly. Frontend assets were also embedded in JSP files, mixing concerns further.
4.2 Spring MVC
The SSH stack—Struts, Spring, and Hibernate—was widely used in this period, alongside custom frameworks. Integrating three frameworks with different conventions and responsibilities still left governance and layering problems. For small and medium-sized projects, however, their module structures could provide useful guidance.
4.3 RPC and Separate Web Frontends
As frontend and backend development became fully separated, their codebases became more specialized and somewhat easier to govern. Some management applications still kept frontend and backend code in one project, though.
4.4 Microservices
Microservices involve RPC, HTTP, messaging, and many other interaction patterns. Both the business and the technology are more complex, and the full chain from clients to backend systems crosses many layers. Governance becomes especially important: a performance problem or bug in one segment of a critical path can trigger cascading failures.
4.5 Android and iOS
My recent work has focused on backend development, so I do not have enough direct experience to cover governance on these platforms. Contributions from readers would be welcome.
5. Summary
As long as people write code and requirements change, code governance remains necessary. Like other forms of governance, it requires proactive work, sound judgment, and a balance between improving what exists and maintaining its usefulness.
The goal is better project structure and readability, fewer potential bugs and performance problems, and easier extension. Done well, it also improves engineering efficiency.
I have collected further references on code and module governance below.
6. References
- Alibaba’s Practices for Addressing iOS Architecture Erosion (WeChat article)
- 码出高效 (a Chinese book on efficient Java development).
- Refactoring.
- How to Write Elegant Code
- Alibaba Engineers on What Makes Good Code
- How Tencent Conducts Code Reviews
- Lessons from Thirteen Years of Coding at Huawei
- How to Conduct Effective Code Reviews
- Forty Java Performance Optimization Details
- Evolution of 58.com’s Android IM Modules for Parallel Development
- How 58.com Implemented Its App Factory
Comments
Comments are powered by GitHub Discussions. Sign in with GitHub to join the discussion.