Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

The project lacked clear guidelines on DDD layer placement, leading to architectural violations like the config module being placed in domain when it belonged in application (#75). Contributors needed explicit rules to distinguish between domain entities, DTOs, and infrastructure concerns.

Changes

Documentation Added

  • docs/contributing/ddd-layer-placement.md - Comprehensive guide with:

    • Layer specifications for Domain, Application, Infrastructure (adapters/ + infrastructure/), and Presentation
    • Decision flowchart mapping code characteristics to correct layer
    • Generic, illustrative patterns demonstrating common architectural concepts (value objects, command handlers, adapters for external tools, CLI definitions)
    • Common mistakes section showing wrong placements with corrections
  • Critical nuance on serde usage - Distinguishes acceptable from problematic patterns:

// ✅ Domain entity with serde for persistence (acceptable pragmatic trade-off)
#[derive(Serialize, Deserialize)]
pub struct EnvironmentName(String);

// ❌ DTO in domain layer (wrong - belongs in application)
#[derive(Serialize, Deserialize)]
pub struct ConfigDto {
    pub name: String,  // Raw primitive, no domain validation
}

Documentation Updated

  • docs/contributing/README.md - Expanded quick reference table with all contributing guides, DDD placement listed first
  • .github/copilot-instructions.md - Added layer placement as Essential Rule Roadmap #1

Examples Approach

The guide uses generic, illustrative code patterns rather than specific codebase examples. This makes the documentation more maintainable (no updates needed when actual code changes) while still effectively demonstrating the architectural principles and common patterns like command handlers, repository implementations, and external tool adapters.

Resolves

Closes #79
Related to #75 (the violation that exposed this gap)

Original prompt

This section details on the original issue you should resolve

<issue_title>Add DDD Layer Placement Guide to Contributing Documentation</issue_title>
<issue_description># Add DDD Layer Placement Guide to Contributing Documentation

📋 Issue Information

🎯 Problem Statement

The project lacks clear guidelines on which code belongs in which DDD layer (Domain, Application, Infrastructure, Presentation). This has led to violations like the config module (#75) being placed in the domain layer when it clearly belongs in the application layer.

Without explicit documentation, contributors (including AI assistants) may:

  • Place DTOs in the domain layer
  • Mix infrastructure concerns (file I/O, HTTP) with domain logic
  • Create unclear boundaries between layers
  • Make code harder to maintain and test

💡 Proposed Solution

Create a comprehensive guide docs/contributing/ddd-layer-placement.md that clearly documents each layer's purpose, rules, red flags, examples, and includes a decision flowchart.

📝 Implementation Plan

See detailed specification: docs/issues/add-ddd-layer-placement-guide.md

✅ Acceptance Criteria

Note for Contributors: These criteria define what the PR reviewer will check. Use this as your pre-review checklist before submitting the PR to minimize back-and-forth iterations.

  • Document created at docs/contributing/ddd-layer-placement.md
  • All four layers documented with clear rules and examples
  • Nuanced guidance on serde usage included (entities vs DTOs)
  • Decision flowchart included for quick reference
  • Real code examples from the codebase
  • Linked from docs/contributing/README.md
  • Referenced in .github/copilot-instructions.md
  • All linters pass (markdownlint, cspell)
  • Document follows project markdown conventions

🏷️ Labels

documentation, enhancement, DDD, contributing-guide</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add DDD layer placement guide to contributing documentation Add DDD Layer Placement Guide to Contributing Documentation Oct 30, 2025
Copilot AI requested a review from josecelano October 30, 2025 16:59
Copilot finished work on behalf of josecelano October 30, 2025 16:59
@josecelano josecelano marked this pull request as ready for review October 30, 2025 17:02
@josecelano
Copy link
Member

@copilot, some pieces of code do not exist. for example:

pub struct DestroyCommandPresenter {
    handler: Arc<DestroyCommandHandler>,
}

Anyway, using real examples from the code would be hard to maintain becuase we have to update them when we change the code. It's better to use common examples/patterns, such as command handlers and adapters for system tools.

Copy link
Contributor Author

Copilot AI commented Oct 30, 2025

@copilot, some pieces of code do not exist. for example:

Updated the guide to use generic, illustrative patterns instead of specific code examples. This makes the documentation more maintainable since it won't need updates when the actual code changes.

Changes in commit 585027d:

  • Replaced all "Examples from the Codebase" sections with "Examples and Patterns"
  • Created generic patterns demonstrating:
    • Value objects with validation
    • Domain entities with business logic
    • Repository traits and implementations
    • Command handlers
    • DTOs with domain conversion
    • External tool adapters
    • CLI definitions and dispatchers
  • Added note at top of guide explaining examples are illustrative patterns
  • Kept same principles and guidance, just made examples generic

All patterns demonstrate the same concepts (command handlers, adapters for system tools, etc.) without claiming to be exact code from the repository.

Copilot finished work on behalf of josecelano October 30, 2025 17:21
Copy link
Member

@josecelano josecelano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 585027d

@josecelano josecelano merged commit 0911cfd into main Oct 30, 2025
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add DDD Layer Placement Guide to Contributing Documentation

2 participants