Skip to main content

Bounded Contexts Linter

A static code analyzer that checks the isolation of bounded contexts in Domain-Driven Design (DDD) projects. This linter ensures that dependencies between modules occur only within a single bounded context, helping to maintain proper isolation between different domains in your application.

Overview

In Domain-Driven Design, bounded contexts are a central pattern that helps in dealing with large models by dividing them into different contexts with explicit boundaries. This linter helps enforce these boundaries by:

  1. Checking that modules don't belong to multiple bounded contexts
  2. Verifying that imports between modules respect bounded context isolation

The linter recognizes two special contexts by default:

  • sharedkernel: Contains modules that can be imported by any context
  • sharedscope: Contains interfaces for interaction between contexts that can be safely imported

See the details of the work on the examples below.

Installation

Requirements

  • Python 3.11 or higher

Install from PyPI

pip install bounded-contexts-linter

Install with flake8 integration

pip install bounded-contexts-linter[flake8]

Usage

Command Line Interface

Run the linter on your project:

bc-linter /path/to/your/project [/path/to/bounded-contexts.toml]
bounded-contexts-linter /path/to/your/project [/path/to/bounded-contexts.toml]

If the configuration file path is not provided, the linter will look for bounded-contexts.toml in the current working directory.

Flake8 Integration

If you've installed the linter with flake8 integration, you can use it as a flake8 plugin:

flake8 /path/to/your/project

Make sure to configure flake8 to use the plugin by adding the following to your .flake8 file:

[flake8]
enable-extensions = BC

Configuration

The linter uses a TOML configuration file to define bounded contexts and their module patterns. By default, it looks for bounded-contexts.toml in the current working directory.

Example Configuration

[bounded-contexts]
names = ["sharedkernel", "sharedscope", "sales", "crm", "user"]

[bounded-contexts.sharedkernel]
description = "Shared kernel modules that can be imported by any context"
contains = [
    "project.domains.user.*",
]

[bounded-contexts.sharedscope]
description = "Interface modules for interaction between contexts"
contains = [
    "project.domains.*.port",
]

[bounded-contexts.crm]
description = "Customer Relationship Management context"
contains = [
    "project.domains.crm.models",
    "project.domains.crm.services",
]

[bounded-contexts.sales]
description = "Sales context"
contains = [
    "project.domains.sales.models",
    "project.domains.sales.services",
]

Pattern Syntax

The contains field in each bounded context section accepts a list of patterns that define which modules belong to that context. The pattern syntax supports:

  • Exact module names: project.domains.crm.models
  • Wildcards: project.domains.crm.*
  • Multiple wildcards: *.crm.*

Examples:

  • project.utils - Matches exactly the module named "project.utils"
  • project.domains.crm.* - Matches all modules under "project.domains.crm"
  • project.domains.*.models - Matches all modules starting with "project.domains." and ending ".models"
  • *.crm.* - Matches all modules containing ".crm."

How It Works

The linter performs the following checks:

  1. Overlapping Modules Check: Ensures that no module belongs to multiple bounded contexts (except for sharedkernel and sharedscope)
  2. Import Isolation Check: Ensures that modules from one bounded context don't import modules from another bounded context (except for sharedkernel and sharedscope)

The linter searches for modules in the specified project directory and checks their imports against the bounded contexts defined in the configuration file.

Metadata

Release files for bounded-contexts-linter 1.0.0

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

Source distribution (sdist)

Source distribution for bounded-contexts-linter 1.0.0
File Size Uploaded Provenance
bounded_contexts_linter-1.0.0.tar.gz 8.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bounded-contexts-linter 1.0.0
File Interpreter ABI Platform
bounded_contexts_linter-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.5 kB

Release files / bounded_contexts_linter-1.0.0.tar.gz

Download URL bounded_contexts_linter-1.0.0.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
cae1d0366134ae0fe60d6d355e9a1648aab88de1d832648b6611e7fcafb49ee2
BLAKE2b-256 checksum
How to use checksums
419d4454036eb43873d7579faf041ad0eb805ee53f81304b03e5a250c0d0c9d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.3

Release files / bounded_contexts_linter-1.0.0-py3-none-any.whl

Download URL bounded_contexts_linter-1.0.0-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0835edf5ed158c26fbd24bccb9224adb80e8b1c3cffa095b06f2b51c204270f
BLAKE2b-256 checksum
How to use checksums
c3fe21ecd5b0bc475880fb0e97e8d8a251cb74f0e75335ee786286ecc0f4f790
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.3

Security for bounded-contexts-linter 1.0.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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