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
- Create a new module This will:
Create a new module directory with proper structure Update the importlinter configuration to include the new module
-
Define module interfaces
-
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
@interfacedecorator become available via the registry - Type annotations are preserved for IDE autocomplete support
- The registry pattern discourages direct imports between modules
Best Practices
- Keep modules focused: Each module should have a single responsibility
- Use interfaces: Access other modules through the interface registry, not direct imports
- Honor boundaries: Structure code to respect the architectural boundaries
- 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)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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