Skip to main content

Architecture Guard & Linter for DDD projects

Project description

PyPI version Python Versions License: MIT

dddguard

Architecture Guard, Linter, and Scaffolder for Domain-Driven Design projects.

Stop arguing about folder structures and layer boundaries. dddguard enforces strict architectural rules, generates compliant boilerplate, and visualizes your project dependency graph.

It is designed to be your interactive architectural companion.

Quick Start

Install globally using uv (requires Python 3.10+):

uv tool install dddguard

Simply run the tool to enter the interactive HUD:

dddguard

The tool will guide you through scanning, linting, or creating new components.

Capabilities ๐Ÿ›ก๏ธ Lint Command: dddguard lint

You can explore detailed architectural rules and naming conventions interactively via diagrams using the 'View Rules (Summary)' and 'View Rules (Matrix)' options within the linter's interface.

๐Ÿ“Š Draw Command: dddguard draw

The visualizer parses your actual code structure and generates an XML file compatible with Draw.io (diagrams.net). It maps relationships between Contexts and Layers based on real imports. When using dddguard drawdir to visualize a specific directory, the generated diagram will include comprehensive information in its legend, providing detailed insights into the visualized architecture.

๐Ÿงฉ Create Command: dddguard create

Scaffold new Bounded Contexts in seconds. Use the interactive wizard to generate production-ready boilerplate with:

  • Correct layers (domain, app, adapters, ports).
  • Dependency Injection containers.

๐Ÿ“ก Scan Command: dddguard scan

The core analysis engine. It builds a dependency graph of your entire project, detecting contexts and layers. Use the interactive filters to explore specific parts of your monolith or modular monolith.

The Standard dddguard enforces a highly structured, granular architecture. This approach maximizes separation of concerns and clearly defines the role of every component, from the global entrypoint down to the individual Bounded Context.

src/
โ”œโ”€โ”€ <context_name>/
โ”‚   โ”œโ”€โ”€ domain/           # Pure Business Logic
โ”‚   โ”‚   โ”œโ”€โ”€ aggregates/   # - Encapsulates business rules and consistency
โ”‚   โ”‚   โ”œโ”€โ”€ entities/     # - Business objects with a distinct identity
โ”‚   โ”‚   โ”œโ”€โ”€ vo/           # - Value Objects, immutable and without identity
โ”‚   โ”‚   โ”œโ”€โ”€ services/     # - Domain-specific operations, not tied to an entity
โ”‚   โ”‚   โ”œโ”€โ”€ events/       # - Represents something that happened in the domain
โ”‚   โ”‚   โ””โ”€โ”€ errors/       # - Custom domain-specific exceptions
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ app/              # Application Layer: Orchestrates domain logic
โ”‚   โ”‚   โ”œโ”€โ”€ use_cases/    # - Implements Commands that change system state
โ”‚   โ”‚   โ”œโ”€โ”€ queries/      # - Implements Queries that read system state
โ”‚   โ”‚   โ”œโ”€โ”€ workflows/    # - Manages long-running processes (Sagas)
โ”‚   โ”‚   โ”œโ”€โ”€ handlers/     # - Reacts to domain or integration events
โ”‚   โ”‚   โ””โ”€โ”€ interfaces/   # - Defines contracts (ports) for driven adapters
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ adapters/         # Translation layer between the core and the outside world
โ”‚   โ”‚   โ”œโ”€โ”€ driving/      # - Adapters that drive the application (e.g., Controllers)
โ”‚   โ”‚   โ””โ”€โ”€ driven/       # - Adapters driven by the application (e.g., Repositories)
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ dto/              # Data Transfer Objects: Simple, logic-less data carriers
โ”‚   โ”‚   โ”œโ”€โ”€ driving/      # - Incoming data structures (Requests)
โ”‚   โ”‚   โ””โ”€โ”€ driven/       # - Outgoing data structures (Responses, Events)
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ ports/            # Technology-specific infrastructure code
โ”‚   โ”‚   โ”œโ”€โ”€ driving/      # - Entry points for incoming signals (web server, CLI app)
โ”‚   โ”‚   โ””โ”€โ”€ driven/       # - Egress points for outgoing signals (DB client, HTTP client)
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ composition.py    # - Wires all dependencies for this specific context
โ”‚
โ”œโ”€โ”€ shared/               # Shared code: kernels, libraries, or models used by multiple contexts
โ”‚
โ””โ”€โ”€ root/                 # Global application entrypoint and composition root
    โ”œโ”€โ”€ composition.py    # - Wires all contexts and shared services together
    โ”œโ”€โ”€ main.py           # - Main application entrypoint (e.g., starts web server)
    โ””โ”€โ”€ cli.py            # - CLI application entrypoint

Anatomy of the Architecture

  1. root/: The top-level entrypoint for your entire application. Its composition.py assembles the different Bounded Contexts and shared/ components.

  2. shared/: A place for code that is shared across multiple contexts, such as a shared kernel, common libraries, or cross-cutting concerns like logging. The structure within shared/ is intentionally flexible.

  3. <context_name>/: Represents a Bounded Context, a self-contained module with its own internal layers:

    • domain/: The heart of the context's business logic. It is completely isolated and pure.
    • app/: Orchestrates the domain logic to perform specific tasks, defining the application's capabilities.
    • adapters/: Translate between the outside world and the application layer, implementing interfaces defined in app/.
    • dto/: Define the data contracts for requests and responses, ensuring clean boundaries.
    • ports/: Contain the raw, technology-specific code that connects to infrastructure.
    • composition.py: The context's local "glue" that wires together its internal components.

Technology Built with modern Python standards:

Typer for the CLI.

Dishka for Dependency Injection.

Rich for beautiful terminal output.

NetworkX for graph analysis.

Maintained by Sense1Tapo4ek

Project details


Download files

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

Source Distribution

dddguard-0.1.0.tar.gz (114.4 kB view details)

Uploaded Source

Built Distribution

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

dddguard-0.1.0-py3-none-any.whl (160.9 kB view details)

Uploaded Python 3

File details

Details for the file dddguard-0.1.0.tar.gz.

File metadata

  • Download URL: dddguard-0.1.0.tar.gz
  • Upload date:
  • Size: 114.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.0

File hashes

Hashes for dddguard-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3cdd1dda0a01c7f20064222a84c05e25bb97ee40326c010748f94d7e56b9c685
MD5 9c16afc0d93712422b294b786e0f87e5
BLAKE2b-256 8ebcd15fe2d1924afe2198081f01ba3098074fd5d0f12cd35c73e7f6a242c211

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dddguard-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 160.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.0

File hashes

Hashes for dddguard-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63cbe990f8d1483e14cee3a0f36f1e080237fb95b1a34f428a31c85f7a7e49d2
MD5 e7b9c8a4fbfca76d50f221074127df68
BLAKE2b-256 eaf4b855c38fc257f4801440ef43d1e29184786e545a6ee06101ae5652695447

See more details on using hashes here.

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