- Python 3.14 with
uvpackage manager — pinned in.python-version, souvprovisions and uses the same interpreter CI and AWS Lambda run (3.14);requires-python = ">=3.14"is a floor, not a license to develop on a newer minor. - Node.js 24+ with
npm - AWS CLI v2 configured with appropriate credentials
- AWS Account with permissions for IAM, DynamoDB, S3, Cognito, AppSync, ACM, Route 53, CloudFront, Lambda, SNS, CloudFormation, and CloudWatch/Billing
- Git for version control
- OpenTofu >= 1.8.0
# Clone the repository
git clone https://github.com/dmeiser/kernelworx.git
cd kernelworx
# Install Python dependencies (Lambda functions)
uv sync
# Install root Node.js dependencies (AppSync resolver bundling tooling)
npm install
# Install OpenTofu (macOS with Homebrew)
brew install opentofu
# Or on Linux
curl -fsSL https://get.opentofu.org | bash# Configure AWS CLI with your dev account
aws configure --profile dev
# Set as default profile (optional)
export AWS_PROFILE=devOpenTofu stores state in S3. The backend bucket must exist before the first tofu init:
# Deploy the bootstrap CloudFormation stack (adjust Environment if needed)
aws cloudformation deploy \
--template-file tofu/bootstrap/state-bucket.yaml \
--stack-name kernelworx-tofu-state \
--parameter-overrides Environment=dev \
--region us-east-1Verify the bucket name matches the backend configured in tofu/application/environments/dev/main.tf (default: kernelworx-tofu-state-us-east-1-dev). If you changed regions or naming conventions, update the backend config or the template parameters accordingly.
Important: Create a .env file in the repository root with your configuration:
cp .env.example .envEdit .env with your settings:
# Encryption passphrase for state files (generate a secure random string)
TF_VAR_encryption_passphrase=your-secure-passphrase-hereThe deployment helper scripts source this root .env file. If you run tofu directly, export the variable instead:
export TF_VAR_encryption_passphrase='your-passphrase'# Check Python version
python --version # Should be 3.14 (the .python-version pin)
# Check uv
uv --version
# Check Node.js
node --version # Should be 24+
# Check AWS credentials
aws sts get-caller-identityUse the deployment helper, which builds the Lambda layer, bundles the AppSync resolver JavaScript, and runs OpenTofu:
# Initialize OpenTofu (first time only)
./tofu/application/scripts/deploy.sh dev init
# Preview changes
./tofu/application/scripts/deploy.sh dev plan
# Apply changes
./tofu/application/scripts/deploy.sh dev applyThe helper will:
- Source the root
.envfor requiredTF_VAR_*values - Build
.build/lambda-layerfrom production Python dependencies - Bundle the AppSync resolver JavaScript (
npm run build:resolvers) - Run
tofuintofu/application/environments/dev
If you run tofu directly, export TF_VAR_encryption_passphrase, build the
layer, and bundle the resolver JavaScript first (npm install at the repo
root, then npm run build:resolvers); a plain tofu apply fails because the
layer archive and the resolver bundle (tofu/application/appsync/dist/) are
missing.
If you prefer more control:
# Set encryption passphrase
export TF_VAR_encryption_passphrase='your-passphrase'
# Build the Lambda layer first (required by the lambda module)
rm -rf .build/lambda-layer
mkdir -p .build/lambda-layer/python
uv export --no-dev --format requirements.txt --no-hashes > .build/lambda-layer/requirements.txt
uv pip install --requirement .build/lambda-layer/requirements.txt --target .build/lambda-layer/python
# Bundle the AppSync resolver JavaScript (required by the appsync module)
npm install
npm run build:resolvers
# Run OpenTofu from the environment directory
cd tofu/application/environments/dev
tofu init
tofu plan -out=tfplan
tofu apply tfplanIf you have existing resources from a previous deployment, you can import them into OpenTofu state:
cd tofu/application/environments/dev
# Import existing DynamoDB table
tofu import 'module.dynamodb.aws_dynamodb_table.accounts' table-name
# Import existing S3 bucket
tofu import 'module.s3.aws_s3_bucket.static' bucket-nameFinding existing resources:
# Find DynamoDB tables
aws dynamodb list-tables --query 'TableNames[?contains(@, `kernelworx`)]'
# Find S3 buckets
aws s3 ls | grep kernelworx
# Find Cognito User Pools
aws cognito-idp list-user-pools --max-results 60 | grep kernelworx
# Find AppSync APIs
aws appsync list-graphql-apis --query 'graphqlApis[?contains(name, `kernelworx`)].id'Each environment has its own directory:
# For dev environment
cd tofu/application/environments/dev
tofu apply
# For prod environment (when ready)
cd tofu/application/environments/prod
tofu applyEach environment gets its own isolated resources with environment-specific naming.
To enable social login providers, set environment variables before deployment:
# Set OAuth credentials as OpenTofu variables
export TF_VAR_google_client_id="your-client-id"
export TF_VAR_google_client_secret="your-client-secret"
# Deploy
cd tofu/application/environments/dev
tofu applyImportant: the dev environment currently enables Google IdP and WebAuthn by default. If you do not have Google OAuth credentials, set enable_google_idp = false and enable_webauthn = false in tofu/application/environments/dev/main.tf before running tofu apply, or the deployment may create a broken Cognito configuration. If these variables are not set and Google IdP remains enabled, only email/password authentication will work reliably.
# Run all Lambda function tests with coverage
uv run pytest tests/unit --cov=src --cov-fail-under=100
# Run specific test file
uv run pytest tests/unit/test_transfer_profile_ownership.py -v
# Run with coverage report
uv run pytest tests/unit --cov=src --cov-report=htmlA Playwright-based e2e smoke suite exercises the deployed dev environment end-to-end (auth, profiles, campaigns, orders, sharing, signup). It requires the dev environment to be live and test users pre-created.
# Install Playwright browsers (first time only)
uv run playwright install chromium
# Run the full e2e suite
uv run pytest tests/e2e/ --ignore=tests/unit -vSee tests/e2e/README.md for full prerequisites, .env requirements, and troubleshooting.
# Format code
uv run ruff check --select I --fix src/ tests/
uv run ruff format src/ tests/
# Type checking
uv run mypy src/
# Run all checks
uv run ruff check --select I --fix src/ tests/ && \
uv run ruff format src/ tests/ && \
uv run mypy src/ && \
uv run pytest tests/unit --cov=src --cov-fail-under=100cd tofu/application/environments/dev
# Bundle the resolver JavaScript first (see Manual Deployment above);
# a plain tofu init/plan fails while tofu/application/appsync/dist is missing
# Initialize working directory
tofu init
# Show differences between deployed and local
tofu plan
# Deploy changes
tofu apply
# Destroy resources (WARNING: use with caution)
tofu destroyAfter deployment, OpenTofu outputs key resource identifiers:
# Get outputs
cd tofu/application/environments/dev
tofu outputKey outputs include:
- cognito_user_pool_id: Cognito User Pool ID
- cognito_client_id: App client ID for authentication
- appsync_api_url: AppSync GraphQL API endpoint
- cloudfront_distribution_id: CloudFront distribution ID for invalidations
- static_assets_bucket: S3 bucket for SPA hosting
- exports_bucket: S3 bucket for generated reports
- site_url: Public URL of the deployed application
After the backend is deployed, build and deploy the React SPA:
cd frontend
# Build the production bundle. For dev/prod the app is same-origin — it calls
# /graphql and the auth paths through the site's CloudFront distribution — so
# VITE_APPSYNC_ENDPOINT and VITE_COGNITO_DOMAIN must stay unset for the build.
# They are only for local `vite dev` and ephemeral environments (see
# frontend/.env.example); make sure no local .env / .env.local defining them
# is present, or Vite will bake the absolute endpoints into the bundle.
#
# The public order pages (API-key auth) instead need the AppSync API key baked
# into the same build — a replaced key with a stale bundle fails every public
# call with Unauthorized until the next deploy:
export VITE_APPSYNC_API_KEY=$(tofu -chdir=../tofu/application/environments/dev output -raw appsync_api_key)
npm run build
# Upload to S3
aws s3 sync dist s3://$(tofu -chdir=../tofu/application/environments/dev output -raw static_assets_bucket) --delete
# Invalidate the CloudFront distribution
aws cloudfront create-invalidation \
--distribution-id $(tofu -chdir=../tofu/application/environments/dev output -raw cloudfront_distribution_id) \
--paths "/*"If a previous apply was interrupted:
tofu force-unlock <lock-id>Delete the existing domain or use a different environment name:
# Delete domain
aws cognito-idp delete-user-pool-domain \
--domain login.dev.kernelworx.app \
--user-pool-id us-east-1_XXXXXXXXXEither:
- Import it using context:
-c table_name=kernelworx-accounts-ue1-dev - Delete it:
aws dynamodb delete-table --table-name kernelworx-accounts-ue1-dev - Rename in different environment:
-c environment=prod
The deployed resources use serverless/on-demand pricing:
- DynamoDB: Pay-per-request (PAY_PER_REQUEST)
- S3: Pay for storage and requests
- Cognito: Essentials tier (~$0.015 per MAU after 50 free MAUs)
- AppSync: Pay per request and data transfer
- Lambda: Pay per invocation
Monthly Budget: $10/month with alerts at 80% and 100% configured in CloudWatch Billing Alerts.
- Run Backend Tests -
uv run pytest tests/unit --cov=src --cov-fail-under=100 - Deploy Frontend - Build the React SPA and deploy to S3 + CloudFront
- Configure Social Providers - Set up an OAuth app with Google (optional)
- Create an Admin Catalog - Required before campaigns can be created
- Create Test Users -
bash scripts/create-test-users.sh - Run E2E Smoke Tests -
uv run pytest tests/e2e/ --ignore=tests/unit -v - Set Up CI/CD - GitHub Actions for automated testing and deployment
- Documentation: See AGENT.md and docs/ for development guidelines and specifications
- Issues: File issues on GitHub repository
- Contact: dave@repeatersolutions.com