Add comprehensive project layout best practices#17006
Conversation
Expands the "Organizing your project code" section with practical guidance: - Common project structures (flat, by layer, by service) - When to use each approach - Pulumi-specific tips for config helpers and naming conventions - How to organize application code alongside infrastructure - When to split into separate projects This gives users concrete examples rather than just abstract concepts. Fixes #11766 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Documentation ReviewThis PR significantly expands the "Organizing your project code" section with practical, actionable guidance. The content is well-structured and provides valuable real-world examples. However, there are a few issues to address: Issues Found1. Typographical inconsistency (line 331) The text uses "Typescript" but should be "TypeScript" (capital S) for consistency with the official TypeScript branding and the rest of the documentation. 2. Consider adding a trailing newline verification While I cannot confirm from the diff whether the file ends with a newline (as required by AGENTS.md), please verify that the file ends with a proper trailing newline character. Strengths
Style Compliance✅ Headings follow sentence case (H2+) Overall, this is a strong enhancement that addresses issue #11766 effectively. Once the TypeScript capitalization is corrected, this will be ready to merge. Mention me (@claude) if you'd like me to review any updates or have questions! |
|
Your site preview for commit 22e1c06 is ready! 🎉 http://www-testing-pulumi-docs-origin-pr-17006-22e1c066.s3-website.us-west-2.amazonaws.com. |
cnunciato
left a comment
There was a problem hiding this comment.
A few things we might want to tweak here, but this extra detail definitely helps!
| // Validate config at program start | ||
| if (!["dev", "staging", "prod"].includes(environment)) { | ||
| throw new Error(`Unknown environment: ${environment}`); | ||
| } |
There was a problem hiding this comment.
Is this (hard-coding "allowed" stack names) a common pattern? I haven't seen it much myself — but if it's something we think is a best practice, or that we see in the wild, I'd be okay with it. Otherwise, might suggest we nix, or replace with something more common (reading another file, from ENV, from an async service, etc.).
This particular example would also benefit slightly from a usage example. (It'd be simple, but complete the picture a bit better.) Happy to add one if you like!
There was a problem hiding this comment.
@jkodroff is this something we ever see in the wild?
There was a problem hiding this comment.
This is just not a good practice IMO. The environment name is usually synonymous with the stack name, and to me, by virtue of a stack being initialized, it's valid, not something we need to validate after the fact.
| export function name(resourceName: string): string { | ||
| return `${project}-${stack}-${resourceName}`; | ||
| } | ||
| ``` |
There was a problem hiding this comment.
This one could also benefit from a usage example (again, simple, but would make the usefulness clearer IMO).
There was a problem hiding this comment.
I don't think this is needed at all with latest and greatest autonaming.
…ex.md Co-authored-by: Christian Nunciato <c@nunciato.org>
…ex.md Co-authored-by: Christian Nunciato <c@nunciato.org>
…ex.md Co-authored-by: Christian Nunciato <c@nunciato.org>
…ex.md Co-authored-by: Christian Nunciato <c@nunciato.org>
…ex.md Co-authored-by: Christian Nunciato <c@nunciato.org>
|
Your site preview for commit 98e468e is ready! 🎉 http://www-testing-pulumi-docs-origin-pr-17006-98e468e6.s3-website.us-west-2.amazonaws.com. |
|
Your site preview for commit 328cdbd is ready! 🎉 http://www-testing-pulumi-docs-origin-pr-17006-328cdbd3.s3-website.us-west-2.amazonaws.com. |
|
Your site preview for commit a0073f6 is ready! 🎉 http://www-testing-pulumi-docs-origin-pr-17006-a0073f61.s3-website.us-west-2.amazonaws.com. |
|
Your site preview for commit 322ba21 is ready! 🎉 http://www-testing-pulumi-docs-origin-pr-17006-322ba218.s3-website.us-west-2.amazonaws.com. |
|
Your site preview for commit 7c0f740 is ready! 🎉 http://www-testing-pulumi-docs-origin-pr-17006-7c0f7406.s3-website.us-west-2.amazonaws.com. |
jkodroff
left a comment
There was a problem hiding this comment.
Since this is such foundational guidance, I think we need to go over this with a fine-toothed comb and make sure there's consensus. I'm not quite at the "Request Changes" level since this probably makes things better, but I think we would do better to vet this a little more before shipping.
|
|
||
| #### Organized by resource layer | ||
|
|
||
| For medium-sized projects, organize files by infrastructure layer: |
There was a problem hiding this comment.
I disagree on this. I would keep all resources in the entrypoint file, except for (local) components, which nearly always go in a separate file. If there's a local library or maybe structured config classes, those would also each go in a separate file.
If you have that many resources that you need to split among that many files, you should probably have separate programs, e.g the classic Networking -> K8s Cluster -> Workloads pattern of codebases.
| ├── Pulumi.dev.yaml | ||
| ├── Pulumi.prod.yaml | ||
| ├── index.ts # Main entrypoint | ||
| └── config.ts # Config helpers and constants |
| ├── Pulumi.yaml | ||
| ├── Pulumi.dev.yaml | ||
| ├── Pulumi.prod.yaml | ||
| ├── index.ts # Main entrypoint |
There was a problem hiding this comment.
Without giving an outline of what the entrypoint file contains, this example risks confusing more than it clarifies.
| } | ||
| ``` | ||
|
|
||
| **Application code alongside infrastructure:** If your Pulumi project also contains application code (such as Lambda function code or Docker build contexts), consider organizing it into clearly labeled directories: |
There was a problem hiding this comment.
This example is the most useful yet, but it's specific to a serverless app IMO.
We should also show a containerized version, which for me would do something like:
README.md
Makefile # or whatever - orchestrates building the app code, deploying to a container registry, and then calling Pulumi to deploy
app/
(app code here)
infra/
(Pulumi code here)
Based on review feedback from jkodroff and cnunciato: - Remove environment validation example (conflicts with stack-based environments) - Remove resource naming conventions helper (modern autonaming makes this unnecessary) - Revise file organization guidance to emphasize keeping resources in entrypoint - Add guidance to split into multiple projects if complexity grows - Soften config.ts guidance from prescriptive to optional - Add containerized application example with Makefile pattern - Convert bold headers to proper subheadings for better structure These changes make the guidance more conservative and aligned with current best practices. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
@jkodroff I've addressed your feedback from the review:
The revised guidance is more conservative and aligned with current best practices. A few questions:
|
|
Your site preview for commit 4776f62 is ready! 🎉 http://www-testing-pulumi-docs-origin-pr-17006-4776f627.s3-website.us-west-2.amazonaws.com. |
* Add comprehensive project layout best practices Expands the "Organizing your project code" section with practical guidance: - Common project structures (flat, by layer, by service) - When to use each approach - Pulumi-specific tips for config helpers and naming conventions - How to organize application code alongside infrastructure - When to split into separate projects This gives users concrete examples rather than just abstract concepts. Fixes #11766 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update content/docs/iac/guides/basics/organizing-projects-stacks/_index.md Co-authored-by: Christian Nunciato <c@nunciato.org> * Update content/docs/iac/guides/basics/organizing-projects-stacks/_index.md Co-authored-by: Christian Nunciato <c@nunciato.org> * Update content/docs/iac/guides/basics/organizing-projects-stacks/_index.md Co-authored-by: Christian Nunciato <c@nunciato.org> * Update content/docs/iac/guides/basics/organizing-projects-stacks/_index.md Co-authored-by: Christian Nunciato <c@nunciato.org> * Update content/docs/iac/guides/basics/organizing-projects-stacks/_index.md Co-authored-by: Christian Nunciato <c@nunciato.org> * Address PR feedback on project organization guidance Based on review feedback from jkodroff and cnunciato: - Remove environment validation example (conflicts with stack-based environments) - Remove resource naming conventions helper (modern autonaming makes this unnecessary) - Revise file organization guidance to emphasize keeping resources in entrypoint - Add guidance to split into multiple projects if complexity grows - Soften config.ts guidance from prescriptive to optional - Add containerized application example with Makefile pattern - Convert bold headers to proper subheadings for better structure These changes make the guidance more conservative and aligned with current best practices. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Cam Soper <csoper@pulumi.com> Co-authored-by: Christian Nunciato <c@nunciato.org> Co-authored-by: Cam <cam.soper@outlook.com>
Expands the "Organizing your project code" section with practical guidance:
This gives users concrete examples rather than just abstract concepts.
Fixes #11766