How alma-cdk/project works
1. This repository is a TypeScript CDK library, not an application. Its main public boundary is the @alma-cdk/project package exported from src/index.ts, with the core runtime centered on AWS CDK constructs and helpers for multi-account, multi-environment deployments.
2. The root orchestration object is Project (src/project/project.ts). It replaces a plain cdk.App and carries project-wide metadata such as project name, author/contact info, default region, and the account strategy. Everything else hangs off this scope.
3. Account and environment configuration are first-class subsystems under src/configurations and src/context. These modules normalize declared account/environment definitions, resolve the selected account and environment from CDK context, and expose typed accessors so stacks can query configuration consistently instead of reading ad hoc files.
4. Runtime selection is driven by CDK context values, especially account and environment passed at deploy time. The README shows the intended flow: cdk deploy -c account=dev -c environment=feature/abc-123. Those values are interpreted by the context modules and then used to bind the project to the correct AWS account, region, and environment behavior.
5. AccountWrapper and EnvironmentWrapper (src/wrapper) are the structural boundaries for instantiating account-scoped and environment-scoped constructs beneath the Project. They provide the composition layer where one project can contain multiple environments and each environment can target one of several accounts.
6. SmartStack (src/smartstack) is the main stack abstraction. It wraps AWS CDK Stack behavior with project conventions: stable vs ephemeral environment handling, termination protection, tag application, and name generation. This is the construct most application stacks are expected to extend.
7. The naming system is a separate subsystem under src/name. It provides multiple name formats (Name, UrlName, PathName) plus trimming and max-length logic. This matters because the library is responsible for producing safe AWS resource identifiers across different resource types and account/environment combinations.
8. Tagging is centralized under src/smartstack/tags with supporting feature checks. The stack/tag layer computes standard tags such as Account, Environment, Project, Author, Organization, and Contact, and it also contains exclusion/check logic so tags can be applied or suppressed based on resource type and compatibility rules.
9. Feature-flag compatibility is isolated in src/feature-flags. The presence of both legacyTags and v0Tags indicates the library supports migration behavior between major versions, letting the same codebase adapt tag semantics and conventions while preserving backward compatibility for older projects.
10. The remaining folders support the public API: src/error adds structured metadata to errors, src/project contains account/environment type resolution and region logic, src/template and src/utils hold reusable helpers, and src/__test__ plus test/integration.test.ts verify the construct behavior end-to-end. Build/release is managed with Projen and GitHub Actions, but the runtime architecture is still primarily a compositional CDK library around Project -> Wrappers -> SmartStack -> resources.
Main entry points: project.ts Project · src/index.ts Package API · stack.ts SmartStack · tags/index.ts Stack Tags
Components 21
Public API
Package entrypoints exported from src/index.ts and module barrels
- Package API · Top-level library exports for @alma-cdk/project
src/index.ts
Project Runtime
Project orchestration, account/environment modeling, and deployment scope
- Project API · Project-related exports
src/project/index.ts - Project · Root CDK scope carrying project metadata and account strategy
src/project/project.ts - Project Context · Typed project-wide context and metadata resolution
src/project/project-context.ts - Account Type · Account classification and strategy helpers
src/project/account-type.ts - Env Type · Environment classification and stability helpers
src/project/environment-type.ts - Region Resolve · Default region selection and resolution rules
src/project/resolve-region.ts - Context API · Context resolution exports
src/context/index.ts - Account Context · Resolves selected account from CDK context
src/context/account.ts - Env Context · Resolves selected environment from CDK context
src/context/environment.ts - Account Wrapper · Account-scoped composition boundary beneath Project
src/wrapper/account.ts - Env Wrapper · Environment-scoped composition boundary beneath AccountWrapper
src/wrapper/environment.ts
Stack Conventions
Smart stack abstractions, naming, tagging, and termination behavior
- SmartStack · CDK Stack wrapper with project conventions
src/smartstack/stack.ts - Stack Names · Stack-specific naming conventions
src/smartstack/name/index.ts - Stack Tags · Standard tags, exclusions, and compatibility checks
src/smartstack/tags/index.ts - Termination · Termination protection behavior for stacks
src/smartstack/termination/index.ts - Name System · Name, URL, and path formatting with length trimming
src/name/index.ts - Feature Flags · Legacy and v0 tag compatibility switches
src/feature-flags/index.ts
Support Modules
Shared helpers, error metadata, and template utilities
- Error Metadata · Structured error augmentation utilities
src/error/add.ts - Template Utils · Reusable template-related helpers
src/template/index.ts - Shared Utils · General-purpose lookup and access helpers
src/utils/find.ts
Connections 29
- Package API → Project API: exports · Package entrypoint re-exports project API
- Package API → Context API: exports · Package entrypoint re-exports context API
- Package API → SmartStack: exports · Package entrypoint exposes stack abstraction
- Package API → Name System: exports · Package entrypoint exposes naming helpers
- Package API → Feature Flags: exports · Package entrypoint exposes compatibility flags
- Package API → Error Metadata: exports · Package entrypoint exposes error helpers
- Project API → Project: builds · Project API centers on the root orchestration object
- Project API → Project Context: types · Project API exports project-wide context types
- Project → Project Context: stores · Project carries normalized project metadata
- Project → Account Type: uses · Project binds account strategy
- Project → Env Type: uses · Project binds environment behavior
- Project → Region Resolve: resolves · Project determines default region
- Context API → Account Context: exports · Context barrel exposes account resolution
- Context API → Env Context: exports · Context barrel exposes environment resolution
- Account Context → Env Context: coordinates · Account and environment selection are interpreted together from CDK context
- Account Context → Account Wrapper: binds · Resolved account becomes the account scope boundary
- Env Context → Env Wrapper: binds · Resolved environment becomes the environment scope boundary
- Project → Account Wrapper: contains · Project is the parent scope for accounts
- Account Wrapper → Env Wrapper: contains · Account scope contains one or more environments
- Env Wrapper → SmartStack: hosts · Environment scope hosts application stacks
- SmartStack → Stack Names: applies · Stacks use naming conventions for safe identifiers
- SmartStack → Stack Tags: applies · Stacks apply standard tags through centralized tagging
- SmartStack → Termination: guards · Stacks can enable termination protection rules
- Stack Names → Name System: formats · Stack names are derived from the shared naming system
- Stack Tags → Feature Flags: checks · Tag behavior depends on compatibility feature flags
- Stack Tags → Shared Utils: uses · Tag selection and exclusion logic uses shared utilities
- SmartStack → Template Utils: uses · Stack implementation relies on template helpers
- Project → Error Metadata: annotates · Project errors carry structured metadata
- Feature Flags → Stack Tags: controls · Legacy and v0 modes alter tag semantics