Best Modular Monolith Tools: 10 Options for Enforcing Boundaries and Extracting Services

BY ADAM WASIELEWSKIDEC 01, 202622 MIN READ

/TABLE OF CONTENTS

/ARTICLE

/ARTICLE

[1]TL;DR

  • A modular monolith keeps one deployable and adds modules with a small public API and hidden internals, which is the pattern research literature describes as combining a monolith's simplicity with microservice-style boundaries.
  • Graftcode leads this list because it covers what the other nine tools leave open: the same generated call runs in memory inside the monolith or against a Gateway after extraction, with the host setting in GraftConfig as the switch, and modules can be written in .NET, Node.js, TypeScript, Java, Python, PHP or Ruby.
  • The other nine tools do three jobs: defining modules (Spring Modulith, ABP Framework, jMolecules), enforcing boundaries in CI (ArchUnit, ArchUnitNET, Packwerk, Deptrac, Sonar Architecture) and organizing the repository (Nx).
  • Java teams can start with Spring Modulith, which is free under Apache 2.0, and Rails teams can use Packwerk, an MIT-licensed gem with a release as recent as November 2026. Sonar Architecture needs a commercial SonarQube edition, and the cross-language boundary rule in Nx comes from its open-source Conformance plugin.
  • Service Weaver, Google's Go framework for modular monoliths, is no longer an option: Google ended active development on December 5, 2024, and the repository was archived in March 2026.

A modular monolith is one of the more practical answers to a common question: how do you keep a growing codebase understandable without paying the cost of a distributed system? Teams adopt the pattern to separate business domains inside one deployable application, so that ownership is clear, a change in one domain stays in that domain, and a later move to services does not require untangling the code first.

This guide compares ten tools that help build and maintain a modular monolith. Each entry covers what the tool does, its strengths and weaknesses, and its pricing, with a comparison table and a stack-based decision guide near the end. Graftcode comes first because it handles how modules call each other and how a module later moves out of the process, which the other nine tools do not. The remaining nine are grouped by the job they do, because the best fit depends on the language and framework the monolith already uses.

[2]What Is a Modular Monolith Architecture?

By a common definition, a modular monolith is a single deployable application organized into well-defined modules based on business domains. Each module exposes a small public API, keeps its implementation internal, and declares which other modules it depends on.

The difference from an ordinary monolith is enforcement. Folders alone do not stop one module from calling another module's internal classes, and over time those shortcuts tangle the codebase. A modular monolith adds rules, and the tools in this guide check those rules during builds and tests so that violations fail early.

The running example in this guide is a SaaS order-management application with three modules: Orders, Billing and Inventory. Orders may call the public API of Billing, but it must not reach into Billing's repository classes. The next diagram shows where this pattern sits between a tangled monolith and a set of microservices.

Diagram showing a modular monolith between a tangled monolith and microservices

The boundary rule itself is simple, as the second diagram shows. What differs between tools is how the rule is declared, such as annotations, configuration files or test code, and when it is checked.

Diagram of the module boundary rule between Orders and Billing

[3]How These Modular Monolith Tools Were Chosen

Each tool in this guide was checked against its own documentation, repository or pricing page. The criteria were the language and framework it supports, whether it defines or enforces module boundaries, how it supports extracting a module later, and what it costs. Where a source did not state a detail, such as a license on a documentation page, the entry leaves that detail out.

The tools do different jobs, so the next diagram groups them into four categories. A team often picks one framework or convention for defining modules and one checker for enforcement, then adds a repository tool or a cross-runtime layer if the codebase calls for it.

Diagram grouping the ten modular monolith tools into four categories

[4]Best Modular Monolith Tools in 2026

1. Graftcode

Graftcode

Graftcode is a runtime integration system for generated, package-based method calls between modules or services. It addresses the part of a modular monolith that frameworks and checkers do not cover: how modules call each other, and how that call changes when a module leaves the process. A Receiver exposes public methods and is hosted by the Graftcode Gateway (gg), and a Caller installs a generated, strongly typed Graft and calls the Receiver as if it were local code.

The execution modes documentation explains how this works for a monolith. Generated Graft templates default the host setting in GraftConfig to inmemory, so the Receiver runs in the same process as the Caller with no network hop. In that mode the Caller must be able to resolve the Receiver module locally, which the module setting in GraftConfig provides, and whether the generated package already includes the Receiver depends on the ecosystem. Setting the host to a WebSocket address such as wss:// sends the same generated call to a Gateway that hosts the module elsewhere, and that remote setting needs no module path. In .NET the settings look like this:

csharp
// Monolith: the Receiver runs in the same process as the Caller
GraftConfig.Host = "inmemory";
GraftConfig.Module = "Billing.dll"; // exact module id from the generated package or Vision
// After extraction: point the same Graft at the Gateway that hosts the module
GraftConfig.Host = "wss://billing.internal/ws";

In the order-management example, Billing can stay in memory until it needs its own scaling or release cycle. At that point the team starts a Gateway for the compiled module and changes the host setting in the Orders module, and the call site stays as it was. The Gateway repository shows the launch form, and gg scans the current directory for modules and detects the runtime when no options are given:

bash
./gg ./Billing.dll --port 8888

The diagram below shows the two modes side by side.

Graftcode in-memory and remote execution modes side by side

Best for: Systems where modules are written in different languages, or teams that expect to extract specific modules into services later.

Pros

  • The execution mode changes through configuration and the generated call site stays the same, so extracting a module does not require rewriting its callers.
  • The scenario guide lists a polyglot in-memory runtime that runs modules from multiple languages in one process, including switching between monolith and microservices.
  • The supported-language list covers .NET, Node.js and TypeScript, Java and JVM, Python, PHP and Ruby, both for hosting code with the Gateway and for generating Grafts.
  • The Gateway can also expose hosted module methods as Model Context Protocol tools, according to the Gateway repository, which makes the same modules available to AI agents.

Cons

  • Graftcode connects modules but does not check dependency rules, so teams still pair it with a boundary checker such as ArchUnit, ArchUnitNET, Packwerk or Deptrac.
  • In-memory calls still represent and transfer arguments and results, so the documentation advises against describing them as zero-copy or equal to a direct language call.
  • Remote execution adds transport availability, latency, authentication and partial-failure concerns that generated typing does not remove, and the Gateway that hosts the module has to be operated and scaled with the service.
  • The public contract should use primitives, strings and plain models, and static, stateless methods scale best.

Pricing: The documentation states that a free standalone Gateway exists, and the Graftcode site invites visitors to create a free account. Paid plans are not published on the site, so confirm terms with Graftcode for production use.

2. Spring Modulith

Spring Modulith

Spring Modulith is the Spring project for building well-structured Spring Boot applications from domain-driven application modules. According to the reference documentation, each direct sub-package of the main application package becomes a module, with provided and required interfaces, optional named interfaces for additional exposed packages, and allowedDependencies declarations in package-info.java. In a typical layout the application class sits in a main package such as example, with example.order and example.inventory as modules. Types in a module's base package form its API, and sub-packages such as example.order.internal stay hidden from other modules. A module that needs to expose more than its base package declares a named interface with @NamedInterface("spi") on a package, and other modules refer to it as order :: spi in allowedDependencies. Calling ApplicationModules.of(Application.class).verify() in a test turns these declarations into a failing build when a module reaches into another module's internals.

Modules can also interact through application events, which the documentation counts as part of a module's provided and required interfaces, so Orders can publish an event that Billing listens to without a direct method call. The @Modulithic annotation customizes the system name, shared modules and additional packages, and a module can be marked as open with type = Type.OPEN to ease the migration of an existing codebase, which the documentation recommends for migration rather than as a target design. The project page also lists integration testing of individual modules, module-level observability and generated documentation such as component diagrams.

Best for: Java and Kotlin teams already on Spring Boot.

Pros

  • Verification checks the module structure, so internal access across modules can fail a build.
  • Application events published and listened to by modules are part of the module model, so event-based interaction between modules is visible in the generated documentation and in verification.
  • The @ApplicationModuleTests annotation supports integration tests for a single module.
  • The Documenter class generates component diagrams and module canvases from the code.
  • It is open source under Apache 2.0 and maintained by the Spring team.

Cons

  • It supports Spring Boot applications only.
  • Without explicit declarations, a module may depend on any other module's API, so teams have to add allowedDependencies to get strict rules.
  • The compiler does not stop a public type in an internal package from being referenced, so the verification step has to run in CI.

Pricing: Free and open source. Current releases are listed on the project page.

3. ABP Framework

ABP Framework

ABP Framework is a .NET application framework built around reusable modules, and it offers a Modular Monolith startup template next to Layered and microservice templates. In ABP, every module is a class derived from AbpModule, and a module declares its direct dependencies with the [DependsOn] attribute, for example [DependsOn(typeof(AbpAspNetCoreMvcModule))]. ABP resolves the full dependency graph at startup, initializes modules in dependency order and shuts them down in the reverse order. Each module registers its services in ConfigureServices, PreConfigureServices and PostConfigureServices run before and after the ConfigureServices methods of all modules, and OnApplicationInitialization is where the startup module typically builds the middleware pipeline.

The module development best practices guide is based on DDD layers, and modules that follow it are database-independent, so a module built that way can later be deployed as a microservice. The framework suits teams that want module structure, templates and prebuilt application modules in one package.

Best for: .NET teams that want a framework and templates rather than assembling rules themselves.

Pros

  • A Modular Monolith startup template gives a new project a module structure from the first commit.
  • Dependencies between modules are declared explicitly with [DependsOn], and ABP initializes and shuts modules down in dependency order.
  • The free Community tier includes the open-source core framework, the ABP CLI and basic application modules.
  • Paid tiers remove the 5-module integration limit and add commercial features.

Cons

  • The framework brings its own conventions, which is a larger commitment than adding a checker to an existing project.
  • [DependsOn] declares which modules depend on which, but the module documentation reviewed for this guide does not describe a check that blocks references to another module's internal types, so teams can pair it with a checker such as ArchUnitNET.
  • The Community tier limits module integration to 5 modules.
  • The pricing page does not state which tiers include the Modular Monolith template, so confirm that before choosing a tier.

Pricing: The ABP pricing page lists a free Community tier and commercial tiers: Team at $2,999 for 3 developer seats, Business at $5,999 and Enterprise at $9,999.

4. Nx

Nx

Nx is a build system for JavaScript and TypeScript monorepos, with plugins that extend it to other languages, including Java through Gradle and Maven and .NET. In a modular monolith, its project graph shows how projects depend on each other, and its module boundary enforcement constrains which projects may import which. Tags are declared as a tags array in project.json, or under an nx key in package.json, with values such as scope:client or scope:shared. The @nx/enforce-module-boundaries rule takes a depConstraints list in which each entry names a sourceTag and the tags its dependencies must carry through onlyDependOnLibsWithTags, so a constraint for scope:admin that allows scope:shared and scope:admin lets admin projects use only shared and admin libraries. Tag values can be an exact string, a glob that uses *, or a regular expression.

The Conformance rule @nx/conformance/enforce-project-boundaries is configured under conformance.rules in nx.json and uses onlyDependOnProjectsWithTags. It checks dependencies in the Nx project graph through nx conformance:check and works for any project type, including Java, Python and PHP, which is why it is the option for polyglot repositories.

Best for: TypeScript monorepos where each module is a library or project in the workspace.

Pros

  • Boundaries use tags set in project.json or package.json, plus depConstraints that state which tags may depend on which.
  • The @nx/enforce-module-boundaries rule runs through ESLint or Oxlint and checks TypeScript imports and package.json dependencies.
  • Task caching and affected commands keep builds fast as the number of modules grows.

Cons

  • The lint rule covers JavaScript and TypeScript. The Conformance rule that works across languages comes from the separate Conformance plugin, which is MIT licensed and needs no Nx key, while rules hosted in Nx Cloud need the Enterprise plan.
  • Projects without tags cannot depend on other projects unless all tags are explicitly allowed, which adds setup work for existing repositories.

Pricing: The Nx pricing page lists a free Hobby plan with 50K monthly credits and up to 5 active contributors, a Team plan from $29 per month, a usage-based CI plan in beta and custom Enterprise pricing. See the Nx pricing page for current terms.

5. ArchUnit

ArchUnit

ArchUnit is a Java library for specifying and asserting architecture rules in plain Java. It analyzes bytecode and works with any plain Java unit testing framework, so a rule such as "classes in the Orders module must not depend on Billing internals" becomes a test that runs in CI.

Classes are imported with ClassFileImporter or through the @AnalyzeClasses annotation, and rules use a fluent API such as noClasses().that().resideInAPackage("..orders..").should().dependOnClassesThat().resideInAPackage("..billing.internal.."). The two dots in a package identifier match any number of package segments. For module work the library API is the more useful part: slices().matching("..myapp.(*)..").should().beFreeOfCycles() treats each package under myapp as a slice and fails on cyclic dependencies between slices, while layeredArchitecture() and onionArchitecture() define layers and the access allowed between them. With JUnit, fields annotated with @ArchTest are evaluated as rules, and ArchTests.in lets projects reuse rules grouped in another class.

Best for: Java teams that want boundary rules as ordinary tests, with or without Spring.

Pros

  • Rules are written in Java, so they live next to the code and follow the same review process.
  • It runs inside existing test frameworks and needs no separate service.
  • It pairs with Spring Modulith and jMolecules, which can supply architecture rules for ArchUnit to check.

Cons

  • It supports Java only.
  • Someone has to write and maintain the rules, and the checks cover only the rules that were written.
  • A rule that selects no classes fails by default, for example after a package rename, so rule sets need updating together with the code they describe.

Pricing: Free, published under the Apache License 2.0.

6. ArchUnitNET

ArchUnitNET

ArchUnitNET brings the same idea to C#: a library for asserting architecture rules in automated tests. It reads the architecture from the analyzed binaries and ships adapters for common .NET test frameworks such as xUnit and MSTest. The architecture is loaded once with new ArchLoader().LoadAssemblies(...).Build(), ideally into a static field that every test reuses, and rules start from Types(), Classes(), Interfaces() or MethodMembers(). A boundary rule for the running example reads Types().That().ResideInNamespace("Orders").Should().NotDependOnAny(Types().That().ResideInNamespace("Billing.Internal")), is checked with rule.Check(Architecture), and can carry a reason through Because("...") that appears when the rule fails. Extension packages exist for xUnit, xUnit v3, NUnit and MSTestV2.

Best for: .NET teams that want boundary tests without adopting a full framework.

Pros

  • Rules are written in C# with a fluent API and run as regular tests.
  • Rules can be combined with And and Or and described with As and Because, so a failing test states the intent of the boundary.
  • Test framework packages exist for several runners, including xUnit and MSTest.
  • It is licensed under Apache 2.0.

Cons

  • It supports .NET only.
  • The repository page shows no dedicated layer or slice API, so layers are built by hand as object providers from type predicates.
  • Because it reads binaries, the project documentation recommends running its tests in the Debug configuration.
  • As with ArchUnit, rule authoring and upkeep fall to the team.

Pricing: Free and open source.

7. Packwerk

Packwerk

Packwerk is a Ruby gem from Shopify that enforces boundaries and modularizes Rails applications. It groups files into packages, defines package-level constant visibility, and analyzes static constant references to flag any reference that crosses a package boundary. The tool builds on the Zeitwerk autoloader, which comes with Rails 6, and requires Ruby 2.7 or above. Setup is a gem 'packwerk' line in the Gemfile, bundle install, and bin/packwerk init to generate the configuration files. The design goal is to avoid false positives, at the cost of some false negatives, which fits teams that adopt it on an existing Rails monolith and tighten the boundaries in stages.

Best for: Ruby on Rails monoliths.

Pros

  • It sets package-level boundaries between Ruby constants, so cross-package references are flagged.
  • It is designed for incremental adoption in codebases that already exist.
  • The gem is actively released, with version 3.4.0 published on November 30, 2026 under the MIT license.

Cons

  • It supports Ruby and Rails only.
  • Only constants loaded by the Zeitwerk autoloader can be resolved, and custom inflections or collapsed directories can cause false positives.
  • Only static constant references are analyzed, so method calls and object flow are ignored.
  • Third-party tools exist around Packwerk, including a Rust implementation called packs, so teams may need to choose between implementations.

Pricing: Free, MIT licensed. The GitHub repository is public.

8. jMolecules

jMolecules

jMolecules provides libraries that help developers express architectural abstractions in Java code. Instead of enforcing rules by itself, it adds annotations and types that make a design explicit, and other tools read them to verify the architecture.

The libraries are split by concern: jmolecules-ddd holds the DDD building blocks, jmolecules-events the event types, and jmolecules-architecture the architecture styles, with layered, onion, hexagonal and CQRS variants. The DDD annotations include @Entity, @Identity, @ValueObject and @Repository, and a type-based model offers interfaces such as AggregateRoot, Entity, Identifier and Association. With the type-based model, tools can verify that aggregates use dedicated identifier types, that aggregate roots refer only to their own entities, and that one aggregate refers to another only through an Association. In the running example, an Order aggregate in the Orders module would reference a Billing invoice through an Association instead of holding the invoice object. The integrations project adds support for Spring, Spring Data JPA, MongoDB and JDBC, and Jackson, and the ArchUnit rules in jmolecules-archunit verify the relationships between building blocks.

Best for: Java teams doing domain-driven design who want architecture visible in the code.

Pros

  • Package-level annotations such as @DomainLayer in package-info.java can mark a whole package as a layer or a port and adapter.
  • DDD building blocks, including aggregate roots, entities and an Association interface, make references between aggregates explicit.
  • Spring Modulith can detect jMolecules components, building blocks and events for its module model and documentation.

Cons

  • It needs a verification tool such as ArchUnit rules or the jQAssistant plugin to enforce anything.
  • The repository does not describe modular monoliths directly, so the module story comes from combining it with other tools.

Pricing: Free under Apache-2.0.

9. Deptrac

Deptrac

Deptrac is a static analysis tool for PHP that defines, visualizes and enforces architectural rules. The Deptrac documentation describes keeping bundles or modules independent of each other and running the check in CI to block pull requests that break the rules. In the configuration, layers are named groups of classes selected by collectors such as ClassLikeConfig::create('.Controller.'), which matches the fully qualified class name including the namespace, and a ruleset lists the layers that each layer may access, for example Ruleset::forLayer($controller)->accesses($service). A layer with no accesses entry may not use any other layer, so the default is strict.

Running vendor/bin/deptrac analyse reports each violation with its reason, such as DependsOnDisallowedLayer, the source and target classes, and the file and line. The summary table counts violations, skipped violations, uncovered dependencies, allowed dependencies, warnings and errors, and skipped violations do not fail the run, which gives teams a way to adopt the rules on an existing codebase and clear the backlog gradually.

Best for: PHP and Symfony or Laravel applications.

Pros

  • A deptrac.php file, generated with deptrac init, defines the directories to scan, the layers and the rulesets.
  • Collectors match class names by regular expression, so layers can follow naming conventions.
  • The report separates violations, skipped violations and uncovered dependencies, so rules can be introduced gradually without failing every build on day one.
  • An optional Graphviz formatter draws layers, rules and violations.

Cons

  • It supports PHP only, and it needs PHP 8.2 or later to run, although it can analyze projects targeting older PHP versions.
  • The original repository was archived on February 17, 2025, and the project continues under the deptrac organization on GitHub, so update old links and install instructions.

Pricing: Free. The original repository lists an MIT license.

10. Sonar Architecture

Sonar Architecture

Sonar Architecture is the architecture analysis feature of SonarQube. It builds a current architecture view from each analysis, grouping classes and files recursively by package, folder or module and arranging the containers so that relationships generally flow from left to right. Teams can also define an intended architecture in the Architecture > Intended architecture editor of the SonarQube UI by adding containers and sub-containers and declaring which sibling containers may depend on each other, and any undefined dependency between siblings is treated as forbidden. Editing needs the Architecture Administrator permission, which project administrators have by default.

The analysis reports flaws such as tangles and oversized components, smells such as weak tangles and split responsibilities, and deviations from the intended architecture, which are raised as SonarQube issues. Deviations come in two types, wrong dependencies and wrong locations, and they appear only once an intended architecture has been defined and saved. The feature fits organizations that already run SonarQube and want boundary checks in the same quality gate.

Best for: Teams with a commercial SonarQube Server edition and Java, C#, JavaScript, Python or TypeScript code.

Pros

  • The intended architecture is modeled in a visual editor, so tech leads can define containers and allowed dependencies without writing configuration files.
  • Analysis runs as part of the normal scan, and it reports violations as issues.
  • Architecture views document the current structure for the whole team.

Cons

  • The SonarQube Server 2025.6 documentation states that the feature is available in all commercial editions and supported on Java, and the 2026.4 documentation lists C#, Java, JavaScript, Python and TypeScript. It is not available in the Community Build.
  • Per the 2026.4 documentation, no issues are raised until tech leads define the intended architecture.

Pricing: Commercial. Sonar's pricing page lists SonarQube Server in Developer, Enterprise and Data Center editions, priced per instance per year by lines of code.

[5]Modular Monolith Tools Comparison Table

ToolCategoryStackChecks boundariesPricing
GraftcodeConnect modules.NET, Node.js and TypeScript, Java, Python, PHP, RubyNo, it handles calls between modulesFree standalone Gateway; paid plans not published
Spring ModulithDefine modulesJava, Spring BootYes, through verificationFree, Apache 2.0
ABP FrameworkDefine modules.NETFramework conventionsFree Community tier; paid from $2,999
NxOrganize repositoryJavaScript, TypeScript, plugins for othersYes, lint rule for JS/TS and Conformance rule for other languagesFree Hobby plan; Team from $29 per month
ArchUnitEnforce boundariesJavaYes, through testsFree, Apache 2.0
ArchUnitNETEnforce boundaries.NETYes, through testsFree, Apache 2.0
PackwerkEnforce boundariesRuby on RailsYes, through package checksFree, MIT
jMoleculesDefine modulesJavaNo, supplies annotations to other toolsFree, Apache-2.0
DeptracEnforce boundariesPHPYes, through CI checksFree
Sonar ArchitectureEnforce boundariesJava, C#, JavaScript, Python, TypeScript per the 2026.4 documentationYes, through quality analysisCommercial editions

[6]How to Choose the Right Modular Monolith Tool

The right starting point is the language and framework the monolith already runs on, because most tools in this guide are tied to one stack. The table below pairs each common stack with a first tool and a complementary enforcement tool, and it points to Graftcode for systems that span several languages or that plan to extract modules.

Recommended modular monolith tool by stack

Service Weaver is deliberately absent from the list. Its site states that Google ended active development on the framework effective December 5, 2024, and its GitHub repository was archived on March 4, 2026, so it is a poor basis for a new system.

[7]Where Should You Start with a Modular Monolith

A modular monolith works when modules have a small public API, hidden internals and rules that fail the build when someone breaks them. The tools above split by job and stack: Graftcode connects modules across runtimes and execution modes, Spring Modulith, ABP Framework and jMolecules define modules, ArchUnit, ArchUnitNET, Packwerk, Deptrac and Sonar Architecture check them, and Nx organizes the repository.

Start with the single tool that matches the current stack, add one boundary rule for the module that causes the most trouble, and run it in CI. For systems that mix languages or expect to extract a module into a service, read the Graftcode quick start and try the in-memory mode on one module before changing anything else.

[8]FAQ

Can a modular monolith replace microservices?

Yes, for many teams. A modular monolith keeps one deployable and one set of operational tooling while separating domains inside the code, so it avoids the cost of running distributed services. Teams extract individual modules into services later if a module needs its own scaling or release cycle.

Do you need a tool to build a modular monolith?

No, but one is strongly recommended. Folders and naming conventions can express modules, yet nothing stops a developer from reaching into another module's internals. A framework such as Spring Modulith or a checker such as ArchUnit, Packwerk or Deptrac turns the conventions into failing builds.

Can modules in one monolith be written in different languages?

Yes, with a runtime layer built for it. Most tools in this guide support one language, but Graftcode documents a polyglot in-memory runtime that runs modules from several technologies in one process. Teams should still check the supported language pairs in the Graftcode documentation before committing.

Is Service Weaver still a good choice for a modular monolith?

No. Google announced that it ended active development of the framework on December 5, 2024, and the repository is now archived. Existing applications can continue to run it, but new projects are better served by the maintained tools above.

Can you extract a module into a service later?

Yes, and that is one of the main reasons to build a modular monolith. Clean boundaries make extraction a smaller job, and tools such as Spring Modulith verify the structure first. Graftcode adds a way to keep the call site unchanged when the host setting points at a Gateway instead of running in memory.

/WRITTEN BY

Adam Wasielewski

A comparison of 10 modular monolith tools that define modules, enforce boundaries in CI and make it easier to extract a service later, with pros, cons, pricing and a decision guide by stack.

/TAGS

    /RELATED POSTS