How jdiazromeral/django-ddd works
Project Type and Purpose
• This is an open-source tool/library that plugs into Django.
• It provides a management command (start_clean_app) and an app‐config helper (CleanAppConfig) to scaffold and configure Django apps in a Domain-Driven Design (DDD) style.
File Structure
• Top-level “django_ddd/” package contains:
• _app_template/ – a directory of template files (application/, domain/, infrastructure/) used by the generator.
• apps_config/ – logic to customize Django’s app registry (CleanAppConfig).
• management/commands/start_clean_app.py – the CLI entry point.
• A dummy_app/ folder and tests/ exist for validation.
• Support files: setup.py, Pipfile, Dockerfile, GitHub Actions workflows.
a. Developer CLI Layer
• manage.py invokes Django’s management framework.
• start_clean_app command is registered under django_ddd.management.commands.
b. Generator Core
• The command loads template files from django_ddd/_app_template.
• It renders and writes out a new app folder with subdirectories: application/, domain/, infrastructure/.
c. App‐Config Integration
• CleanAppConfig (in apps_config/clean_app_config.py) extends Django’s AppConfig.
• It adjusts models, migrations, admin module lookups using user-provided settings (CUSTOM_MODELS_MODULE, etc.).
d. Generated App Structure
• New apps are wired into Django by adding "app_name.infrastructure.apps.AppNameConfig" to INSTALLED_APPS.
• At runtime, Django uses CleanAppConfig to locate infrastructure.models, infrastructure.migrations, infrastructure.admin.
e. Test & CI Pipeline
• Unit tests in tests/ exercise both the command and config.
• Dockerfile + GitHub Actions handle build, test, and publish flows.
Relationships and Interactions
• Developer → CLI: shell → python manage.py start_clean_app →
→ Generator Core (loads templates) → writes → File System (new app).
• Runtime: Django AppRegistry loads CleanAppConfig →
→ redirects model/admin/migration imports to infrastructure submodules →
→ Django ORM & admin use those.
• CI/CD: pushes to GitHub → triggers workflows (django.yml, pythonpublish.yml) →
→ builds Docker image → runs tests → publishes package.
Architectural Patterns & Design Principles
• Template Method: file scaffolding uses a static directory of templates.
• Extension Point: CleanAppConfig dynamically alters Django’s discovery of app modules.
• Separation of Concerns:
• _app_template (pure templates)
• management.commands (CLI logic)
• apps_config (Django integration)
• tests (quality assurance)
• Domain-Driven Structure: every generated app has distinct domain/, application/, and infrastructure/.