Skip to content

Feature/cdk migration #1102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 66 commits into from
Aug 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
91fd3a4
Increment root package version, move to node 22
tvhees Jun 18, 2025
c4cadcf
Add root CDK application and test-cdk-service
tvhees Jun 18, 2025
654f2c5
Rename cdk folder to application
tvhees Jun 19, 2025
b3f62c9
Add CDK migration notes, version and alias resources, lambda defaults…
tvhees Jun 20, 2025
19a2004
Reduce output from step function tasks with Jsonata
tvhees Jun 20, 2025
2d0955b
small refactor of lambdas and step function
tvhees Jun 23, 2025
8db7ebd
Added an example using JSONata and non-lambda resources in step funct…
tvhees Jun 23, 2025
88e5094
Avoid linting CDK output folder
tvhees Jun 23, 2025
02cc563
Extract constructs to cdk-utils, provide injector for name overrides,…
tvhees Jun 25, 2025
eb52cee
Minor fixes
tvhees Jun 26, 2025
9a96131
Rework vite/eslint config to mjs format and document lib requirements…
tvhees Jun 26, 2025
27e3594
Update CDK utils lib to match new lib standards
tvhees Jun 26, 2025
ead5b3b
Fix issues with nx g remove stumbling on eslint.config.js
tvhees Jun 26, 2025
0798ec7
Move vitest workspace to mjs
tvhees Jun 26, 2025
3fc6db3
Keep vitest.workspace.ts with a comment
tvhees Jun 26, 2025
245ca3d
Add tests and docs to cdk service example
tvhees Jun 26, 2025
84a1b86
Rework context, create custom cdk-nag ruleset, use it to test service…
tvhees Jun 26, 2025
8bf682a
Add typechecks, tests for cdk-utils, and drop coverage requirement fo…
tvhees Jun 26, 2025
1e532e3
Added generator for cdk services
tvhees Jun 27, 2025
5d24e9b
Clean up generators. move all context to application-context, add pla…
tvhees Jun 27, 2025
fb085f9
Update readmes
tvhees Jun 27, 2025
f7edf10
Remove legacy service example
tvhees Jun 27, 2025
f1016d9
Namespace cd-utils and add better readme instructions
tvhees Jun 27, 2025
c61d766
Generator produces a better stack test file
tvhees Jun 27, 2025
e12081e
Further test improvements for generated services
tvhees Jun 27, 2025
02a2464
Guard against Stack or Service in new service names
tvhees Jun 27, 2025
9598585
Minor addition to migration notes
tvhees Jun 27, 2025
0a19ce2
Clean up example cdk service
tvhees Jun 27, 2025
34d4c5d
Don't recommend immutable install, iit fails due to package name change
tvhees Jun 27, 2025
42b3459
Add note about confirming change deployment
tvhees Jun 27, 2025
beae0fb
Change dev deploy command syntax and add destroy command
tvhees Jun 27, 2025
f422aa0
Improve readme docs for initial app management
tvhees Jun 27, 2025
e138e95
Total overhaul adding the latest state of the cdk template
tvhees Jul 10, 2025
c69c948
Fix cdk-service generator issue
tvhees Jul 10, 2025
1be23dc
Add owner tag to the whole application
tvhees Jul 10, 2025
3868fca
Refactor log group properties into a separate file and enhance loggin…
tvhees Jul 17, 2025
d4defe4
Migrate to Nx 2.3.11, update other deps
tvhees Aug 5, 2025
7ad959a
Streamline cdk-service generator template, remove unnecessary extension
tvhees Aug 5, 2025
9fbfb80
Add esm support banner to lambda bundling
tvhees Aug 5, 2025
5c3b575
Clean up nvm use in pre-commit hook, disable Nx terminal ui
tvhees Aug 5, 2025
53ab90b
Migrate to new application structure
tvhees Aug 5, 2025
16eaf66
Add defaults for pg task
tvhees Aug 5, 2025
dea15eb
Gitignore .env.json file
tvhees Aug 5, 2025
35f4786
Add required configuration for pg:parameters in core application
tvhees Aug 5, 2025
3d5f030
Update core application reference for @nx/js/typescript plugin
tvhees Aug 5, 2025
fb99abb
Update generator and add readme notes around adding/removing services
tvhees Aug 5, 2025
7a30317
Add updated bitbucket pipelines config
tvhees Aug 5, 2025
cef0716
Update playground: to pg: in docs
tvhees Aug 6, 2025
a0c56cc
Make `origin/main` the default comparison branch and add a note about…
tvhees Aug 6, 2025
53d35b9
Clean up gitignore, commit CLAUDE.md
tvhees Aug 6, 2025
204a68a
Remove default AWS account/region config from application
tvhees Aug 6, 2025
0b57fc2
Fix missing import of Stage in generator index.ts
tvhees Aug 9, 2025
8e2b492
Chore: Developer QOL adjustments for commit and pg deploys
tvhees Aug 10, 2025
8be2c2e
Test Nx Package should use node 22 and cdk-service
tvhees Aug 11, 2025
f652e7c
Fix CLI argument handling of cdk-service-plugin generator, rename gen…
tvhees Aug 11, 2025
58dc962
Avoid yarn lock error when generating test library
tvhees Aug 11, 2025
1c40ef3
Turn off immutable installs just for package build test
tvhees Aug 11, 2025
43cee54
Use yarn for all package build commands, don't run test task in packa…
tvhees Aug 11, 2025
3cd4033
Overhaul stage setup and cdk-utils to use property injectors and aspe…
tvhees Aug 16, 2025
4c3825e
Update documentation and CLAUDE.md
tvhees Aug 16, 2025
ee8c440
Improve types and documentation for SSM Parameter Group
tvhees Aug 16, 2025
54b644d
Make injector withProps method return a new instance, improve JSDocs
tvhees Aug 16, 2025
8693cf7
Consilidate bucket constructs, rework injectors to use configuration …
tvhees Aug 17, 2025
2a05e44
Update cdk-utils readme and CLAUDE files
tvhees Aug 17, 2025
ff9b8bb
Move to using store-parameters package over a custom script for SSM p…
tvhees Aug 17, 2025
33b4665
Code review changes
tvhees Aug 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions .git-hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,40 @@
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

# This take the current active node version you want to verify the hook
export NVM_DIR="$HOME/.nvm"
a=$(nvm current)

export PATH="$NVM_DIR/versions/node/$a/bin:$PATH"

# Define colours for nicer CLI output
RED="\033[1;31m"
GREEN="\033[1;32m"
NO_COLOUR="\033[0m"

echo -e "${GREEN} Executing git hook $0 $@ ${NO_COLOUR}"
echo -e "${GREEN}Executing git hook $0 $@${NO_COLOUR}"

# Use the current Node version explicitly
nvm use

# Get the list of staged changes
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)

# Exclude files that shouldn't trigger pre-commit checks
# This is done here because `nx affected` doesn't look at task inputs
# when determining if a project is affected
EXCLUDED_FILES_REGEX='.*\.md$' # Ignore markdown files
EXCLUDED_FILES_REGEX+='|.*\/step-functions\/.*\.(yml|yaml)$' # Ignore step function yaml files
EXCLUDED_FILES_REGEX+='|^\/?([^\/]*)$' # Ignore all root-level files
AFFECTED_FILES=$(echo "$STAGED_FILES" | \
grep -vE "$EXCLUDED_FILES_REGEX" | \
paste -sd,)

echo -e "${GREEN}\nAffected files: $AFFECTED_FILES\n${NO_COLOUR}"

# Exit early if there are no affected files
if [ -z "$AFFECTED_FILES" ]; then
echo -e "${GREEN}No affected files found. Exiting pre-commit hook.${NO_COLOUR}"
exit 0
fi

commands=("npx nx affected -t lint, typecheck --parallel=3" "npx nx affected:test --coverage")
# Prepare the affected commands for static analysis targets
AFFECTED_COMMAND="yarn nx affected --files=$AFFECTED_FILES --nxBail --tui=false"
commands=("$AFFECTED_COMMAND -t lint typecheck --parallel=3", "$AFFECTED_COMMAND -t test --configuration coverage")
failures=()

# Loop over commands, execute and push failure message if we see one
Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ jobs:
deploy:
name: Test package building
runs-on: ubuntu-latest
env:
# Generating an Nx library will cause a failure if this is enabled
YARN_ENABLE_IMMUTABLE_INSTALLS: 0
strategy:
matrix:
node-version: [20.18]
node-version: [22.14]
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -29,13 +32,13 @@ jobs:
cache: yarn

- name: Install dependencies
run: yarn install --immutable
run: yarn install

- name: Generate test library
run: npx nx g library test-lib --directory=libs/test-lib --unitTestRunner=none
run: yarn nx g library test-lib --directory=libs/test-lib --unitTestRunner=none

- name: Generate test app
run: npx nx g service test-app
run: yarn nx g service test-app --type=general

# The next 2 lines are needed for nx affected to work when CI is running on a PR
- name: Set base SHA to origin/main
Expand All @@ -45,10 +48,10 @@ jobs:
run: git fetch

- name: Run tests
run: npx nx affected -t lint, test, build --parallel=3 --base=origin/main
run: yarn nx affected -t lint, typecheck, build --parallel=3 --base=origin/main

- name: Remove test library
run: npx nx g rm test-lib
run: yarn nx g rm @aligent/test-lib

- name: Remove test app
run: npx nx g rm test-app
run: yarn nx g rm @services/test-app
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

# environment
*.env
*.env*.csv
!.env.example.csv

# compiled output
dist
tmp
/out-tsc
.serverless
out-tsc
.build

# dependencies
Expand Down Expand Up @@ -58,3 +59,7 @@ Thumbs.db
# Vite temporary config files
vite.config.*.timestamp*
vitest.config.*.timestamp*

# CDK asset staging directory
.cdk.staging
cdk.out
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20.18
v22.14.0
5 changes: 4 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"nrwl.angular-console",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"editorconfig.editorconfig"
"editorconfig.editorconfig",
"amazonwebservices.aws-toolkit-vscode",
"usernamehw.errorlens",
"yoavbls.pretty-ts-errors"
]
}
155 changes: 155 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Essential Commands

### Testing

- **Run tests for affected projects**: `yarn test`
- **Run tests for all projects**: `yarn test:all`
- **Run a single test file**: `npx vitest run path/to/test.spec.ts`
- **Run tests in watch mode**: `npx vitest watch`
- **Run tests for specific project**: `npx nx test @libs/cdk-utils`
- **Run specific test file with Nx**: `npx nx test @libs/cdk-utils -- path/to/test.spec.ts`

### Code Quality

- **Lint affected projects**: `yarn lint`
- **Lint all projects**: `yarn lint:all`
- **Type check affected projects**: `yarn typecheck`
- **Type check all projects**: `yarn typecheck:all`

### Service Management

- **Generate new service**: `npx nx g service <service-name>`
- **Generate notification service**: `npx nx g service <service-name> notification`
- **Deploy service to AWS**: `npx nx deploy <service-name> -- -s <stage> --aws-profile <profile>`
- **Remove service from AWS**: `npx nx run <service-name>:remove -- -s <stage> --aws-profile <profile>`

### CDK Deployment

- **Deploy all stacks**: `cd applications/core && cdk deploy`
- **Deploy staging stacks**: `cd applications/core && cdk deploy stg/**`
- **Deploy production stacks**: `cd applications/core && cdk deploy prd/**`
- **View CDK diff**: `cd applications/core && cdk diff`

### API Client Generation

- **Generate typed API client**: `npx nx g client <client-name>`

## Architecture Overview

This is an AWS microservices template using:

- **Nx monorepo** structure with services in `services/` and libraries in `libs/`
- **AWS CDK v2** for infrastructure as code (recently migrated from Serverless Framework)
- **TypeScript** with strict type checking extending @aligent/ts-code-standards
- **Node.js 22.14.0** runtime

### Key Architecture Patterns

1. **Service-Based Architecture**

- Each service is a separate CDK Stack defined in `services/<service-name>/src/index.ts`
- Services export a Stack class that extends `aws-cdk-lib.Stack`
- Services are imported and instantiated in `ApplicationStage` inside `applications/core/bin/main.ts`

2. **CDK Application Structure**

- Entry point: `applications/core/bin/main.ts` creates CDK App and stages
- Stages (dev/stg/prd) are created as ApplicationStage instances directly in `main.ts`
- Stage-specific configuration is applied via property injectors and aspects
- Each stage automatically configures resources based on deployment environment

3. **Lambda and Step Functions**

- Lambda functions are in `services/<service>/src/lambda/`
- Step Functions use YAML definitions in `services/<service>/src/step-functions/`
- Shared constructs in `services/<service>/src/lib/constructs/`
- Step Functions use JSONata for output transformations
- Automatic versioning and aliasing applied via VersionFunctionsAspect
- Stage-specific configuration applied via property injectors

4. **Property Injection Architecture**

- Configuration-based defaults applied via property injectors:
- **NodeJsFunctionDefaultsInjector**: Bundling configuration (sourceMap, esm, minify)
- **LogGroupDefaultsInjector**: Duration-based retention (SHORT/MEDIUM/LONG)
- **StepFunctionDefaultsInjector**: Automatic logging for EXPRESS workflows
- **BucketDefaultsInjector**: Auto-cleanup policies for S3 buckets
- Cross-cutting concerns handled by aspects (VersionFunctionsAspect for automatic versioning)
- Configuration can be customized per stage or globally
- Uses CDK's built-in property injection system - no custom constructs needed

5. **CDK Constructs and Utilities**

- **S3Bucket**: Lifecycle management with duration-based rules (SHORT/MEDIUM/LONG/PERMANENT)
- **SsmParameterGroup**: Abstract class for grouping and managing SSM parameters
- **StepFunctionFromFile**: Load Step Function definitions from YAML/JSON files

6. **Testing Strategy**
- Vitest for unit testing with coverage reports
- Test files colocated with source files as `*.spec.ts` or `*.test.ts`
- Workspace-level Vitest configuration in `vitest.workspace.ts`

## Important Context

### CDK Migration Notes

- Project migrated from Serverless Framework to CDK using property injection pattern
- CDK construct IDs are critical - changing them will replace resources
- Lambda versions and aliases are automatically created via VersionFunctionsAspect
- Step Functions use `LambdaInvoke` resource with automatic retry blocks
- Task outputs are nested in `Payload` property - use JSONata to transform
- Stage-specific resource configuration handled by property injectors

### Configuration

- Update brand name in `nx.json` generators section before first use
- Package name in `package.json` should follow `@<brand>-int/integrations` format
- Services are tagged with STAGE and SERVICE tags automatically

### Development Workflow

1. Always run lint and type checks before committing
2. Use Nx affected commands to optimize CI/CD performance
3. Follow existing code patterns and conventions in the codebase
4. Check `CDK-MIGRATION-NOTES.md` for CDK-specific guidance

## AI Helpers

The `docs/ai-helpers/` folder contains documentation templates to assist AI code assistants in creating consistent and comprehensive documentation:

### Recommended MCP Servers

When using Claude Code or other MCP-compatible tools, the following MCP servers are recommended for this repository:

- **context7**: Provides up-to-date documentation for libraries and frameworks
- **eslint**: Enables linting capabilities for code quality checks
- **nx**: Offers Nx-specific commands and workspace insights

These servers should be used when available to enhance development capabilities.

### Available Templates

- **`APPLICATION_ARCHITECTURE_FORMAT.md`**: Template for creating comprehensive architecture diagrams for AWS CDK services
- Provides guidelines for analyzing CDK application structure
- Includes Mermaid diagram formats with consistent color palettes
- Shows how to map Step Function workflows and Lambda functions
- Contains common architectural patterns and best practices

- **`SERVICE_README_FORMAT.md`**: Template for creating service-specific README documentation
- Standardized format for service documentation
- Context diagram template showing external system interactions
- Sections for workflows, critical information, and operational details
- Consistent color palette for system visualization

### When to Use

Reference these templates when:
- Creating new architecture documentation (`ARCHITECTURE.md`)
- Documenting a new service with a README
- Updating existing service documentation
- Generating visual representations of service interactions
- Ensuring consistency across all service documentation
Loading