Skip to main content

django-modulith

A toolkit for building modular, maintainable Django applications using the Modulith architectural pattern.

What is a Modulith?

A Modulith is a monolithic application that is internally structured as a collection of well-defined, loosely-coupled modules. It combines the deployment simplicity of a monolith with the architectural clarity of microservices.

Features

  • Module Generation: Quickly scaffold new application modules with proper structure
  • Interface Registry: Define clear boundaries between modules via the interface registry
  • Import Control: Enforce architectural boundaries using import linting
  • Django Integration: Seamlessly works with Django's existing patterns

Installation

Add to your Django project's INSTALLED_APPS:

INSTALLED_APPS = [
    # ...
    'django_modulith',
    # ...
]

Quick Start

  1. Create a new module This will:

Create a new module directory with proper structure Update the importlinter configuration to include the new module

  1. Define module interfaces

  2. Use module interfaces

Architecture Enforcement

The library helps enforce module boundaries through import linting:

# Check for import rule violations
python -m importlinter

# Generate visualization of module dependencies
python -m importlinter.visualization

Interface Registry

The InterfaceRegistry serves as the core of the inter-module communication:

  • Functions registered with the @interface decorator become available via the registry
  • Type annotations are preserved for IDE autocomplete support
  • The registry pattern discourages direct imports between modules

Best Practices

  1. Keep modules focused: Each module should have a single responsibility
  2. Use interfaces: Access other modules through the interface registry, not direct imports
  3. Honor boundaries: Structure code to respect the architectural boundaries
  4. Document interfaces: Well-documented interfaces make the module boundaries clear

Configuration

Import Linter Configuration The .importlinter file controls module boundaries:

[importlinter]
root_package = modules
include_external_packages = n

[importlinter:contract:modulith_modules]
name = Domain modules are independent
type = independence
modules = 
    users
    products
    orders

Advanced Usage

Type Hints

A stub file (interface_registry.pyi) is automatically generated to provide proper type hints for registered interfaces.

Contributing

Contributions are welcome! Please check the contribution guidelines for more details.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for django-modulith 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for django-modulith 0.1.1
File Interpreter ABI Platform
django_modulith-0.1.1-py3-none-any.whl Python 3 none any Details

Release files / django_modulith-0.1.1-py3-none-any.whl

Download URL django_modulith-0.1.1-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f594e0822c9f779fbbf6e3104518fe540a1f240cff1a89608b93c6cb1456499
BLAKE2b-256 checksum
How to use checksums
6964590b3c5b73d9c9030ad401d5c54621b9a6ec60bd3dfe24cb626dbc28de51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 18, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page