Skip to main content

DDD Structure Generator for Python Projects

Project description

DDDify

A code generator for Domain-Driven Design (DDD) project structures in Python with Clean Architecture principles.

Installation

Install globally using uv:

uv tool install dddify

Or install from source:

git clone https://github.com/yourusername/dddify.git
cd dddify
pip install -e .

Quick Start

Generate a new domain structure:

dddify generate "Order Management" "Order"

Short form:

dddify g "Order Management" "Order"

For help:

dddify --help

Configuration

Create a dddify.toml file in your project root:

[dddify]
output_dir = "backend/domains"

Or add to your pyproject.toml:

[tool.dddify]
output_dir = "backend/domains"

Configuration Options

  • output_dir: Target directory for generated domains (default: ".")

Usage

Basic Command

dddify generate <domain_name> [entity_name] [options]

Arguments:

  • domain_name: Name of the domain (e.g., "Order Management")
  • entity_name: Name of the entity (optional, defaults to domain name)

Options:

  • -o, --output: Output directory (overrides config file)

Examples

Generate with default config:

dddify g "User Management" "User"

Generate with custom output directory:

dddify g "Product Catalog" "Product" -o ./src/domains

Generated Structure

DDDify generates a complete DDD structure following Clean Architecture:

order_management/
├── domain/
│   ├── aggregate.py          # Aggregate root with domain events
│   ├── events.py              # Domain event base class
│   ├── value_objects.py       # Value object definitions
│   ├── exceptions.py          # Domain-specific exceptions
│   ├── repo.py                # Repository interface (ABC)
│   ├── ports.py               # External system interfaces
│   ├── __init__.py            # Domain exports
│   └── entities/
│       └── __init__.py
├── application/
│   ├── commands/
│   │   └── __init__.py
│   ├── queries/
│   │   └── __init__.py
│   └── __init__.py
├── infrastructure/
│   ├── persistence/
│   │   ├── orm.py             # SQLAlchemy ORM model
│   │   ├── repository.py      # Repository implementation
│   │   └── __init__.py
│   ├── adapters/
│   │   └── __init__.py
│   └── di/
│       ├── container.py       # Dishka DI container
│       └── __init__.py
└── presentation/
    ├── router.py              # FastAPI router
    ├── schemas.py             # Pydantic schemas
    ├── exception_handlers.py  # FastAPI exception handlers
    └── __init__.py

Features

  • Clean Architecture: Strict separation of concerns across layers
  • Domain-Driven Design: Aggregates, entities, value objects, domain events
  • Async-First: AsyncSession for SQLAlchemy, async repository pattern
  • Modern Python: Type hints, | union syntax, UUID primary keys
  • Dependency Injection: Dishka container with REQUEST scope
  • FastAPI Ready: Router, schemas, and exception handlers included
  • Absolute Imports: Automatically calculated based on output directory

Architecture Layers

Domain Layer

  • Aggregate: Entity with identity, domain events, and business logic
  • Events: Immutable domain events for event sourcing
  • Repository Interface: Abstract contract for data access
  • Exceptions: Domain-specific error hierarchy
  • Ports: Interfaces for external systems

Application Layer

  • Commands: Write operations (CQRS pattern)
  • Queries: Read operations (CQRS pattern)

Infrastructure Layer

  • Persistence: SQLAlchemy ORM models and repository implementation
  • Adapters: External service adapters
  • DI Container: Dishka provider for dependency injection

Presentation Layer

  • Router: FastAPI endpoints with UUID parameters
  • Schemas: Pydantic models for request/response
  • Exception Handlers: HTTP exception mapping

Technology Stack

  • FastAPI: Web framework
  • SQLAlchemy: ORM with async support
  • Pydantic: Data validation
  • Dishka: Dependency injection
  • UUID: Unique identifiers
  • Python 3.11+: Modern type hints

License

MIT

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

dddify-0.1.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

dddify-0.1.1-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file dddify-0.1.1.tar.gz.

File metadata

  • Download URL: dddify-0.1.1.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for dddify-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8a3b18e35d9899a8b19343e81dbbb208eca33bae0c7e0fa3c8f6e96ed25663ab
MD5 1a6796755f9195685bd0bb7ca38aea06
BLAKE2b-256 c9c68134660b31365d675fba9f1501ff0d1ef3b1bde83d12190d4024546abb8f

See more details on using hashes here.

File details

Details for the file dddify-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: dddify-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for dddify-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 87774d5c8f5a75c921574c35108630e477313d986bfb0021fdea3fff89038f96
MD5 c985428c1f38f6273de97c63777e9157
BLAKE2b-256 10bd57366d6817da2e384fe07273f02be3ee0b8c7872cc727951ade3719612be

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