@friggframework/devtools 2.0.0-next.4 → 2.0.0-next.40

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.
Files changed (197) hide show
  1. package/frigg-cli/.eslintrc.js +141 -0
  2. package/frigg-cli/__tests__/jest.config.js +102 -0
  3. package/frigg-cli/__tests__/unit/commands/build.test.js +483 -0
  4. package/frigg-cli/__tests__/unit/commands/install.test.js +418 -0
  5. package/frigg-cli/__tests__/unit/commands/ui.test.js +592 -0
  6. package/frigg-cli/__tests__/utils/command-tester.js +170 -0
  7. package/frigg-cli/__tests__/utils/mock-factory.js +270 -0
  8. package/frigg-cli/__tests__/utils/test-fixtures.js +463 -0
  9. package/frigg-cli/__tests__/utils/test-setup.js +286 -0
  10. package/frigg-cli/build-command/index.js +54 -0
  11. package/frigg-cli/deploy-command/index.js +175 -0
  12. package/frigg-cli/generate-command/__tests__/generate-command.test.js +312 -0
  13. package/frigg-cli/generate-command/azure-generator.js +43 -0
  14. package/frigg-cli/generate-command/gcp-generator.js +47 -0
  15. package/frigg-cli/generate-command/index.js +332 -0
  16. package/frigg-cli/generate-command/terraform-generator.js +555 -0
  17. package/frigg-cli/generate-iam-command.js +115 -0
  18. package/frigg-cli/index.js +47 -1
  19. package/frigg-cli/index.test.js +1 -4
  20. package/frigg-cli/init-command/backend-first-handler.js +756 -0
  21. package/frigg-cli/init-command/index.js +93 -0
  22. package/frigg-cli/init-command/template-handler.js +143 -0
  23. package/frigg-cli/install-command/index.js +1 -4
  24. package/frigg-cli/package.json +51 -0
  25. package/frigg-cli/start-command/index.js +24 -4
  26. package/frigg-cli/test/init-command.test.js +180 -0
  27. package/frigg-cli/test/npm-registry.test.js +319 -0
  28. package/frigg-cli/ui-command/index.js +154 -0
  29. package/frigg-cli/utils/app-resolver.js +319 -0
  30. package/frigg-cli/utils/backend-path.js +16 -17
  31. package/frigg-cli/utils/npm-registry.js +167 -0
  32. package/frigg-cli/utils/process-manager.js +199 -0
  33. package/frigg-cli/utils/repo-detection.js +405 -0
  34. package/infrastructure/DEPLOYMENT-INSTRUCTIONS.md +268 -0
  35. package/infrastructure/GENERATE-IAM-DOCS.md +278 -0
  36. package/infrastructure/IAM-POLICY-TEMPLATES.md +176 -0
  37. package/infrastructure/README.md +443 -0
  38. package/infrastructure/WEBSOCKET-CONFIGURATION.md +105 -0
  39. package/infrastructure/__tests__/fixtures/mock-aws-resources.js +391 -0
  40. package/infrastructure/__tests__/helpers/test-utils.js +277 -0
  41. package/infrastructure/aws-discovery.js +1176 -0
  42. package/infrastructure/aws-discovery.test.js +1220 -0
  43. package/infrastructure/build-time-discovery.js +206 -0
  44. package/infrastructure/build-time-discovery.test.js +378 -0
  45. package/infrastructure/create-frigg-infrastructure.js +3 -5
  46. package/infrastructure/env-validator.js +77 -0
  47. package/infrastructure/frigg-deployment-iam-stack.yaml +401 -0
  48. package/infrastructure/iam-generator.js +836 -0
  49. package/infrastructure/iam-generator.test.js +172 -0
  50. package/infrastructure/iam-policy-basic.json +218 -0
  51. package/infrastructure/iam-policy-full.json +288 -0
  52. package/infrastructure/integration.test.js +383 -0
  53. package/infrastructure/run-discovery.js +110 -0
  54. package/infrastructure/serverless-template.js +1472 -138
  55. package/infrastructure/serverless-template.test.js +1759 -0
  56. package/management-ui/.eslintrc.js +22 -0
  57. package/management-ui/README.md +203 -0
  58. package/management-ui/components.json +21 -0
  59. package/management-ui/docs/phase2-integration-guide.md +320 -0
  60. package/management-ui/index.html +13 -0
  61. package/management-ui/package-lock.json +16517 -0
  62. package/management-ui/package.json +76 -0
  63. package/management-ui/packages/devtools/frigg-cli/ui-command/index.js +302 -0
  64. package/management-ui/postcss.config.js +6 -0
  65. package/management-ui/server/api/backend.js +256 -0
  66. package/management-ui/server/api/cli.js +315 -0
  67. package/management-ui/server/api/codegen.js +663 -0
  68. package/management-ui/server/api/connections.js +857 -0
  69. package/management-ui/server/api/discovery.js +185 -0
  70. package/management-ui/server/api/environment/index.js +1 -0
  71. package/management-ui/server/api/environment/router.js +378 -0
  72. package/management-ui/server/api/environment.js +328 -0
  73. package/management-ui/server/api/integrations.js +876 -0
  74. package/management-ui/server/api/logs.js +248 -0
  75. package/management-ui/server/api/monitoring.js +282 -0
  76. package/management-ui/server/api/open-ide.js +31 -0
  77. package/management-ui/server/api/project.js +1029 -0
  78. package/management-ui/server/api/users/sessions.js +371 -0
  79. package/management-ui/server/api/users/simulation.js +254 -0
  80. package/management-ui/server/api/users.js +362 -0
  81. package/management-ui/server/api-contract.md +275 -0
  82. package/management-ui/server/index.js +873 -0
  83. package/management-ui/server/middleware/errorHandler.js +93 -0
  84. package/management-ui/server/middleware/security.js +32 -0
  85. package/management-ui/server/processManager.js +296 -0
  86. package/management-ui/server/server.js +346 -0
  87. package/management-ui/server/services/aws-monitor.js +413 -0
  88. package/management-ui/server/services/npm-registry.js +347 -0
  89. package/management-ui/server/services/template-engine.js +538 -0
  90. package/management-ui/server/utils/cliIntegration.js +220 -0
  91. package/management-ui/server/utils/environment/auditLogger.js +471 -0
  92. package/management-ui/server/utils/environment/awsParameterStore.js +264 -0
  93. package/management-ui/server/utils/environment/encryption.js +278 -0
  94. package/management-ui/server/utils/environment/envFileManager.js +286 -0
  95. package/management-ui/server/utils/import-commonjs.js +28 -0
  96. package/management-ui/server/utils/response.js +83 -0
  97. package/management-ui/server/websocket/handler.js +325 -0
  98. package/management-ui/src/App.jsx +109 -0
  99. package/management-ui/src/assets/FriggLogo.svg +1 -0
  100. package/management-ui/src/components/AppRouter.jsx +65 -0
  101. package/management-ui/src/components/Button.jsx +70 -0
  102. package/management-ui/src/components/Card.jsx +97 -0
  103. package/management-ui/src/components/EnvironmentCompare.jsx +400 -0
  104. package/management-ui/src/components/EnvironmentEditor.jsx +372 -0
  105. package/management-ui/src/components/EnvironmentImportExport.jsx +469 -0
  106. package/management-ui/src/components/EnvironmentSchema.jsx +491 -0
  107. package/management-ui/src/components/EnvironmentSecurity.jsx +463 -0
  108. package/management-ui/src/components/ErrorBoundary.jsx +73 -0
  109. package/management-ui/src/components/IntegrationCard.jsx +481 -0
  110. package/management-ui/src/components/IntegrationCardEnhanced.jsx +770 -0
  111. package/management-ui/src/components/IntegrationExplorer.jsx +379 -0
  112. package/management-ui/src/components/IntegrationStatus.jsx +336 -0
  113. package/management-ui/src/components/Layout.jsx +716 -0
  114. package/management-ui/src/components/LoadingSpinner.jsx +113 -0
  115. package/management-ui/src/components/RepositoryPicker.jsx +248 -0
  116. package/management-ui/src/components/SessionMonitor.jsx +350 -0
  117. package/management-ui/src/components/StatusBadge.jsx +208 -0
  118. package/management-ui/src/components/UserContextSwitcher.jsx +212 -0
  119. package/management-ui/src/components/UserSimulation.jsx +327 -0
  120. package/management-ui/src/components/Welcome.jsx +434 -0
  121. package/management-ui/src/components/codegen/APIEndpointGenerator.jsx +637 -0
  122. package/management-ui/src/components/codegen/APIModuleSelector.jsx +227 -0
  123. package/management-ui/src/components/codegen/CodeGenerationWizard.jsx +247 -0
  124. package/management-ui/src/components/codegen/CodePreviewEditor.jsx +316 -0
  125. package/management-ui/src/components/codegen/DynamicModuleForm.jsx +271 -0
  126. package/management-ui/src/components/codegen/FormBuilder.jsx +737 -0
  127. package/management-ui/src/components/codegen/IntegrationGenerator.jsx +855 -0
  128. package/management-ui/src/components/codegen/ProjectScaffoldWizard.jsx +797 -0
  129. package/management-ui/src/components/codegen/SchemaBuilder.jsx +303 -0
  130. package/management-ui/src/components/codegen/TemplateSelector.jsx +586 -0
  131. package/management-ui/src/components/codegen/index.js +10 -0
  132. package/management-ui/src/components/connections/ConnectionConfigForm.jsx +362 -0
  133. package/management-ui/src/components/connections/ConnectionHealthMonitor.jsx +182 -0
  134. package/management-ui/src/components/connections/ConnectionTester.jsx +200 -0
  135. package/management-ui/src/components/connections/EntityRelationshipMapper.jsx +292 -0
  136. package/management-ui/src/components/connections/OAuthFlow.jsx +204 -0
  137. package/management-ui/src/components/connections/index.js +5 -0
  138. package/management-ui/src/components/index.js +21 -0
  139. package/management-ui/src/components/monitoring/APIGatewayMetrics.jsx +222 -0
  140. package/management-ui/src/components/monitoring/LambdaMetrics.jsx +169 -0
  141. package/management-ui/src/components/monitoring/MetricsChart.jsx +197 -0
  142. package/management-ui/src/components/monitoring/MonitoringDashboard.jsx +393 -0
  143. package/management-ui/src/components/monitoring/SQSMetrics.jsx +246 -0
  144. package/management-ui/src/components/monitoring/index.js +6 -0
  145. package/management-ui/src/components/monitoring/monitoring.css +218 -0
  146. package/management-ui/src/components/theme-provider.jsx +52 -0
  147. package/management-ui/src/components/theme-toggle.jsx +39 -0
  148. package/management-ui/src/components/ui/badge.tsx +36 -0
  149. package/management-ui/src/components/ui/button.test.jsx +56 -0
  150. package/management-ui/src/components/ui/button.tsx +57 -0
  151. package/management-ui/src/components/ui/card.tsx +76 -0
  152. package/management-ui/src/components/ui/dropdown-menu.tsx +199 -0
  153. package/management-ui/src/components/ui/select.tsx +157 -0
  154. package/management-ui/src/components/ui/skeleton.jsx +15 -0
  155. package/management-ui/src/hooks/useFrigg.jsx +601 -0
  156. package/management-ui/src/hooks/useSocket.jsx +58 -0
  157. package/management-ui/src/index.css +193 -0
  158. package/management-ui/src/lib/utils.ts +6 -0
  159. package/management-ui/src/main.jsx +10 -0
  160. package/management-ui/src/pages/CodeGeneration.jsx +14 -0
  161. package/management-ui/src/pages/Connections.jsx +252 -0
  162. package/management-ui/src/pages/ConnectionsEnhanced.jsx +633 -0
  163. package/management-ui/src/pages/Dashboard.jsx +311 -0
  164. package/management-ui/src/pages/Environment.jsx +314 -0
  165. package/management-ui/src/pages/IntegrationConfigure.jsx +669 -0
  166. package/management-ui/src/pages/IntegrationDiscovery.jsx +567 -0
  167. package/management-ui/src/pages/IntegrationTest.jsx +742 -0
  168. package/management-ui/src/pages/Integrations.jsx +253 -0
  169. package/management-ui/src/pages/Monitoring.jsx +17 -0
  170. package/management-ui/src/pages/Simulation.jsx +155 -0
  171. package/management-ui/src/pages/Users.jsx +492 -0
  172. package/management-ui/src/services/api.js +41 -0
  173. package/management-ui/src/services/apiModuleService.js +193 -0
  174. package/management-ui/src/services/websocket-handlers.js +120 -0
  175. package/management-ui/src/test/api/project.test.js +273 -0
  176. package/management-ui/src/test/components/Welcome.test.jsx +378 -0
  177. package/management-ui/src/test/mocks/server.js +178 -0
  178. package/management-ui/src/test/setup.js +61 -0
  179. package/management-ui/src/test/utils/test-utils.jsx +134 -0
  180. package/management-ui/src/utils/repository.js +98 -0
  181. package/management-ui/src/utils/repository.test.js +118 -0
  182. package/management-ui/src/workflows/phase2-integration-workflows.js +884 -0
  183. package/management-ui/tailwind.config.js +63 -0
  184. package/management-ui/tsconfig.json +37 -0
  185. package/management-ui/tsconfig.node.json +10 -0
  186. package/management-ui/vite.config.js +26 -0
  187. package/management-ui/vitest.config.js +38 -0
  188. package/package.json +20 -9
  189. package/infrastructure/app-handler-helpers.js +0 -57
  190. package/infrastructure/backend-utils.js +0 -90
  191. package/infrastructure/routers/auth.js +0 -26
  192. package/infrastructure/routers/integration-defined-routers.js +0 -37
  193. package/infrastructure/routers/middleware/loadUser.js +0 -15
  194. package/infrastructure/routers/middleware/requireLoggedInUser.js +0 -12
  195. package/infrastructure/routers/user.js +0 -41
  196. package/infrastructure/routers/websocket.js +0 -55
  197. package/infrastructure/workers/integration-defined-workers.js +0 -24
@@ -0,0 +1,176 @@
1
+ # Frigg IAM Policy Templates
2
+
3
+ This directory contains IAM policy templates for deploying Frigg applications with the appropriate permissions.
4
+
5
+ ## Quick Start
6
+
7
+ For immediate deployment, you have two ready-to-use IAM policy options:
8
+
9
+ ### Option 1: Basic Policy (Recommended for getting started)
10
+ ```bash
11
+ # Use the basic policy for core Frigg functionality
12
+ aws iam put-user-policy \
13
+ --user-name frigg-deployment-user \
14
+ --policy-name FriggBasicDeploymentPolicy \
15
+ --policy-document file://iam-policy-basic.json
16
+ ```
17
+
18
+ **Includes permissions for:**
19
+ - ✅ AWS Discovery (finding your VPC, subnets, security groups)
20
+ - ✅ CloudFormation stacks (deploy/update Frigg applications)
21
+ - ✅ Lambda functions (create and manage serverless functions)
22
+ - ✅ Lambda EventSourceMappings (connect Lambda to SQS, SNS, Kinesis)
23
+ - ✅ API Gateway (HTTP endpoints for your integrations)
24
+ - ✅ SQS/SNS (message queues and notifications)
25
+ - ✅ S3 (deployment artifacts, including bucket tagging)
26
+ - ✅ CloudWatch/Logs (monitoring and logging)
27
+ - ✅ IAM roles (Lambda execution roles)
28
+
29
+ ### Option 2: Full Policy (All features enabled)
30
+ ```bash
31
+ # Use the full policy for advanced Frigg features
32
+ aws iam put-user-policy \
33
+ --user-name frigg-deployment-user \
34
+ --policy-name FriggFullDeploymentPolicy \
35
+ --policy-document file://iam-policy-full.json
36
+ ```
37
+
38
+ **Includes everything from Basic Policy PLUS:**
39
+ - ✅ **VPC Management** - Create route tables, NAT gateways, VPC endpoints
40
+ - ✅ **KMS Encryption** - Field-level encryption for sensitive data
41
+ - ✅ **SSM Parameter Store** - Secure configuration management
42
+
43
+ ## When to Use Which Policy
44
+
45
+ ### Use Basic Policy When:
46
+ - Getting started with Frigg
47
+ - Building simple integrations without VPC requirements
48
+ - You want minimal AWS permissions
49
+ - You're not handling sensitive data requiring encryption
50
+
51
+ ### Use Full Policy When:
52
+ - You need VPC isolation for security/compliance
53
+ - You're handling sensitive data requiring KMS encryption
54
+ - You want to use SSM Parameter Store for configuration
55
+ - You're deploying production applications
56
+
57
+ ## Current Issue Resolution
58
+
59
+ **If you're seeing the error:** `User is not authorized to perform: ec2:CreateRouteTable`
60
+
61
+ This means your current deployment user doesn't have VPC permissions. You have two options:
62
+
63
+ ### Quick Fix: Apply Full Policy
64
+ ```bash
65
+ aws iam put-user-policy \
66
+ --user-name frigg-deployment-user \
67
+ --policy-name FriggFullDeploymentPolicy \
68
+ --policy-document file://iam-policy-full.json
69
+ ```
70
+
71
+ ### Alternative: Update CloudFormation Stack
72
+ If you deployed using the CloudFormation template, update it with VPC support:
73
+ ```bash
74
+ aws cloudformation update-stack \
75
+ --stack-name frigg-deployment-iam \
76
+ --template-body file://frigg-deployment-iam-stack.yaml \
77
+ --parameters ParameterKey=EnableVPCSupport,ParameterValue=true \
78
+ --capabilities CAPABILITY_IAM
79
+ ```
80
+
81
+ ## Using the IAM Generator
82
+
83
+ For custom policy generation based on your app definition:
84
+
85
+ ```javascript
86
+ const { generateIAMPolicy, generateIAMCloudFormation } = require('./iam-generator');
87
+
88
+ // Generate basic JSON policy
89
+ const basicPolicy = generateIAMPolicy('basic');
90
+
91
+ // Generate full JSON policy
92
+ const fullPolicy = generateIAMPolicy('full');
93
+
94
+ // Generate CloudFormation template with auto-detection
95
+ const autoTemplate = generateIAMCloudFormation(appDefinition, { mode: 'auto' });
96
+
97
+ // Generate CloudFormation template with specific mode
98
+ const basicTemplate = generateIAMCloudFormation(appDefinition, { mode: 'basic' });
99
+ const fullTemplate = generateIAMCloudFormation(appDefinition, { mode: 'full' });
100
+ ```
101
+
102
+ ### Generator Modes
103
+
104
+ - **`basic`** - Core permissions only, ignores app definition features
105
+ - **`full`** - All features enabled, ignores app definition features
106
+ - **`auto`** - Analyzes app definition and enables features as needed (default)
107
+
108
+ ## Security Best Practices
109
+
110
+ ### Resource Scoping
111
+ Both policies are scoped to resources containing "frigg" in their names:
112
+ - ✅ `my-frigg-app-prod` (will work)
113
+ - ❌ `my-integration-app` (won't work - missing "frigg")
114
+
115
+ ### Account-Specific Resources
116
+ Replace `*` with your AWS account ID for tighter security:
117
+ ```json
118
+ {
119
+ "Resource": [
120
+ "arn:aws:lambda:us-east-1:123456789012:function:*frigg*"
121
+ ]
122
+ }
123
+ ```
124
+
125
+ ### Environment-Specific Policies
126
+ Consider separate policies for different environments:
127
+ - `frigg-dev-policy` (full permissions for development)
128
+ - `frigg-prod-policy` (restricted permissions for production)
129
+
130
+ ## Troubleshooting
131
+
132
+ ### Common Permission Errors
133
+
134
+ 1. **"ec2:CreateRouteTable" error** → Use Full Policy
135
+ 2. **"kms:GenerateDataKey" error** → Enable KMS in your policy
136
+ 3. **"ssm:GetParameter" error** → Enable SSM in your policy
137
+ 4. **Lambda VPC errors** → Ensure VPC permissions are enabled
138
+ 5. **"lambda:DeleteEventSourceMapping" error** → Update to latest policy (includes EventSourceMapping permissions)
139
+ 6. **"ec2:DeleteVpcEndpoints" error** → Update IAM policy to use `ec2:DeleteVpcEndpoints` (plural) instead of `ec2:DeleteVpcEndpoint`
140
+ 7. **"s3:PutBucketTagging" error** → Update to latest policy (includes S3 bucket tagging permissions)
141
+
142
+ ### Validation
143
+ Test your policy by deploying a simple Frigg app:
144
+ ```bash
145
+ npx create-frigg-app test-deployment
146
+ cd test-deployment
147
+ frigg deploy
148
+ ```
149
+
150
+ ### Policy Comparison
151
+
152
+ | Feature | Basic Policy | Full Policy | CloudFormation Template |
153
+ |---------|--------------|-------------|-------------------------|
154
+ | Core Deployment | ✅ | ✅ | ✅ |
155
+ | VPC Management | ❌ | ✅ | ✅ (conditional) |
156
+ | KMS Encryption | ❌ | ✅ | ✅ (conditional) |
157
+ | SSM Parameters | ❌ | ✅ | ✅ (conditional) |
158
+ | Format | JSON | JSON | YAML with parameters |
159
+ | Use Case | Getting started | Production ready | Infrastructure as Code |
160
+
161
+ ## Files in this Directory
162
+
163
+ - `iam-policy-basic.json` - Core Frigg permissions only (JSON format)
164
+ - `iam-policy-full.json` - All features enabled (JSON format)
165
+ - `frigg-deployment-iam-stack.yaml` - CloudFormation template with conditional parameters
166
+ - `iam-generator.js` - Programmatic policy generation with basic/full/auto modes
167
+ - `AWS-IAM-CREDENTIAL-NEEDS.md` - Detailed permission explanations and troubleshooting
168
+ - `IAM-POLICY-TEMPLATES.md` - This file - Quick start guide and usage examples
169
+
170
+ ## Support
171
+
172
+ If you encounter permission issues:
173
+ 1. Check the error message for the specific missing permission
174
+ 2. Verify your resource names contain "frigg"
175
+ 3. Consider upgrading from Basic to Full policy
176
+ 4. Review the AWS-IAM-CREDENTIAL-NEEDS.md for detailed explanations
@@ -0,0 +1,443 @@
1
+ # Frigg Infrastructure
2
+
3
+ This directory contains the infrastructure-as-code templates and utilities for deploying Frigg applications to AWS.
4
+
5
+ ## Quick Start
6
+
7
+ ```bash
8
+ # Install dependencies
9
+ npm install
10
+
11
+ # Run infrastructure tests
12
+ npm test
13
+
14
+ # Deploy basic infrastructure
15
+ frigg deploy --stage production
16
+
17
+ # Deploy with Phase 3 features
18
+ frigg deploy --stage production --enable-phase3
19
+ ```
20
+
21
+ ## Directory Structure
22
+
23
+ ```
24
+ infrastructure/
25
+ ├── README.md # This file
26
+ ├── PHASE3-DEPLOYMENT-GUIDE.md # Phase 3 deployment guide
27
+ ├── AWS-DISCOVERY-TROUBLESHOOTING.md # AWS discovery troubleshooting
28
+ ├── DEPLOYMENT-INSTRUCTIONS.md # General deployment instructions
29
+ ├── README-TESTING.md # Testing strategy documentation
30
+ ├──
31
+ ├── cloudformation/ # CloudFormation templates
32
+ │ ├── monitoring-infrastructure.yaml # Enhanced monitoring (Phase 3)
33
+ │ ├── cdn-infrastructure.yaml # CDN and UI distribution (Phase 3)
34
+ │ ├── codegen-infrastructure.yaml # Code generation services (Phase 3)
35
+ │ ├── alerting-infrastructure.yaml # Advanced alerting (Phase 3)
36
+ │ └── deployment-pipeline.yaml # CI/CD pipeline (Phase 3)
37
+ ├──
38
+ ├── aws-discovery.js # AWS resource discovery utility
39
+ ├── build-time-discovery.js # Build-time discovery integration
40
+ ├── serverless-template.js # Serverless configuration generator
41
+ ├── iam-generator.js # IAM policy generator
42
+ ├── create-frigg-infrastructure.js # Infrastructure creation utility
43
+ ├── run-discovery.js # Discovery runner script
44
+ ├──
45
+ ├── __tests__/ # Test files
46
+ │ ├── fixtures/ # Test fixtures and mock data
47
+ │ └── helpers/ # Test helper utilities
48
+ ├── aws-discovery.test.js # AWS discovery tests
49
+ ├── build-time-discovery.test.js # Build-time discovery tests
50
+ ├── serverless-template.test.js # Serverless template tests
51
+ ├── iam-generator.test.js # IAM generator tests
52
+ ├── integration.test.js # End-to-end integration tests
53
+ └── ... # Additional test files
54
+ ```
55
+
56
+ ## Infrastructure Components
57
+
58
+ ### Core Infrastructure (Phase 1-2)
59
+
60
+ #### 1. Serverless Template Generator (`serverless-template.js`)
61
+
62
+ Generates complete serverless.yml configurations with:
63
+
64
+ - VPC configuration and resource discovery (with optional self-healing)
65
+ - NAT/EIP management strategies (`discover`, `createAndManage`, `useExisting`)
66
+ - KMS encryption for field-level encryption
67
+ - SSM Parameter Store integration
68
+ - Integration-specific functions and queues
69
+ - WebSocket support for real-time features
70
+
71
+ #### 2. AWS Discovery (`aws-discovery.js`)
72
+
73
+ Automatically discovers existing AWS resources and highlights misconfigurations:
74
+
75
+ - Default VPC and security groups
76
+ - Private subnets for Lambda functions (with routing validation)
77
+ - Customer-managed KMS keys
78
+ - Route tables for VPC endpoints
79
+ - NAT gateways / Elastic IPs and whether remediation is required
80
+
81
+ #### 3. Build-Time Discovery (`build-time-discovery.js`)
82
+
83
+ Integrates AWS discovery into the build process:
84
+
85
+ - Pre-build hook for serverless deployments
86
+ - Environment variable injection
87
+ - Template variable replacement
88
+ - Error handling and fallback values
89
+
90
+ ### Phase 3 Infrastructure
91
+
92
+ #### 1. Enhanced Monitoring (`cloudformation/monitoring-infrastructure.yaml`)
93
+
94
+ Production-ready monitoring with:
95
+
96
+ - Code generation service monitoring
97
+ - UI distribution monitoring
98
+ - Advanced CloudWatch dashboards
99
+ - Custom metrics and alarms
100
+
101
+ #### 2. CDN Infrastructure (`cloudformation/cdn-infrastructure.yaml`)
102
+
103
+ CloudFront distribution for UI packages:
104
+
105
+ - S3 bucket for multi-framework UI packages
106
+ - CloudFront distribution with custom domains
107
+ - Lambda function for package deployment
108
+ - API Gateway for package management
109
+
110
+ #### 3. Code Generation Infrastructure (`cloudformation/codegen-infrastructure.yaml`)
111
+
112
+ Serverless code generation platform:
113
+
114
+ - SQS queue for generation requests
115
+ - Lambda function with AI/ML integration
116
+ - DynamoDB tracking table
117
+ - S3 storage for templates and generated code
118
+ - ElastiCache for template caching
119
+
120
+ #### 4. Advanced Alerting (`cloudformation/alerting-infrastructure.yaml`)
121
+
122
+ Multi-channel alerting system:
123
+
124
+ - Multiple SNS topics for alert severity levels
125
+ - Lambda function for alert processing
126
+ - PagerDuty and Slack integration
127
+ - Composite alarms for system health
128
+ - Advanced metrics collection
129
+
130
+ #### 5. Deployment Pipeline (`cloudformation/deployment-pipeline.yaml`)
131
+
132
+ CI/CD pipeline for automated deployments:
133
+
134
+ - CodePipeline with GitHub integration
135
+ - CodeBuild projects for backend and UI
136
+ - Multi-stage deployment workflow
137
+ - Integration testing and approval gates
138
+
139
+ ## Configuration Options
140
+
141
+ ### App Definition Structure
142
+
143
+ ```javascript
144
+ const appDefinition = {
145
+ // Basic configuration
146
+ name: 'my-frigg-app',
147
+ provider: 'aws',
148
+
149
+ // VPC configuration
150
+ vpc: {
151
+ enable: true,
152
+ management: 'discover', // 'discover' | 'create-new' | 'use-existing'
153
+ selfHeal: true, // Let the template repair routing/NAT issues
154
+ securityGroupIds: [...], // Optional: custom security groups or CFN Refs
155
+ subnets: {
156
+ management: 'discover', // 'discover' | 'create' | 'use-existing'
157
+ ids: [...], // Required when management is 'use-existing'
158
+ },
159
+ natGateway: {
160
+ management: 'discover', // 'discover' | 'createAndManage' | 'useExisting'
161
+ id: 'nat-xxxxxxxx', // Required when management is 'useExisting'
162
+ },
163
+ enableVPCEndpoints: true // Optional: create VPC endpoints
164
+ },
165
+
166
+ // KMS encryption
167
+ encryption: {
168
+ fieldLevelEncryptionMethod: 'kms',
169
+ createResourceIfNoneFound: true
170
+ },
171
+
172
+ // SSM Parameter Store
173
+ ssm: {
174
+ enable: true
175
+ },
176
+
177
+ // WebSocket support (optional)
178
+ websockets: {
179
+ enable: true
180
+ },
181
+
182
+ // Integrations
183
+ integrations: [
184
+ { Definition: { name: 'hubspot' } },
185
+ { Definition: { name: 'salesforce' } }
186
+ ]
187
+ };
188
+ ```
189
+
190
+ ### Environment Variables
191
+
192
+ The infrastructure system uses environment variables for AWS resource references:
193
+
194
+ ```bash
195
+ # Automatically set by AWS discovery
196
+ AWS_DISCOVERY_VPC_ID=vpc-12345678
197
+ AWS_DISCOVERY_SECURITY_GROUP_ID=sg-12345678
198
+ AWS_DISCOVERY_SUBNET_ID_1=subnet-12345678
199
+ AWS_DISCOVERY_SUBNET_ID_2=subnet-87654321
200
+ AWS_DISCOVERY_PUBLIC_SUBNET_ID=subnet-abcdef12
201
+ AWS_DISCOVERY_ROUTE_TABLE_ID=rtb-12345678
202
+ AWS_DISCOVERY_KMS_KEY_ID=arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012
203
+
204
+ # Set by serverless framework
205
+ AWS_REGION=us-east-1
206
+ STAGE=production
207
+ SERVICE_NAME=my-frigg-app
208
+ ```
209
+
210
+ ## Usage Examples
211
+
212
+ ### Basic Deployment
213
+
214
+ ```javascript
215
+ const { composeServerlessDefinition } = require('./serverless-template');
216
+
217
+ const appDefinition = {
218
+ name: 'my-app',
219
+ integrations: [{ Definition: { name: 'hubspot' } }],
220
+ };
221
+
222
+ const serverlessConfig = await composeServerlessDefinition(appDefinition);
223
+ // Use serverlessConfig for deployment
224
+ ```
225
+
226
+ ### VPC-Enabled Deployment
227
+
228
+ ```javascript
229
+ const appDefinition = {
230
+ name: 'secure-app',
231
+ vpc: { enable: true },
232
+ encryption: { fieldLevelEncryptionMethod: 'kms' },
233
+ ssm: { enable: true },
234
+ integrations: [{ Definition: { name: 'salesforce' } }],
235
+ };
236
+
237
+ const serverlessConfig = await composeServerlessDefinition(appDefinition);
238
+ ```
239
+
240
+ ### Phase 3 Deployment with WebSockets
241
+
242
+ ```javascript
243
+ const appDefinition = {
244
+ name: 'realtime-app',
245
+ websockets: { enable: true },
246
+ vpc: { enable: true },
247
+ integrations: [{ Definition: { name: 'slack' } }],
248
+ };
249
+
250
+ const serverlessConfig = await composeServerlessDefinition(appDefinition);
251
+ ```
252
+
253
+ ## Testing
254
+
255
+ ### Running Tests
256
+
257
+ ```bash
258
+ # Run all infrastructure tests
259
+ npm test
260
+
261
+ # Run specific test suites
262
+ npm test aws-discovery.test.js
263
+ npm test serverless-template.test.js
264
+ npm test integration.test.js
265
+
266
+ # Run with coverage
267
+ npm test -- --coverage
268
+
269
+ # Run in watch mode
270
+ npm test -- --watch
271
+ ```
272
+
273
+ ### Test Categories
274
+
275
+ 1. **Unit Tests**: Test individual components
276
+
277
+ - AWS discovery utilities
278
+ - Serverless template generation
279
+ - IAM policy generation
280
+
281
+ 2. **Integration Tests**: Test end-to-end workflows
282
+
283
+ - Complete discovery and template generation
284
+ - Plugin integration
285
+ - Phase 3 infrastructure validation
286
+
287
+ 3. **Performance Tests**: Validate infrastructure limits
288
+ - CloudFormation template sizes
289
+ - Resource count limits
290
+ - Cross-stack dependencies
291
+
292
+ ### Mock Data
293
+
294
+ Tests use mock AWS resources to avoid real AWS API calls:
295
+
296
+ ```javascript
297
+ const mockAWSResources = {
298
+ defaultVpcId: 'vpc-12345678',
299
+ defaultSecurityGroupId: 'sg-12345678',
300
+ privateSubnetId1: 'subnet-private-1',
301
+ privateSubnetId2: 'subnet-private-2',
302
+ defaultKmsKeyId:
303
+ 'arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012',
304
+ };
305
+ ```
306
+
307
+ ## Security
308
+
309
+ ### IAM Permissions
310
+
311
+ The infrastructure requires specific IAM permissions for AWS resource discovery and deployment:
312
+
313
+ - **EC2**: Describe VPCs, subnets, security groups, route tables
314
+ - **KMS**: List keys, describe keys
315
+ - **STS**: Get caller identity
316
+ - **CloudFormation**: Full access for stack operations
317
+ - **Lambda**: Function management
318
+ - **API Gateway**: API management
319
+ - **S3**: Bucket and object operations (including tagging)
320
+ - **DynamoDB**: Table operations
321
+ - **SQS**: Queue operations
322
+ - **SNS**: Topic operations
323
+ - **CloudWatch**: Metrics and alarms
324
+ - **IAM**: Role and policy management
325
+
326
+ ### Best Practices
327
+
328
+ 1. **Least Privilege**: IAM roles have minimal required permissions
329
+ 2. **Encryption**: All data encrypted at rest and in transit
330
+ 3. **VPC Security**: Lambda functions in private subnets when needed
331
+ 4. **Access Control**: S3 buckets block public access by default
332
+ 5. **Audit Logging**: CloudTrail integration for API calls
333
+
334
+ ## Troubleshooting
335
+
336
+ ### Common Issues
337
+
338
+ #### AWS Discovery Failures
339
+
340
+ ```bash
341
+ # Check AWS credentials
342
+ aws sts get-caller-identity
343
+
344
+ # Verify region configuration
345
+ echo $AWS_REGION
346
+
347
+ # Test VPC discovery
348
+ node -e "
349
+ const { AWSDiscovery } = require('./aws-discovery');
350
+ const discovery = new AWSDiscovery('us-east-1');
351
+ discovery.findDefaultVpc().then(console.log).catch(console.error);
352
+ "
353
+ ```
354
+
355
+ #### Serverless Deployment Issues
356
+
357
+ ```bash
358
+ # Enable debug logging
359
+ SLS_DEBUG=true serverless deploy
360
+
361
+ # Check generated template
362
+ serverless print
363
+
364
+ # Validate CloudFormation template
365
+ aws cloudformation validate-template --template-body file://template.json
366
+ ```
367
+
368
+ - **Connectivity to external services (e.g., databases):** If your Lambda functions in a VPC cannot connect to external services, ensure that the `FriggLambdaSecurityGroup` has the correct **egress** rules to allow outbound traffic on the required ports (e.g., port 27017 for MongoDB).
369
+
370
+ #### Infrastructure Test Failures
371
+
372
+ ```bash
373
+ # Run specific failing test
374
+ npm test -- --testNamePattern="should discover all AWS resources"
375
+
376
+ # Debug with verbose output
377
+ npm test -- --verbose --silent=false
378
+
379
+ # Check test environment
380
+ npm run test:debug
381
+ ```
382
+
383
+ ### Performance Optimization
384
+
385
+ #### Lambda Cold Starts
386
+
387
+ - Use provisioned concurrency for critical functions
388
+ - Optimize function size and dependencies
389
+ - Monitor cold start metrics
390
+
391
+ #### VPC Performance
392
+
393
+ - Use VPC endpoints to reduce NAT Gateway costs
394
+ - Monitor ENI creation/deletion times
395
+ - Consider Lambda@Edge for global distribution
396
+
397
+ #### Cost Optimization
398
+
399
+ - Use S3 Intelligent Tiering
400
+ - Configure CloudWatch log retention
401
+ - Monitor and alert on unexpected usage
402
+
403
+ ## Contributing
404
+
405
+ ### Adding New Infrastructure Components
406
+
407
+ 1. Create CloudFormation template in `cloudformation/`
408
+ 2. Add validation tests in `__tests__/`
409
+ 3. Update integration tests
410
+ 4. Document in deployment guide
411
+ 5. Add to CI/CD pipeline
412
+
413
+ ### Testing Guidelines
414
+
415
+ 1. Mock all AWS API calls
416
+ 2. Test both success and failure scenarios
417
+ 3. Validate CloudFormation template syntax
418
+ 4. Test cross-stack dependencies
419
+ 5. Include performance and security tests
420
+
421
+ ### Documentation
422
+
423
+ 1. Update this README for new features
424
+ 2. Add examples to deployment guide
425
+ 3. Document troubleshooting steps
426
+ 4. Include security considerations
427
+
428
+ ## Support
429
+
430
+ - **Documentation**: See `PHASE3-DEPLOYMENT-GUIDE.md` for detailed deployment instructions
431
+ - **Testing**: See `README-TESTING.md` for testing strategy
432
+ - **Troubleshooting**: See `AWS-DISCOVERY-TROUBLESHOOTING.md` for common issues
433
+ - **Issues**: Create GitHub issues for bugs and feature requests
434
+ - **Discussions**: Use GitHub Discussions for questions and ideas
435
+
436
+ ## Related Documentation
437
+
438
+ - [Phase 3 Deployment Guide](./PHASE3-DEPLOYMENT-GUIDE.md)
439
+ - [Testing Strategy](./README-TESTING.md)
440
+ - [AWS Discovery Troubleshooting](./AWS-DISCOVERY-TROUBLESHOOTING.md)
441
+ - [IAM Policy Templates](./IAM-POLICY-TEMPLATES.md)
442
+ - [VPC Configuration](./VPC-CONFIGURATION.md)
443
+ - [WebSocket Configuration](./WEBSOCKET-CONFIGURATION.md)