Skip to content

Latest commit

 

History

History
36 lines (27 loc) · 1.48 KB

implementation.md

File metadata and controls

36 lines (27 loc) · 1.48 KB

Implementation Details

Architecture

The factory uses a compiler-like architecture rather than simple string templating. This ensures type safety and enables deep validation.

1. Parser Layer

  • Location: src/generators/{type}/parser.ts
  • Role: Reads raw input (YAML/JSON) and converts it into the ProjectConfig IR.
  • Logic: Heuristics are applied here (e.g., "if port 80 is exposed, set publiclyAccessible: true").

2. Validation Layer

  • Location: src/validators/
  • Role: Enforces rules on the IR.
  • Validators:
    • SecurityValidator: Checks NIST compliance (encryption, access).
    • CostValidator: Estimates monthly spend.
    • ContractValidator: Checks alignment with application requirements.
    • SecretsValidator: Verifies secret existence.

3. Synthesis Layer (Factory)

  • Location: src/core/factory.ts
  • Role: Iterates over the validated IR and delegates to registered Generators.
  • CDK Integration: Creates a cdk.App and cdk.Stack, applying Aspects (like cdk-nag) before purely synthesizing.

4. Template Layer

  • Location: src/templates/
  • Role: Reusable L3 CDK constructs. These are functions that take a specific Resource Config (e.g., FargateServiceConfig) and return a Construct.

Monorepo Structure

The repository uses pnpm workspaces.

  • packages/
    • cdk-factory: The core library and CLI. (Currently the main package).
  • scripts/: Maintenance scripts.