Skip to main content

Architecture Guard & Linter & Scanner 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.

๐Ÿ“ก 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)
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ 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/ or triggering app/ logic.
    • 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 Stack

The project is built with modern Python tooling and development practices:

  • Typer + Rich + InquirerPy best smooth CLI experience.
  • Dishka lightweight Dependency Injection for clean and decoupled architecture.

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-1.1.1.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

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

dddguard-1.1.1-py3-none-any.whl (149.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dddguard-1.1.1.tar.gz
Algorithm Hash digest
SHA256 93be6d40060cbb4be773c0d3ce2b97e1d86a222f281410a60739be72bc47f284
MD5 91556d5ae2406d360cfeeb02d2e25c29
BLAKE2b-256 582b4e08d3f1ebefdc25b174fbac1c0e304a236877cb3b71cb8d51d29a5ff6d9

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for dddguard-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6952d53fc6ea3764f8838700596677e4cec9b5ac1999e55d61e601397a39824e
MD5 0ff10d8d440393c6195b542374c307f1
BLAKE2b-256 a424a84ad9c00785688f6fb9817bae98e990a2b3ad2e8c1a70b18ef75faa6a5f

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