Skip to main content

CLI tool for generating DDD architecture in Python projects

Project description

PyConstructor ๐Ÿ—๏ธ

Python Version License

PyConstructor is a command-line tool that helps developers quickly create a project structure following Domain-Driven Design (DDD) principles. The tool generates architecture based on a YAML configuration that defines bounded contexts, entities, repositories, services, use cases, and other DDD elements.

๐Ÿš€ Quick Start

Installation

# Install via pip
pip install pyconstructor
# Install via uv
uv add pyconstructor

# Generate YAML file with example data
pyc init

# Edit the generated ddd-config.yaml file
# ...

# Generate structure
pyc run

Basic Usage

  1. Initialize a new project with a preset configuration:
pyc init --preset <PresetType(Optional argument, default to Standard)>
  1. Validate your configuration (Optional command):
pyc validate
  1. Preview the project structure (Optional command):
pyc preview --file <file_name> (Optional argument)
  1. Generate the project:
pyc run --file <file_name> (Optional argument)

๐Ÿ“‹ Available Commands

Core Commands

Command Description Example
init Initialize a new project with a preset configuration pyc init --preset standard
validate Validate your YAML configuration pyc validate --file custom-config.yaml
preview Preview the project structure without generating files pyc preview --file custom-config.yaml
run Generate the project structure pyc run --file custom-config.yaml

Command Options

init Command

# Create project with standard preset
pyc init --preset standard

# Force overwrite existing config
pyc init --preset standard --force

validate Command

# Validate default config (ddd-config.yaml)
pyc validate

# Validate specific config file
pyc validate --file custom-config.yaml

preview Command

# Preview default config
pyc preview

# Preview specific config
pyc preview --file custom-config.yaml

Output:

  • Displays the project structure tree in the console
  • Generates a structure.md file with the same tree view for future reference

Example output:

app/
โ”œโ”€โ”€ domain/
โ”‚   โ”œโ”€โ”€ user/
โ”‚   โ”‚   โ”œโ”€โ”€ entities/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ user.py
โ”‚   โ”‚   โ””โ”€โ”€ value_objects/
โ”‚   โ”‚       โ””โ”€โ”€ email.py
โ”‚   โ””โ”€โ”€ catalog/
โ”‚       โ””โ”€โ”€ entities/
โ”‚           โ””โ”€โ”€ product.py
โ”œโ”€โ”€ application/
โ”‚   โ””โ”€โ”€ user/
โ”‚       โ””โ”€โ”€ use_cases/
โ”‚           โ””โ”€โ”€ register_user.py
โ””โ”€โ”€ infrastructure/
    โ””โ”€โ”€ repositories/
        โ””โ”€โ”€ user_repository.py

run Command

# Generate from default config
pyc run

# Generate from specific config
pyc run --file custom-config.yaml

Architecture Presets

PyConstructor comes with three built-in presets:

Simple Preset

Basic DDD structure without bounded contexts:

pyc init --preset simple

Standard Preset

Default preset with bounded contexts:

pybuilder init --preset standard

Advanced Preset

Complex structure with nested contexts:

pyc init --preset advanced

Configuration

The tool uses YAML configuration files to define your project structure. Example configurations are provided in the src/templates/config_templates directory.

Simple Configuration Example

settings:
  preset: "simple"

layers:
  domain:
    entities: User, Product
    value_objects: Email, Price

Standard Configuration Example

settings:
  preset: "standard"

layers:
  domain:
    contexts:
      - name: user
        entities: [User, Profile]
        value_objects: [Email, Password]
      - name: catalog
        entities: [Product, Category]

Advanced Configuration Example (for microservice architecture)

settings:
  preset: "advanced"

layers:
  contexts:
    - name: user_context
      domain:
        entities: User
        value_objects: Email
      application:
        use_cases: CreateUser
      infrastructure:
        repositories: UserRepository

    - name: payment_context
      domain:
        entities: Payment
      application:
        use_cases: ProcessPayment
      infrastructure:
        repositories: TransactionRepository

๐Ÿค Contributing

Contributions are welcome. Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git switch -c feature/amazing-feature)
  3. Run tests (pytest)
  4. Commit your changes (git commit -m 'Add amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT Licenseโ€”see the LICENSE file for details.

๐Ÿ‘ค Author

Grigoriy Sokolov (Sokolov_Gr@proton.me)

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

pyconstructor-0.2.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

pyconstructor-0.2.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file pyconstructor-0.2.0.tar.gz.

File metadata

  • Download URL: pyconstructor-0.2.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.5

File hashes

Hashes for pyconstructor-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fc1ad2b4599c148bd93ed804268411f94d866fe700a9a9daba94456bd68df891
MD5 60ca399169f212db454319d1127595f7
BLAKE2b-256 66ec32756145098b24b546325602411cedeafc628f4be8000832fecab4970658

See more details on using hashes here.

File details

Details for the file pyconstructor-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pyconstructor-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e5ee81f089c56ce170c07b2110b32aa620700eaa68947524d2407f6e59041880
MD5 17374ba89d02dbe1fcd326b93f599d9a
BLAKE2b-256 a28ea185b5d6760d6e5719047b55bf74f31150782b9436e826c7866fcf25a164

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