Skip to main content

No project description provided

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_modulith-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file django_modulith-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_modulith-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de4210cb2514700e631addf8e9bb8225b41636bd502d0fab667f2a10eaf33a98
MD5 f17545f46ddc05aaa9080d3250934a50
BLAKE2b-256 9c8e337c15b0f0b33f3d7061439052e16f81a4ab67002cabf42340eac672d5b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_modulith-0.1.0-py3-none-any.whl:

Publisher: python-package.yml on patzomir/django-modulith

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page