@thunder-so/thunder 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/CLI.md +65 -0
- package/.agents/METADATA.md +75 -0
- package/.agents/PRD.md +537 -0
- package/.agents/SKILLS.md +543 -0
- package/README.md +409 -0
- package/bun.lock +425 -0
- package/cli/th.mjs +45 -0
- package/index.ts +25 -0
- package/package.json +63 -0
- package/runtime/Dockerfile +44 -0
- package/thunder-so-thunder-1.1.0.tgz +0 -0
- package/tsconfig.tsbuildinfo +1 -0
package/.agents/CLI.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Thunder CLI Scope
|
|
2
|
+
|
|
3
|
+
The Thunder CLI (`th`) is the primary interface for developing, deploying, and managing applications built with `@thunder-so/thunder`. It is designed to be a thin, context-aware wrapper around the AWS CDK, providing a developer experience similar to SST but tailored for the Thunder ecosystem.
|
|
4
|
+
|
|
5
|
+
## Core Mandates
|
|
6
|
+
|
|
7
|
+
1. **Context-Awareness:** [x] **DONE**: The CLI automatically detects the current environment, application, and service from the repository structure or configuration, minimizing repetitive flag usage.
|
|
8
|
+
2. **Zero-Config Defaults:** [x] **DONE**: "It just works" out of the box with sensible defaults for AWS regions, accounts, and resource sizing.
|
|
9
|
+
3. **Local Dev Parity:** [ ] **TODO**: Enables a local development loop that closely mirrors production, including live Lambda iteration (future scope) and local emulation of static sites.
|
|
10
|
+
|
|
11
|
+
## Command Reference
|
|
12
|
+
|
|
13
|
+
### `th init`
|
|
14
|
+
- [ ] **TODO**: Scaffolds a new Thunder project or adds a new service to an existing monorepo.
|
|
15
|
+
|
|
16
|
+
- **Usage:** `th init [template] [name]`
|
|
17
|
+
- **Features:**
|
|
18
|
+
- Detects if running in an existing workspace (monorepo).
|
|
19
|
+
- Prompts for project type: `static`, `lambda`, `fargate`, `nuxt`, `astro`, `ec2`, `template`.
|
|
20
|
+
- Generates `thunder.config.ts` (or updates it).
|
|
21
|
+
- Creates necessary `bin/*.ts` entry points.
|
|
22
|
+
- Sets up `.gitignore` and `package.json` scripts.
|
|
23
|
+
|
|
24
|
+
### `th deploy`
|
|
25
|
+
- [ ] **TODO**: Deploys the application to AWS.
|
|
26
|
+
|
|
27
|
+
- **Usage:** `th deploy [--stage <stage>] [--filter <service>]`
|
|
28
|
+
- **Features:**
|
|
29
|
+
- **Stage Management:** defaults to `dev` for local, but supports `prod`, `staging`, `pr-*`.
|
|
30
|
+
- **Context-Driven:** [x] **DONE**: Reads `bin/*.ts` files to determine which stacks to deploy.
|
|
31
|
+
- **Metadata Push:** [x] **DONE**: Updates the `thunder-discovery` bucket with new resource ARNs and endpoints after successful deployment.
|
|
32
|
+
- **Output:** Prints critical URLs (CloudFront, API Gateway, ALB) to the console.
|
|
33
|
+
|
|
34
|
+
### `th destroy`
|
|
35
|
+
- [ ] **TODO**: Tears down resources.
|
|
36
|
+
|
|
37
|
+
- **Usage:** `th remove [--stage <stage>] [--filter <service>]`
|
|
38
|
+
- **Features:**
|
|
39
|
+
- **Safety Checks:** Prompts for confirmation, especially for `prod` stages or stateful resources (RDS, S3).
|
|
40
|
+
- **Metadata Cleanup:** Removes entries from the `thunder-discovery` bucket.
|
|
41
|
+
|
|
42
|
+
## Implementation Details
|
|
43
|
+
|
|
44
|
+
### Context Resolution (`bin/*.ts`)
|
|
45
|
+
- [x] **DONE**: The CLI relies on the convention of `bin/<type>.ts` files.
|
|
46
|
+
- `th deploy` scans `bin/` directory.
|
|
47
|
+
- It executes these scripts using `ts-node` or `tsx`.
|
|
48
|
+
- The scripts instantiate the Stacks (e.g., `NuxtStack`, `FargateStack`).
|
|
49
|
+
- The CLI injects context (app, env, service, account, region) via environment variables or context context keys.
|
|
50
|
+
|
|
51
|
+
### CLI Architecture
|
|
52
|
+
- [ ] **TODO**:
|
|
53
|
+
- **Runtime:** Node.js
|
|
54
|
+
- **Core Libs:** `aws-cdk` (programmatic), `aws-sdk` (v3), `inquirer` (prompts), `commander` (args), `ink` (TUI).
|
|
55
|
+
- **Build:** `esbuild` for fast bundling of Lambda code during `th dev`.
|
|
56
|
+
|
|
57
|
+
## Comparison with SST
|
|
58
|
+
|
|
59
|
+
| Feature | SST CLI | Thunder CLI |
|
|
60
|
+
| :--- | :--- | :--- |
|
|
61
|
+
| **Engine** | Pulumi / Terraform (v3) | AWS CDK (Native) |
|
|
62
|
+
| **Language** | TypeScript / Python / Go | TypeScript (Strict) |
|
|
63
|
+
| **State** | Cloud State Backend | CloudFormation + S3 Metadata |
|
|
64
|
+
| **Local Dev** | Live Lambda (Multiplexing) | Hotswap + Local Framework Server |
|
|
65
|
+
| **Constructs** | Broad (150+ providers) | Focused (AWS Web patterns) |
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Metadata Discovery
|
|
2
|
+
|
|
3
|
+
Thunder implements an "SST-style" discovery mechanism to enable the Thunder CLI and potential future Thunder Console to automatically identify and interact with deployed resources without relying on manual tagging or complex CloudFormation stack queries.
|
|
4
|
+
|
|
5
|
+
## How Thunder Tags Deployments
|
|
6
|
+
|
|
7
|
+
- [x] **DONE**: Thunder uses a state-based approach rather than traditional AWS resource tags for discovery.
|
|
8
|
+
|
|
9
|
+
### State Storage
|
|
10
|
+
When you deploy a Thunder service, it automatically stores its deployment state in a centralized S3 bucket named `thunder-discovery-<account>-<region>`.
|
|
11
|
+
|
|
12
|
+
### Key Structure
|
|
13
|
+
Metadata files are stored with the following hierarchy:
|
|
14
|
+
`apps/<application>/<environment>/<service>/metadata.json`
|
|
15
|
+
|
|
16
|
+
### Metadata Content
|
|
17
|
+
The `metadata.json` file contains a standardized set of properties that align with the service's `CfnOutput` names:
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"id": "myapp-prod-web",
|
|
21
|
+
"application": "myapp",
|
|
22
|
+
"service": "web",
|
|
23
|
+
"environment": "prod",
|
|
24
|
+
"region": "us-east-1",
|
|
25
|
+
"timestamp": "2026-03-04T12:00:00.000Z",
|
|
26
|
+
"type": "Nuxt",
|
|
27
|
+
"DistributionId": "E1234567890",
|
|
28
|
+
"DistributionUrl": "https://d123.cloudfront.net",
|
|
29
|
+
"Route53Domain": "https://myapp.com",
|
|
30
|
+
"CodePipelineName": "myapp-prod-web-pipeline"
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## How the CLI/Console Discovers Apps
|
|
35
|
+
|
|
36
|
+
1. **Bucket Resolution**: The tool determines the discovery bucket name based on the current AWS account and region.
|
|
37
|
+
2. **S3 Scanning**: It lists the objects in the bucket under the `apps/` prefix.
|
|
38
|
+
3. **Metadata Parsing**: It reads the `metadata.json` files to discover:
|
|
39
|
+
- All deployed Thunder apps.
|
|
40
|
+
- Their environments/stages.
|
|
41
|
+
- Their individual services and associated resource IDs/URLs.
|
|
42
|
+
4. **Automatic Discovery**: Because the `DiscoveryConstruct` is embedded in every Thunder stack, new services and updates are automatically reflected in S3 upon successful deployment.
|
|
43
|
+
|
|
44
|
+
## Implementation Details
|
|
45
|
+
|
|
46
|
+
- [x] **DONE**: **`DiscoveryConstruct`**: A shared construct located in `lib/constructs/discovery.ts`.
|
|
47
|
+
- [x] **DONE**: **`BucketDeployment`**: Uses `aws-s3-deployment` to upload `Source.jsonData` during the CDK deployment phase.
|
|
48
|
+
- [x] **DONE**: **Standardization**: Metadata field names are strictly aligned with `CfnOutput` logical IDs (e.g., `DistributionId`, `ServiceUrl`).
|
|
49
|
+
- [x] **DONE**: Each deployment stores its metadata in a centralized S3 bucket (`thunder-discovery-<account>-<region>`).
|
|
50
|
+
|
|
51
|
+
Metadata includes:
|
|
52
|
+
- [x] App identity (application, service, environment)
|
|
53
|
+
- [x] Resource ARNs, IDs and URLs (Aligned with `CfnOutput` names)
|
|
54
|
+
- [x] Deployment timestamps
|
|
55
|
+
- [x] Framework-specific metadata
|
|
56
|
+
- [x] Route53 domain integration
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
## ISSUES:
|
|
60
|
+
|
|
61
|
+
7:11:10 PM | CREATE_FAILED | Custom::CDKBucketDeployment | Discovery/StoreMet...omResource/Default
|
|
62
|
+
Received response status [FAILED] from custom resource. Message returned: Command '['/opt/awscli/aws', 's3', 'sync', '/tmp/tmpxgahyp87/contents', 's3://thunder-discovery-047719662375-us-east
|
|
63
|
+
-1/apps/nuxt3/dev/fargate']' returned non-zero exit status 1. (RequestId: afc6bb52-d373-4b97-9a7d-36d0ab9b9425)
|
|
64
|
+
7:11:10 PM | ROLLBACK_IN_PROGRESS | AWS::CloudFormation::Stack | nuxt3-fargate-dev-stack
|
|
65
|
+
The following resource(s) failed to create: [DiscoveryStoreMetadataCustomResource5F6695DB, FargateFargateService7449B65B]. Rollback requested by user.
|
|
66
|
+
7:11:10 PM | ROLLBACK_IN_PROGRESS | AWS::CloudFormation::Stack | nuxt3-fargate-dev-stack
|
|
67
|
+
The following resource(s) failed to create: [DiscoveryStoreMetadataCustomResource5F6695DB, FargateFargateService7449B65B]. Rollback requested by user.
|
|
68
|
+
7:11:37 PM | DELETE_FAILED | Custom::CDKBucketDeployment | Discovery/StoreMet...omResource/Default
|
|
69
|
+
Received response status [FAILED] from custom resource. Message returned: Command '['/opt/awscli/aws', 's3', 'rm', 's3://thunder-discovery-047719662375-us-east-1/apps/nuxt3/dev/fargate', '--
|
|
70
|
+
recursive']' returned non-zero exit status 1. (RequestId: f9383113-0976-4fe3-af60-bcefbf14d514)
|
|
71
|
+
|
|
72
|
+
❌ nuxt3-fargate-dev-stack failed: ToolkitError: The stack named nuxt3-fargate-dev-stack failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_FAILED (The following resource(s) failed to delete: [DiscoveryStoreMetadataCustomResource5F6695DB]. ): Received response status [FAILED] from custom resource. Message returned: Command '['/opt/awscli/aws', 's3', 'sync', '/tmp/tmpxgahyp87/contents', 's3://thunder-discovery-047719662375-us-east-1/apps/nuxt3/dev/fargate']' returned non-zero exit status 1. (RequestId: afc6bb52-d373-4b97-9a7d-36d0ab9b9425), Received response status [FAILED] from custom resource. Message returned: Command '['/opt/awscli/aws', 's3', 'rm', 's3://thunder-discovery-047719662375-us-east-1/apps/nuxt3/dev/fargate', '--recursive']' returned non-zero exit status 1. (RequestId: f9383113-0976-4fe3-af60-bcefbf14d514)
|
|
73
|
+
|
|
74
|
+
The following resource(s) failed to delete: [DiscoveryStoreMetadataCustomResource5F6695DB].
|
|
75
|
+
Received response status [FAILED] from custom resource. Message returned: Command '['/opt/awscli/aws', 's3', 'rm', 's3://thunder-discovery-047719662375-us-east-1/apps/nuxt3/dev/fargate', '--recursive']' returned non-zero exit status 1. (RequestId: f9383113-0976-4fe3-af60-bcefbf14d514)
|
package/.agents/PRD.md
ADDED
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
# Thunder - CDK Library for AWS Deployments
|
|
2
|
+
|
|
3
|
+
## Executive Summary
|
|
4
|
+
|
|
5
|
+
Thunder (`@thunder-so/thunder`) is an AWS CDK library for deploying modern web applications. It provides opinionated, production-ready infrastructure patterns for one-line deployment of common web application architectures.
|
|
6
|
+
|
|
7
|
+
**One library to rule them all**: Static SPAs, Lambda Functions, Containers (Fargate/EC2), and Full-stack Frameworks (Nuxt/Astro).
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Project Overview
|
|
12
|
+
|
|
13
|
+
Thunder provides high-level abstractions over AWS CDK, enabling developers to deploy complete infrastructure stacks with minimal configuration. The library covers the full spectrum of web deployment patterns from static sites to full-stack serverless applications.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Stacks
|
|
18
|
+
|
|
19
|
+
| Stack | Description | Use Cases | Status |
|
|
20
|
+
|-----------|-------------|-----------|--------|
|
|
21
|
+
| `Static` | S3 + CloudFront for static SPAs | React, Vue, Svelte, Next.js (SSG), Gatsby | **DONE** |
|
|
22
|
+
| `Lambda` | Lambda + API Gateway for serverless | API endpoints, background jobs, microservices | **DONE** |
|
|
23
|
+
| `Fargate` | ECS Fargate + ALB for containers | Long-running containers, microservices | **DONE** |
|
|
24
|
+
| `EC2` | EC2 instance with Docker + Elastic IP | Single containers, dev environments | **DONE** |
|
|
25
|
+
| `Template` | Coolify One-Click Service Template on EC2 | Pre-built apps (n8n, Plausible, etc.) | **DONE** |
|
|
26
|
+
| `Nuxt` | Full-stack Nuxt.js (Lambda + S3 + CloudFront) | SSR Nuxt applications | **DONE** |
|
|
27
|
+
| `Astro` | Full-stack Astro SSR (with Edge fallback) | SSR Astro applications | **DONE** |
|
|
28
|
+
| `VPC` | Shared VPC with public/private subnets | Shared networking infrastructure | **DONE** |
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Stack Details
|
|
33
|
+
|
|
34
|
+
### 1. Static Stack
|
|
35
|
+
**Purpose**: Static SPA hosting
|
|
36
|
+
**Resources**: S3 + CloudFront (OAC) + Route53 + Lambda@Edge
|
|
37
|
+
**Key Features**:
|
|
38
|
+
- Zero-downtime deployment without bucket pruning
|
|
39
|
+
- Origin Access Control (OAC) for secure S3 access
|
|
40
|
+
- Lambda@Edge for redirects/rewrites
|
|
41
|
+
- Custom security headers policy
|
|
42
|
+
- CI/CD pipeline support
|
|
43
|
+
|
|
44
|
+
**Entry Point**: `bin/static.ts`
|
|
45
|
+
**Stack File**: `stacks/StaticStack.ts`
|
|
46
|
+
**Constructs**:
|
|
47
|
+
- `HostingConstruct` (S3 + CloudFront + Route53)
|
|
48
|
+
- `DeployConstruct` (direct local deployment)
|
|
49
|
+
- `PipelineConstruct` (CodePipeline CI/CD)
|
|
50
|
+
|
|
51
|
+
### 2. Lambda Stack
|
|
52
|
+
**Purpose**: Serverless functions
|
|
53
|
+
**Resources**: Lambda (Zip or Container) + API Gateway v2 + ECR + Route53
|
|
54
|
+
**Key Features**:
|
|
55
|
+
- Bun runtime support via Lambda Layer
|
|
56
|
+
- Keep-warm scheduling (EventBridge)
|
|
57
|
+
- Provisioned concurrency support
|
|
58
|
+
- X-Ray tracing
|
|
59
|
+
- VPC integration
|
|
60
|
+
|
|
61
|
+
**Entry Point**: `bin/lambda.ts`
|
|
62
|
+
**Stack File**: `stacks/LambdaStack.ts`
|
|
63
|
+
**Constructs**:
|
|
64
|
+
- `FunctionsConstruct` (Lambda + API Gateway)
|
|
65
|
+
- `PipelineConstruct` (ECR-based CI/CD)
|
|
66
|
+
|
|
67
|
+
### 3. Fargate Stack
|
|
68
|
+
**Purpose**: Container orchestration
|
|
69
|
+
**Resources**: ECS Fargate + ALB + VPC + ECR + Route53
|
|
70
|
+
**Key Features**:
|
|
71
|
+
- ARM64 or X86_64 architecture support
|
|
72
|
+
- Auto-scaling capabilities
|
|
73
|
+
- Health checks with customizable paths
|
|
74
|
+
- Circuit breaker deployments
|
|
75
|
+
- Nixpacks integration for Dockerfile generation
|
|
76
|
+
- Rolling updates
|
|
77
|
+
|
|
78
|
+
**Entry Point**: `bin/fargate.ts`
|
|
79
|
+
**Stack File**: `stacks/FargateStack.ts`
|
|
80
|
+
**Constructs**:
|
|
81
|
+
- `ServiceConstruct` (ECS service + ALB + VPC)
|
|
82
|
+
- `PipelineConstruct` (ECR-based CI/CD)
|
|
83
|
+
|
|
84
|
+
### 4. EC2 Stack
|
|
85
|
+
**Purpose**: Single EC2 container hosting
|
|
86
|
+
**Resources**: EC2 + Elastic IP + Route53 + CloudWatch Agent
|
|
87
|
+
**Key Features**:
|
|
88
|
+
- Docker-on-EC2 deployment
|
|
89
|
+
- Elastic IP assignment
|
|
90
|
+
- Let's Encrypt SSL (via acmeEmail)
|
|
91
|
+
- SSH access with authorized keys
|
|
92
|
+
- CloudWatch monitoring
|
|
93
|
+
- Nixpacks support
|
|
94
|
+
|
|
95
|
+
**Entry Point**: `bin/ec2.ts`
|
|
96
|
+
**Stack File**: `stacks/Ec2Stack.ts`
|
|
97
|
+
**Constructs**:
|
|
98
|
+
- `ComputeConstruct` (EC2 instance + Docker)
|
|
99
|
+
- `PipelineConstruct` (CI/CD)
|
|
100
|
+
- `Ec2Instance` (instance provisioning)
|
|
101
|
+
- `UserData` (EC2 bootstrap scripts)
|
|
102
|
+
- `CloudwatchAgent` (monitoring)
|
|
103
|
+
|
|
104
|
+
### 5. Template Stack
|
|
105
|
+
**Purpose**: Coolify one-click templates
|
|
106
|
+
**Resources**: EC2 + Docker Compose + Traefik
|
|
107
|
+
**Key Features**:
|
|
108
|
+
- Fetches templates from Coolify GitHub repo
|
|
109
|
+
- Hydrates SERVICE_FQDN, SERVICE_PASSWORD variables
|
|
110
|
+
- Traefik reverse proxy with Let's Encrypt
|
|
111
|
+
- Multi-service Docker Compose support
|
|
112
|
+
|
|
113
|
+
**Entry Point**: `bin/template.ts`
|
|
114
|
+
**Stack File**: `stacks/TemplateStack.ts`
|
|
115
|
+
**Constructs**:
|
|
116
|
+
- `TemplateConstruct` (template deployment)
|
|
117
|
+
- `TemplateFetcher` (fetches from GitHub)
|
|
118
|
+
- `TemplateHydrator` (variable substitution)
|
|
119
|
+
|
|
120
|
+
### 6. Nuxt Stack
|
|
121
|
+
**Purpose**: Full-stack Nuxt.js deployment
|
|
122
|
+
**Resources**: Lambda (SSR) + S3 (Assets) + CloudFront (Dual Origin) + API Gateway
|
|
123
|
+
**Key Features**:
|
|
124
|
+
- Nitro preset optimized for AWS Lambda
|
|
125
|
+
- Static assets served from S3
|
|
126
|
+
- SSR via Lambda function
|
|
127
|
+
- API routes support
|
|
128
|
+
- Unified CloudFront distribution
|
|
129
|
+
|
|
130
|
+
**Entry Point**: `bin/nuxt.ts`
|
|
131
|
+
**Stack File**: `stacks/NuxtStack.ts`
|
|
132
|
+
**Constructs**:
|
|
133
|
+
- `NuxtConstruct` (SSR server + client)
|
|
134
|
+
- `ServerConstruct` (Lambda SSR)
|
|
135
|
+
- `ClientConstruct` (S3 + CloudFront)
|
|
136
|
+
- `FrameworkPipeline` (CI/CD)
|
|
137
|
+
|
|
138
|
+
### 7. Astro Stack
|
|
139
|
+
**Purpose**: Full-stack Astro SSR deployment
|
|
140
|
+
**Resources**: Lambda (SSR) + S3 + CloudFront + Edge Function fallback
|
|
141
|
+
**Key Features**:
|
|
142
|
+
- Same architecture as Nuxt (Lambda + S3 + CloudFront)
|
|
143
|
+
- Lambda@Edge fallback for 404/403 handling
|
|
144
|
+
- Edge-optimized for global distribution
|
|
145
|
+
- Astro-specific optimizations
|
|
146
|
+
|
|
147
|
+
**Entry Point**: `bin/astro.ts`
|
|
148
|
+
**Stack File**: `stacks/AstroStack.ts`
|
|
149
|
+
**Constructs**:
|
|
150
|
+
- `AstroConstruct` (SSR server + client)
|
|
151
|
+
- `ClientConstruct` (S3 + CloudFront + Edge fallback)
|
|
152
|
+
- `FrameworkPipeline` (CI/CD)
|
|
153
|
+
|
|
154
|
+
### 8. VPC Stack
|
|
155
|
+
**Purpose**: Shared VPC infrastructure
|
|
156
|
+
**Resources**: VPC with public/private subnets, NAT gateways
|
|
157
|
+
**Key Features**:
|
|
158
|
+
- Shared networking for multiple services
|
|
159
|
+
- Implements IVpcLink interface
|
|
160
|
+
- Configurable CIDR, AZs, NAT gateways
|
|
161
|
+
- Can be linked to other stacks
|
|
162
|
+
|
|
163
|
+
**Entry Point**: `bin/vpc.ts`
|
|
164
|
+
**Stack File**: `stacks/VpcStack.ts`
|
|
165
|
+
**Constructs**:
|
|
166
|
+
- `VPC` (shared VPC construct)
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Architecture
|
|
171
|
+
|
|
172
|
+
### Project Structure
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
@thunder-so/thunder/
|
|
176
|
+
├── bin/ # CDK entry points
|
|
177
|
+
│ ├── static.ts # Static SPA deployment
|
|
178
|
+
│ ├── lambda.ts # Lambda deployment
|
|
179
|
+
│ ├── fargate.ts # Fargate deployment
|
|
180
|
+
│ ├── ec2.ts # EC2 deployment
|
|
181
|
+
│ ├── template.ts # Coolify template deployment
|
|
182
|
+
│ ├── nuxt.ts # Nuxt deployment
|
|
183
|
+
│ ├── astro.ts # Astro deployment
|
|
184
|
+
│ └── vpc.ts # VPC deployment
|
|
185
|
+
│
|
|
186
|
+
├── cli/ # Thunder CLI
|
|
187
|
+
│ ├── th.mjs # Main CLI entry
|
|
188
|
+
│ ├── th-init.mjs # Init command
|
|
189
|
+
│ ├── th-deploy.mjs # Deploy command
|
|
190
|
+
│ └── th-destroy.mjs # Destroy command
|
|
191
|
+
│
|
|
192
|
+
├── lib/ # CDK constructs
|
|
193
|
+
│ ├── astro/ # Astro framework support
|
|
194
|
+
│ │ ├── index.ts # AstroConstruct
|
|
195
|
+
│ │ └── client.ts # Astro client (S3 + CloudFront + Edge)
|
|
196
|
+
│ │
|
|
197
|
+
│ ├── constructs/ # Shared constructs
|
|
198
|
+
│ │ ├── vpc.ts # VPC construct
|
|
199
|
+
│ │ └── discovery.ts # SST-style metadata discovery
|
|
200
|
+
│ │
|
|
201
|
+
│ ├── ec2/ # EC2 implementation
|
|
202
|
+
│ │ ├── compute.ts # EC2 compute
|
|
203
|
+
│ │ ├── pipeline.ts # EC2 pipeline
|
|
204
|
+
│ │ └── constructs/
|
|
205
|
+
│ │ ├── cloudwatch-agent.ts
|
|
206
|
+
│ │ ├── ec2-instance.ts
|
|
207
|
+
│ │ └── user-data.ts
|
|
208
|
+
│ │
|
|
209
|
+
│ ├── fargate/ # Fargate implementation
|
|
210
|
+
│ │ ├── service.ts # ECS Fargate service
|
|
211
|
+
│ │ └── pipeline.ts # Fargate pipeline
|
|
212
|
+
│ │
|
|
213
|
+
│ ├── frameworks/ # Framework pipeline
|
|
214
|
+
│ │ └── pipeline.ts # Shared framework CI/CD
|
|
215
|
+
│ │
|
|
216
|
+
│ ├── lambda/ # Lambda implementation
|
|
217
|
+
│ │ ├── functions.ts # Lambda + API Gateway
|
|
218
|
+
│ │ └── pipeline.ts # Lambda pipeline
|
|
219
|
+
│ │
|
|
220
|
+
│ ├── nuxt/ # Nuxt implementation
|
|
221
|
+
│ │ ├── index.ts # NuxtConstruct
|
|
222
|
+
│ │ ├── server.ts # Nuxt server (Lambda)
|
|
223
|
+
│ │ └── client.ts # Nuxt client (S3 + CloudFront)
|
|
224
|
+
│ │
|
|
225
|
+
│ ├── static/ # Static implementation
|
|
226
|
+
│ │ ├── hosting.ts # S3 + CloudFront + Route53
|
|
227
|
+
│ │ ├── pipeline.ts # Static CI/CD
|
|
228
|
+
│ │ └── deploy.ts # Direct S3 deployment
|
|
229
|
+
│ │
|
|
230
|
+
│ ├── template/ # Coolify template implementation
|
|
231
|
+
│ │ ├── index.ts # TemplateConstruct
|
|
232
|
+
│ │ ├── template/
|
|
233
|
+
│ │ │ ├── fetch.ts # Fetch from GitHub
|
|
234
|
+
│ │ │ └── hydrate.ts # Variable hydration
|
|
235
|
+
│ │ └── constructs/
|
|
236
|
+
│ │ ├── cloudwatch-agent.ts
|
|
237
|
+
│ │ ├── ec2-instance.ts
|
|
238
|
+
│ │ └── user-data.ts
|
|
239
|
+
│ │
|
|
240
|
+
│ └── utils/ # Shared utilities
|
|
241
|
+
│ ├── index.ts # Main exports
|
|
242
|
+
│ ├── naming.ts # Resource naming
|
|
243
|
+
│ ├── paths.ts # Path sanitization
|
|
244
|
+
│ ├── nixpacks.ts # Nixpacks integration
|
|
245
|
+
│ └── vpc-link.ts # VPC linking
|
|
246
|
+
│
|
|
247
|
+
├── stacks/ # Stack definitions
|
|
248
|
+
│ ├── StaticStack.ts
|
|
249
|
+
│ ├── LambdaStack.ts
|
|
250
|
+
│ ├── FargateStack.ts
|
|
251
|
+
│ ├── Ec2Stack.ts
|
|
252
|
+
│ ├── TemplateStack.ts
|
|
253
|
+
│ ├── NuxtStack.ts
|
|
254
|
+
│ ├── AstroStack.ts
|
|
255
|
+
│ └── VpcStack.ts
|
|
256
|
+
│
|
|
257
|
+
├── types/ # TypeScript interfaces
|
|
258
|
+
│ ├── AppProps.ts # Base props
|
|
259
|
+
│ ├── StaticProps.ts
|
|
260
|
+
│ ├── LambdaProps.ts
|
|
261
|
+
│ ├── FargateProps.ts
|
|
262
|
+
│ ├── Ec2Props.ts
|
|
263
|
+
│ ├── TemplateProps.ts
|
|
264
|
+
│ ├── NuxtProps.ts
|
|
265
|
+
│ ├── VpcProps.ts
|
|
266
|
+
│ ├── CloudFrontProps.ts
|
|
267
|
+
│ └── PipelineProps.ts
|
|
268
|
+
│
|
|
269
|
+
├── .agents/ # Documentation
|
|
270
|
+
│ ├── PRD.md # This file
|
|
271
|
+
│ ├── CLI.md # CLI scope
|
|
272
|
+
│ ├── SKILLS.md # Claude skills plan
|
|
273
|
+
│ └── METADATA.md # Discovery mechanism
|
|
274
|
+
│
|
|
275
|
+
├── index.ts # Main exports
|
|
276
|
+
└── package.json
|
|
277
|
+
```
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
## Shared Infrastructure Patterns
|
|
281
|
+
|
|
282
|
+
### VPC Link Pattern
|
|
283
|
+
All compute stacks (Lambda, Fargate, EC2, Template) support a `link` pattern for VPC integration:
|
|
284
|
+
|
|
285
|
+
- Implemented via `resolveVpc()` utility
|
|
286
|
+
- Accepts `IVpc` directly or `IVpcLink` implementing construct
|
|
287
|
+
- Provides consistent VPC connectivity across stacks
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
// Explicit VPC passing
|
|
291
|
+
const vpc = new VpcStack(this, 'MyVPC', { ... });
|
|
292
|
+
|
|
293
|
+
new FargateStack(this, 'MyService', {
|
|
294
|
+
vpc: vpc,
|
|
295
|
+
// ...
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
// Via link property
|
|
299
|
+
new FargateStack(this, 'MyService', {
|
|
300
|
+
link: vpc, // IVpcLink interface
|
|
301
|
+
// ...
|
|
302
|
+
});
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### Resource Naming
|
|
306
|
+
**Pattern**: 23-character prefix ensuring uniqueness and AWS name limits
|
|
307
|
+
- **Format**: `${app.substring(0,7)}-${service.substring(0,7)}-${env.substring(0,7)}`
|
|
308
|
+
- **Utility**: `getResourceIdPrefix()` in `lib/utils/naming.ts`
|
|
309
|
+
- **Example**: `myapp-t-web-dev` (app="myapplication", service="webfrontend", env="development")
|
|
310
|
+
|
|
311
|
+
### Path Sanitization
|
|
312
|
+
**Purpose**: Ensure valid Unix directory paths for Docker builds and deployments
|
|
313
|
+
- **Utility**: `sanitizePath()` in `lib/utils/paths.ts`
|
|
314
|
+
- **Regex**: Removes invalid characters, normalizes slashes
|
|
315
|
+
- **Use Case**: User-provided rootDir/outputDir sanitization
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## Common Features Across Stacks
|
|
320
|
+
|
|
321
|
+
### 1. Monorepo Support
|
|
322
|
+
- **Path-based filters** in CodeBuild webhooks
|
|
323
|
+
- **rootDir/outputDir** resolution for monorepo packages
|
|
324
|
+
- **Context directory** support for taking source from any path
|
|
325
|
+
|
|
326
|
+
### 2. CI/CD Pipeline Integration
|
|
327
|
+
Optional AWS CodePipeline with GitHub support:
|
|
328
|
+
- Triggered by `accessTokenSecretArn` + `sourceProps` + `buildProps`
|
|
329
|
+
- Path-based filtering for monorepos
|
|
330
|
+
- ECR integration for container stacks
|
|
331
|
+
- S3 deployment for static stacks
|
|
332
|
+
|
|
333
|
+
### 3. Nixpacks Integration
|
|
334
|
+
Automatic Dockerfile generation:
|
|
335
|
+
- **Utility**: `generateNixpacksDockerfile()` in `lib/utils/nixpacks.ts`
|
|
336
|
+
- **Supported**: Fargate, EC2, Template stacks
|
|
337
|
+
- **Build system**: Detects language and generates optimized Dockerfile
|
|
338
|
+
|
|
339
|
+
### 4. Framework Fallbacks
|
|
340
|
+
Astro-specific Edge function for 404/403 handling:
|
|
341
|
+
- Implemented in `lib/astro/client.ts`
|
|
342
|
+
- CloudFront origin failover to S3 for SPA routing
|
|
343
|
+
|
|
344
|
+
### 5. Bun Support
|
|
345
|
+
Bun runtime for Lambda:
|
|
346
|
+
- Lambda Layer integration
|
|
347
|
+
- Custom runtime configuration for CodeBuild
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
## Thunder CLI
|
|
352
|
+
|
|
353
|
+
**Location**: `cli/th.mjs`
|
|
354
|
+
|
|
355
|
+
The Thunder CLI provides context-aware infrastructure management:
|
|
356
|
+
|
|
357
|
+
### Commands
|
|
358
|
+
|
|
359
|
+
| Command | Description | Status |
|
|
360
|
+
|---------|-------------|--------|
|
|
361
|
+
| `th init` | Scaffold new project/service | [ ] **TODO** |
|
|
362
|
+
| `th deploy` | Deploy stacks to AWS | [ ] **TODO** |
|
|
363
|
+
| `th destroy` | Remove resources from AWS | [ ] **TODO** |
|
|
364
|
+
|
|
365
|
+
### CLI Architecture
|
|
366
|
+
- **Runtime**: Node.js
|
|
367
|
+
- **Core Libraries**: `commander`, `inquirer`, `chalk`, `ora`, `shelljs`
|
|
368
|
+
- **Context Resolution**: Reads `bin/*.ts` files
|
|
369
|
+
- **Environment**: Injects CDK context via environment variables
|
|
370
|
+
|
|
371
|
+
### Context Resolution
|
|
372
|
+
1. CLI scans `bin/` directory for stack entry points
|
|
373
|
+
2. Executes via `ts-node` or `tsx`
|
|
374
|
+
3. Injects context: app, env, service, account, region
|
|
375
|
+
4. Delegates to CDK for actual deployment
|
|
376
|
+
|
|
377
|
+
**Status**: Basic CLI structure done, full implementation pending
|
|
378
|
+
|
|
379
|
+
---
|
|
380
|
+
|
|
381
|
+
## CLI Mandates
|
|
382
|
+
|
|
383
|
+
1. **Context-Awareness**: [x] **DONE** - Auto-detects environment from repository
|
|
384
|
+
2. **Zero-Config Defaults**: [x] **DONE** - Sensible defaults for AWS regions, accounts, resource sizing
|
|
385
|
+
3. **Local Dev Parity**: [ ] **TODO** - Local development loop (future scope)
|
|
386
|
+
4. **SST-Style Metadata**: [x] **DONE** - Discovery bucket for deployment state
|
|
387
|
+
|
|
388
|
+
---
|
|
389
|
+
|
|
390
|
+
## Future Extensibility
|
|
391
|
+
|
|
392
|
+
### Framework Support
|
|
393
|
+
|
|
394
|
+
The library should support additional Vite + Nitro-based frameworks:
|
|
395
|
+
- [ ] TanStack Start
|
|
396
|
+
- [ ] Angular AnalogJS
|
|
397
|
+
- [ ] SvelteKit
|
|
398
|
+
- [ ] React Router v7
|
|
399
|
+
- [ ] SolidStart
|
|
400
|
+
|
|
401
|
+
Each framework construct will have preset configurations optimized for that framework.
|
|
402
|
+
|
|
403
|
+
### Console UI
|
|
404
|
+
|
|
405
|
+
Future scope: SST-style Console UI for:
|
|
406
|
+
- Resource visualization
|
|
407
|
+
- Log streaming
|
|
408
|
+
- Real-time monitoring
|
|
409
|
+
- Deployment history
|
|
410
|
+
|
|
411
|
+
**Prerequisite**: Metadata Discovery system (already implemented)
|
|
412
|
+
|
|
413
|
+
---
|
|
414
|
+
|
|
415
|
+
## Status Overview
|
|
416
|
+
|
|
417
|
+
| Feature | Status | Notes |
|
|
418
|
+
|---------|--------|-------|
|
|
419
|
+
| **Static Stack** | [x] **DONE** | Production-ready |
|
|
420
|
+
| **Lambda Stack** | [x] **DONE** | Production-ready |
|
|
421
|
+
| **Fargate Stack** | [x] **DONE** | Production-ready |
|
|
422
|
+
| **EC2 Stack** | [x] **DONE** | Production-ready |
|
|
423
|
+
| **Template Stack** | [x] **DONE** | Production-ready |
|
|
424
|
+
| **Nuxt Stack** | [x] **DONE** | Production-ready |
|
|
425
|
+
| **Astro Stack** | [x] **DONE** | Production-ready |
|
|
426
|
+
| **VPC Stack** | [x] **DONE** | Production-ready |
|
|
427
|
+
| **VPC Link Pattern** | [x] **DONE** | All compute stacks |
|
|
428
|
+
| **Monorepo Support** | [x] **DONE** | Path filters, rootDir |
|
|
429
|
+
| **Nixpacks Integration** | [x] **DONE** | Auto Dockerfile gen |
|
|
430
|
+
| **Metadata Discovery** | [x] **DONE** | SST-style in S3 |
|
|
431
|
+
| **CI/CD Pipelines** | [x] **DONE** | CodePipeline + GitHub |
|
|
432
|
+
| **Bun Support** | [x] **DONE** | Lambda layer |
|
|
433
|
+
| **CLI Framework** | [x] **DONE** | Basic structure |
|
|
434
|
+
| **th init Command** | [ ] **TODO** | Scaffold projects |
|
|
435
|
+
| **th deploy Command** | [ ] **TODO** | Deploy stacks |
|
|
436
|
+
| **th destroy Command** | [ ] **TODO** | Remove resources |
|
|
437
|
+
| **Console UI** | [ ] **TODO** | Future scope |
|
|
438
|
+
| **Additional Frameworks** | [ ] **TODO** | TanStack, SvelteKit, etc. |
|
|
439
|
+
| **Claude Skills** | [ ] **TODO** | See SKILLS.md |
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
## Supported Frameworks & Patterns
|
|
444
|
+
|
|
445
|
+
### Static Sites
|
|
446
|
+
- **Vite-based**: React, Vue, Svelte, Solid
|
|
447
|
+
- **Next.js**: Static Site Generation (SSG)
|
|
448
|
+
- **Astro**: Static Site Generation
|
|
449
|
+
- **Gatsby**: Static site generator
|
|
450
|
+
- **Other**: Any framework outputting to a directory
|
|
451
|
+
|
|
452
|
+
### Serverless
|
|
453
|
+
- **Node.js**: Lambda functions
|
|
454
|
+
- **Bun**: Via Lambda Layer
|
|
455
|
+
- **Containers**: Container-based Lambda
|
|
456
|
+
- **Runtimes**: Node.js 18.x, 20.x
|
|
457
|
+
|
|
458
|
+
### Containers
|
|
459
|
+
- **ECS Fargate**: Serverless containers with ALB
|
|
460
|
+
- **EC2 Docker**: Single-container on EC2
|
|
461
|
+
- **Architectures**: ARM64, X86_64
|
|
462
|
+
- **Orchestration**: Supports docker-compose (Template)
|
|
463
|
+
|
|
464
|
+
### Full-Stack SSR
|
|
465
|
+
- **Nuxt.js**: Universal Vue applications
|
|
466
|
+
- **Astro**: Content-focused websites with SSR
|
|
467
|
+
- **Extensible**: TanStack Start, SvelteKit, AnalogJS (planned)
|
|
468
|
+
|
|
469
|
+
---
|
|
470
|
+
|
|
471
|
+
## Key Design Principles
|
|
472
|
+
|
|
473
|
+
1. **One-Line Deployment**: Minimal configuration for common patterns
|
|
474
|
+
2. **Convention over Configuration**: Sensible defaults, customization when needed
|
|
475
|
+
3. **Framework Agnostic**: Works with any framework, optimized for popular ones
|
|
476
|
+
4. **Production Ready**: Security, monitoring, CI/CD included
|
|
477
|
+
5. **Cost Optimized**: Uses most cost-effective AWS services for each pattern
|
|
478
|
+
6. **Developer Experience**: Fast feedback loops, clear errors, helpful defaults
|
|
479
|
+
7. **Composable**: Stacks can be combined for complex architectures
|
|
480
|
+
|
|
481
|
+
---
|
|
482
|
+
|
|
483
|
+
## Quick Start
|
|
484
|
+
|
|
485
|
+
### Installation
|
|
486
|
+
```bash
|
|
487
|
+
bun add @thunder-so/thunder -d
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
### Basic Usage
|
|
491
|
+
```typescript
|
|
492
|
+
// stack/dev.ts
|
|
493
|
+
import { Cdk, Static, type StaticProps } from '@thunder-so/thunder';
|
|
494
|
+
|
|
495
|
+
const myApp: StaticProps = {
|
|
496
|
+
env: {
|
|
497
|
+
account: '123456789012',
|
|
498
|
+
region: 'us-east-1'
|
|
499
|
+
},
|
|
500
|
+
application: 'myapp',
|
|
501
|
+
service: 'web',
|
|
502
|
+
environment: 'prod',
|
|
503
|
+
rootDir: '.',
|
|
504
|
+
outputDir: 'dist',
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
new Static(
|
|
508
|
+
new Cdk.App(),
|
|
509
|
+
`${myApp.application}-${myApp.service}-${myApp.environment}-stack`,
|
|
510
|
+
myApp
|
|
511
|
+
);
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
### Deployment
|
|
515
|
+
```bash
|
|
516
|
+
npx cdk deploy --app "npx tsx stack/dev.ts" --profile default
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
---
|
|
520
|
+
|
|
521
|
+
## Documentation
|
|
522
|
+
|
|
523
|
+
- **This PRD**: Project overview and architecture
|
|
524
|
+
- **CLI.md**: CLI command reference and scope
|
|
525
|
+
- **SKILLS.md**: Claude Code skills implementation plan
|
|
526
|
+
- **METADATA.md**: Discovery/metadata mechanism details
|
|
527
|
+
|
|
528
|
+
---
|
|
529
|
+
|
|
530
|
+
## License
|
|
531
|
+
|
|
532
|
+
Apache-2.0
|
|
533
|
+
|
|
534
|
+
---
|
|
535
|
+
|
|
536
|
+
**Last Updated**: 2026-03-08
|
|
537
|
+
**Status**: Production-ready stacks, CLI implementation in progress
|