Skip to content

docs: added guidelines for facades and traits#37860

Merged
mergify[bot] merged 3 commits into
mainfrom
facades-guidlines
May 21, 2026
Merged

docs: added guidelines for facades and traits#37860
mergify[bot] merged 3 commits into
mainfrom
facades-guidlines

Conversation

@kumsmrit
Copy link
Copy Markdown
Contributor

Issue # (if applicable)

Closes #.

Reason for this change

The existing design/mixins-facades-traits.md describes the architectural relationship between Facades, Traits, and Mixins, and docs/DESIGN_GUIDELINES.md covers when to use each building block. However, Facades and Traits lack a dedicated implementation guideline.
A new docs/FACADES_AND_TRAITS_DESIGN_GUIDELINES.md provides implementation guidance for Facades and Traits, covering the structural pattern (factory method, private constructor, public methods), naming conventions, project structures, how to use Facades and Traits in construct interfaces, and testing requirements.

Description of changes

  • Created docs/FACADES_AND_TRAITS_DESIGN_GUIDELINES.md - dedicated design guideline for Facades and Traits, covering their key characteristics
  • Updated other design to reference this new doc for Facades-and-Traits guidelines.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions Bot added the p2 label May 13, 2026
@mergify mergify Bot added the contribution/core This is a PR that came from AWS. label May 13, 2026
@mergify mergify Bot temporarily deployed to automation May 13, 2026 11:42 Inactive
@mergify mergify Bot temporarily deployed to automation May 13, 2026 11:42 Inactive
@github-actions
Copy link
Copy Markdown
Contributor

👋 It looks like your PR description follows the template but is missing a valid issue number in the first section.

PRs without a linked issue will receive lower priority for review and merging. Please update the description to include a reference like Closes #123. If no existing issue matches your change, create one first.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label May 13, 2026
@kumsmrit kumsmrit requested a review from alvazjor May 13, 2026 13:58
Copy link
Copy Markdown
Contributor

@kumvprat kumvprat left a comment

Choose a reason for hiding this comment

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

Added a few inline comments

Overall the new guidelines do clear a lot about facades and traits, as well how they work with each other.

? Grant.addToPrincipalOrResource({ /* ... */ resource: this.policyResource })
: Grant.addToPrincipal({ /* ... */ });

this.encryptedResource?.grantOnKey(grantee, 'kms:Decrypt');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Based on my understanding, a facade uses a trait directly to manipulate the external consumers like done here with the IEncryptedResource trait which grants permission to the grantee to use the kms key for decryption

Any reason we don't do the same for the policyResource variable here which is again a type of trait IResourceWithPolicyV2?
Maybe this is just an example but do we want to promote using only traits inside a facade or is that just a loose guidance

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Both policyResource and encryptedResource are traits consumed by the Facade - the difference is in what each trait's contract provides:

  • IResourceWithPolicyV2 has addToResourcePolicy() which accepts a statement — it's passed into Grant.addToPrincipalOrResource because the Grant framework needs to decide whether to use the
    principal's policy or the resource's policy. Calling it directly would bypass that decision.
  • IEncryptedResource provides single self-contained grantOnKey() - it finds the KMS key and grants on it. No decision logic needed, so the Facade calls it directly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Got it

So the facade author would need enough context to make this decision which given the fact that facades are per resource/service is a reasonable assumption.(Author should know enough about the service and it's dependent services to make decisions when designing a facade)

Comment thread docs/FACADES_AND_TRAITS_DESIGN_GUIDELINES.md Outdated
Comment thread docs/FACADES_AND_TRAITS_DESIGN_GUIDELINES.md Outdated
Comment thread docs/FACADES_AND_TRAITS_DESIGN_GUIDELINES.md
`DefaultEncryptedResourceFactories` / `EncryptedResources` (encryption).

To register a Trait for a CloudFormation resource type, implement the factory
and register it in `lib/private/default-traits.ts`:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When adding new traits do we just implement the factory here or the trait itself ?

If trait is not implemented here what is the correct location for a trait for any given module/L1 resource?

Copy link
Copy Markdown
Contributor Author

@kumsmrit kumsmrit May 20, 2026

Choose a reason for hiding this comment

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

Currently both trait interfaces (IResourceWithPolicyV2, IEncryptedResource) live in aws-iam/lib/grant.ts because they are both IAM-related.
The general principle would be: the trait interface and registry live in the module most closely associated with the capability (e.g., an IAM-related trait → aws-iam)

The per-service factory implementations goes in lib/private/default-traits.ts of the service module.

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 21, 2026

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 21, 2026

Merge Queue Status

  • Entered queue2026-05-21 10:48 UTC · Rule: default-squash
  • Checks passed · in-place
  • Merged2026-05-21 11:34 UTC · at cbfc5260a0fdb94df192504f911101053a7e0bfc · squash

This pull request spent 46 minutes 28 seconds in the queue, including 45 minutes 55 seconds running CI.

Required conditions to merge

@mergify mergify Bot temporarily deployed to automation May 21, 2026 10:48 Inactive
@mergify mergify Bot temporarily deployed to automation May 21, 2026 10:48 Inactive
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 21, 2026

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify Bot merged commit 5e6f60d into main May 21, 2026
20 of 21 checks passed
@mergify mergify Bot deleted the facades-guidlines branch May 21, 2026 11:34
@github-actions
Copy link
Copy Markdown
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 21, 2026
@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label May 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

contribution/core This is a PR that came from AWS. p2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants