@friggframework/devtools 2.0.0-next.45 → 2.0.0-next.46

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 (212) hide show
  1. package/infrastructure/ARCHITECTURE.md +487 -0
  2. package/infrastructure/HEALTH.md +468 -0
  3. package/infrastructure/README.md +51 -0
  4. package/infrastructure/__tests__/postgres-config.test.js +914 -0
  5. package/infrastructure/__tests__/template-generation.test.js +687 -0
  6. package/infrastructure/create-frigg-infrastructure.js +1 -1
  7. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +630 -0
  8. package/infrastructure/{DEPLOYMENT-INSTRUCTIONS.md → docs/deployment-instructions.md} +3 -3
  9. package/infrastructure/{IAM-POLICY-TEMPLATES.md → docs/iam-policy-templates.md} +9 -10
  10. package/infrastructure/domains/database/aurora-builder.js +809 -0
  11. package/infrastructure/domains/database/aurora-builder.test.js +950 -0
  12. package/infrastructure/domains/database/aurora-discovery.js +87 -0
  13. package/infrastructure/domains/database/aurora-discovery.test.js +188 -0
  14. package/infrastructure/domains/database/aurora-resolver.js +210 -0
  15. package/infrastructure/domains/database/aurora-resolver.test.js +347 -0
  16. package/infrastructure/domains/database/migration-builder.js +633 -0
  17. package/infrastructure/domains/database/migration-builder.test.js +294 -0
  18. package/infrastructure/domains/database/migration-resolver.js +163 -0
  19. package/infrastructure/domains/database/migration-resolver.test.js +337 -0
  20. package/infrastructure/domains/health/application/ports/IPropertyReconciler.js +164 -0
  21. package/infrastructure/domains/health/application/ports/IResourceDetector.js +129 -0
  22. package/infrastructure/domains/health/application/ports/IResourceImporter.js +142 -0
  23. package/infrastructure/domains/health/application/ports/IStackRepository.js +131 -0
  24. package/infrastructure/domains/health/application/ports/index.js +26 -0
  25. package/infrastructure/domains/health/application/use-cases/__tests__/execute-resource-import-use-case.test.js +679 -0
  26. package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +167 -0
  27. package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +1130 -0
  28. package/infrastructure/domains/health/application/use-cases/execute-resource-import-use-case.js +221 -0
  29. package/infrastructure/domains/health/application/use-cases/reconcile-properties-use-case.js +152 -0
  30. package/infrastructure/domains/health/application/use-cases/reconcile-properties-use-case.test.js +343 -0
  31. package/infrastructure/domains/health/application/use-cases/repair-via-import-use-case.js +535 -0
  32. package/infrastructure/domains/health/application/use-cases/repair-via-import-use-case.test.js +376 -0
  33. package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.js +213 -0
  34. package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +441 -0
  35. package/infrastructure/domains/health/docs/ACME-DEV-DRIFT-ANALYSIS.md +267 -0
  36. package/infrastructure/domains/health/docs/BUILD-VS-DEPLOYED-TEMPLATE-ANALYSIS.md +324 -0
  37. package/infrastructure/domains/health/docs/ORPHAN-DETECTION-ANALYSIS.md +386 -0
  38. package/infrastructure/domains/health/docs/SPEC-CLEANUP-COMMAND.md +1419 -0
  39. package/infrastructure/domains/health/docs/TDD-IMPLEMENTATION-SUMMARY.md +391 -0
  40. package/infrastructure/domains/health/docs/TEMPLATE-COMPARISON-IMPLEMENTATION.md +551 -0
  41. package/infrastructure/domains/health/domain/entities/issue.js +299 -0
  42. package/infrastructure/domains/health/domain/entities/issue.test.js +528 -0
  43. package/infrastructure/domains/health/domain/entities/property-mismatch.js +108 -0
  44. package/infrastructure/domains/health/domain/entities/property-mismatch.test.js +275 -0
  45. package/infrastructure/domains/health/domain/entities/resource.js +159 -0
  46. package/infrastructure/domains/health/domain/entities/resource.test.js +432 -0
  47. package/infrastructure/domains/health/domain/entities/stack-health-report.js +306 -0
  48. package/infrastructure/domains/health/domain/entities/stack-health-report.test.js +601 -0
  49. package/infrastructure/domains/health/domain/services/__tests__/health-score-percentage-based.test.js +380 -0
  50. package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +971 -0
  51. package/infrastructure/domains/health/domain/services/__tests__/import-template-generator.test.js +1150 -0
  52. package/infrastructure/domains/health/domain/services/__tests__/logical-id-mapper.test.js +672 -0
  53. package/infrastructure/domains/health/domain/services/__tests__/template-parser.test.js +496 -0
  54. package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +419 -0
  55. package/infrastructure/domains/health/domain/services/health-score-calculator.js +248 -0
  56. package/infrastructure/domains/health/domain/services/health-score-calculator.test.js +504 -0
  57. package/infrastructure/domains/health/domain/services/import-progress-monitor.js +195 -0
  58. package/infrastructure/domains/health/domain/services/import-template-generator.js +435 -0
  59. package/infrastructure/domains/health/domain/services/logical-id-mapper.js +345 -0
  60. package/infrastructure/domains/health/domain/services/mismatch-analyzer.js +234 -0
  61. package/infrastructure/domains/health/domain/services/mismatch-analyzer.test.js +431 -0
  62. package/infrastructure/domains/health/domain/services/property-mutability-config.js +382 -0
  63. package/infrastructure/domains/health/domain/services/template-parser.js +245 -0
  64. package/infrastructure/domains/health/domain/services/update-progress-monitor.js +192 -0
  65. package/infrastructure/domains/health/domain/value-objects/health-score.js +138 -0
  66. package/infrastructure/domains/health/domain/value-objects/health-score.test.js +267 -0
  67. package/infrastructure/domains/health/domain/value-objects/property-mutability.js +161 -0
  68. package/infrastructure/domains/health/domain/value-objects/property-mutability.test.js +198 -0
  69. package/infrastructure/domains/health/domain/value-objects/resource-state.js +167 -0
  70. package/infrastructure/domains/health/domain/value-objects/resource-state.test.js +196 -0
  71. package/infrastructure/domains/health/domain/value-objects/stack-identifier.js +192 -0
  72. package/infrastructure/domains/health/domain/value-objects/stack-identifier.test.js +262 -0
  73. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-cfn-tagged.test.js +312 -0
  74. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-multi-stack.test.js +367 -0
  75. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +432 -0
  76. package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.js +784 -0
  77. package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +1133 -0
  78. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.js +565 -0
  79. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +554 -0
  80. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-importer.js +318 -0
  81. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-importer.test.js +398 -0
  82. package/infrastructure/domains/health/infrastructure/adapters/aws-stack-repository.js +777 -0
  83. package/infrastructure/domains/health/infrastructure/adapters/aws-stack-repository.test.js +580 -0
  84. package/infrastructure/domains/integration/integration-builder.js +397 -0
  85. package/infrastructure/domains/integration/integration-builder.test.js +593 -0
  86. package/infrastructure/domains/integration/integration-resolver.js +170 -0
  87. package/infrastructure/domains/integration/integration-resolver.test.js +369 -0
  88. package/infrastructure/domains/integration/websocket-builder.js +69 -0
  89. package/infrastructure/domains/integration/websocket-builder.test.js +195 -0
  90. package/infrastructure/domains/networking/vpc-builder.js +1829 -0
  91. package/infrastructure/domains/networking/vpc-builder.test.js +1262 -0
  92. package/infrastructure/domains/networking/vpc-discovery.js +177 -0
  93. package/infrastructure/domains/networking/vpc-discovery.test.js +350 -0
  94. package/infrastructure/domains/networking/vpc-resolver.js +324 -0
  95. package/infrastructure/domains/networking/vpc-resolver.test.js +501 -0
  96. package/infrastructure/domains/parameters/ssm-builder.js +79 -0
  97. package/infrastructure/domains/parameters/ssm-builder.test.js +189 -0
  98. package/infrastructure/domains/parameters/ssm-discovery.js +84 -0
  99. package/infrastructure/domains/parameters/ssm-discovery.test.js +210 -0
  100. package/infrastructure/{iam-generator.js → domains/security/iam-generator.js} +2 -2
  101. package/infrastructure/domains/security/kms-builder.js +366 -0
  102. package/infrastructure/domains/security/kms-builder.test.js +374 -0
  103. package/infrastructure/domains/security/kms-discovery.js +80 -0
  104. package/infrastructure/domains/security/kms-discovery.test.js +177 -0
  105. package/infrastructure/domains/security/kms-resolver.js +96 -0
  106. package/infrastructure/domains/security/kms-resolver.test.js +216 -0
  107. package/infrastructure/domains/shared/base-builder.js +112 -0
  108. package/infrastructure/domains/shared/base-resolver.js +186 -0
  109. package/infrastructure/domains/shared/base-resolver.test.js +305 -0
  110. package/infrastructure/domains/shared/builder-orchestrator.js +212 -0
  111. package/infrastructure/domains/shared/builder-orchestrator.test.js +213 -0
  112. package/infrastructure/domains/shared/cloudformation-discovery-v2.js +334 -0
  113. package/infrastructure/domains/shared/cloudformation-discovery.js +375 -0
  114. package/infrastructure/domains/shared/cloudformation-discovery.test.js +590 -0
  115. package/infrastructure/domains/shared/environment-builder.js +119 -0
  116. package/infrastructure/domains/shared/environment-builder.test.js +247 -0
  117. package/infrastructure/domains/shared/providers/aws-provider-adapter.js +544 -0
  118. package/infrastructure/domains/shared/providers/aws-provider-adapter.test.js +377 -0
  119. package/infrastructure/domains/shared/providers/azure-provider-adapter.stub.js +93 -0
  120. package/infrastructure/domains/shared/providers/cloud-provider-adapter.js +136 -0
  121. package/infrastructure/domains/shared/providers/gcp-provider-adapter.stub.js +82 -0
  122. package/infrastructure/domains/shared/providers/provider-factory.js +108 -0
  123. package/infrastructure/domains/shared/providers/provider-factory.test.js +170 -0
  124. package/infrastructure/domains/shared/resource-discovery.js +192 -0
  125. package/infrastructure/domains/shared/resource-discovery.test.js +552 -0
  126. package/infrastructure/domains/shared/types/app-definition.js +205 -0
  127. package/infrastructure/domains/shared/types/discovery-result.js +106 -0
  128. package/infrastructure/domains/shared/types/discovery-result.test.js +258 -0
  129. package/infrastructure/domains/shared/types/index.js +46 -0
  130. package/infrastructure/domains/shared/types/resource-ownership.js +108 -0
  131. package/infrastructure/domains/shared/types/resource-ownership.test.js +101 -0
  132. package/infrastructure/domains/shared/utilities/base-definition-factory.js +380 -0
  133. package/infrastructure/domains/shared/utilities/base-definition-factory.js.bak +338 -0
  134. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +248 -0
  135. package/infrastructure/domains/shared/utilities/handler-path-resolver.js +134 -0
  136. package/infrastructure/domains/shared/utilities/handler-path-resolver.test.js +268 -0
  137. package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +55 -0
  138. package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +138 -0
  139. package/infrastructure/{env-validator.js → domains/shared/validation/env-validator.js} +2 -1
  140. package/infrastructure/domains/shared/validation/env-validator.test.js +173 -0
  141. package/infrastructure/esbuild.config.js +53 -0
  142. package/infrastructure/infrastructure-composer.js +87 -0
  143. package/infrastructure/{serverless-template.test.js → infrastructure-composer.test.js} +115 -24
  144. package/infrastructure/scripts/build-prisma-layer.js +553 -0
  145. package/infrastructure/scripts/build-prisma-layer.test.js +102 -0
  146. package/infrastructure/{build-time-discovery.js → scripts/build-time-discovery.js} +80 -48
  147. package/infrastructure/{build-time-discovery.test.js → scripts/build-time-discovery.test.js} +5 -4
  148. package/layers/prisma/nodejs/package.json +8 -0
  149. package/management-ui/server/utils/cliIntegration.js +1 -1
  150. package/management-ui/server/utils/environment/awsParameterStore.js +29 -18
  151. package/package.json +11 -11
  152. package/frigg-cli/.eslintrc.js +0 -141
  153. package/frigg-cli/__tests__/unit/commands/build.test.js +0 -251
  154. package/frigg-cli/__tests__/unit/commands/db-setup.test.js +0 -548
  155. package/frigg-cli/__tests__/unit/commands/install.test.js +0 -400
  156. package/frigg-cli/__tests__/unit/commands/ui.test.js +0 -346
  157. package/frigg-cli/__tests__/unit/utils/database-validator.test.js +0 -366
  158. package/frigg-cli/__tests__/unit/utils/error-messages.test.js +0 -304
  159. package/frigg-cli/__tests__/unit/utils/prisma-runner.test.js +0 -486
  160. package/frigg-cli/__tests__/utils/mock-factory.js +0 -270
  161. package/frigg-cli/__tests__/utils/prisma-mock.js +0 -194
  162. package/frigg-cli/__tests__/utils/test-fixtures.js +0 -463
  163. package/frigg-cli/__tests__/utils/test-setup.js +0 -287
  164. package/frigg-cli/build-command/index.js +0 -65
  165. package/frigg-cli/db-setup-command/index.js +0 -193
  166. package/frigg-cli/deploy-command/index.js +0 -175
  167. package/frigg-cli/generate-command/__tests__/generate-command.test.js +0 -301
  168. package/frigg-cli/generate-command/azure-generator.js +0 -43
  169. package/frigg-cli/generate-command/gcp-generator.js +0 -47
  170. package/frigg-cli/generate-command/index.js +0 -332
  171. package/frigg-cli/generate-command/terraform-generator.js +0 -555
  172. package/frigg-cli/generate-iam-command.js +0 -118
  173. package/frigg-cli/index.js +0 -75
  174. package/frigg-cli/index.test.js +0 -158
  175. package/frigg-cli/init-command/backend-first-handler.js +0 -756
  176. package/frigg-cli/init-command/index.js +0 -93
  177. package/frigg-cli/init-command/template-handler.js +0 -143
  178. package/frigg-cli/install-command/backend-js.js +0 -33
  179. package/frigg-cli/install-command/commit-changes.js +0 -16
  180. package/frigg-cli/install-command/environment-variables.js +0 -127
  181. package/frigg-cli/install-command/environment-variables.test.js +0 -136
  182. package/frigg-cli/install-command/index.js +0 -54
  183. package/frigg-cli/install-command/install-package.js +0 -13
  184. package/frigg-cli/install-command/integration-file.js +0 -30
  185. package/frigg-cli/install-command/logger.js +0 -12
  186. package/frigg-cli/install-command/template.js +0 -90
  187. package/frigg-cli/install-command/validate-package.js +0 -75
  188. package/frigg-cli/jest.config.js +0 -124
  189. package/frigg-cli/package.json +0 -54
  190. package/frigg-cli/start-command/index.js +0 -149
  191. package/frigg-cli/start-command/start-command.test.js +0 -297
  192. package/frigg-cli/test/init-command.test.js +0 -180
  193. package/frigg-cli/test/npm-registry.test.js +0 -319
  194. package/frigg-cli/ui-command/index.js +0 -154
  195. package/frigg-cli/utils/app-resolver.js +0 -319
  196. package/frigg-cli/utils/backend-path.js +0 -25
  197. package/frigg-cli/utils/database-validator.js +0 -161
  198. package/frigg-cli/utils/error-messages.js +0 -257
  199. package/frigg-cli/utils/npm-registry.js +0 -167
  200. package/frigg-cli/utils/prisma-runner.js +0 -280
  201. package/frigg-cli/utils/process-manager.js +0 -199
  202. package/frigg-cli/utils/repo-detection.js +0 -405
  203. package/infrastructure/aws-discovery.js +0 -1176
  204. package/infrastructure/aws-discovery.test.js +0 -1220
  205. package/infrastructure/serverless-template.js +0 -2094
  206. /package/infrastructure/{WEBSOCKET-CONFIGURATION.md → docs/WEBSOCKET-CONFIGURATION.md} +0 -0
  207. /package/infrastructure/{GENERATE-IAM-DOCS.md → docs/generate-iam-command.md} +0 -0
  208. /package/infrastructure/{iam-generator.test.js → domains/security/iam-generator.test.js} +0 -0
  209. /package/infrastructure/{frigg-deployment-iam-stack.yaml → domains/security/templates/frigg-deployment-iam-stack.yaml} +0 -0
  210. /package/infrastructure/{iam-policy-basic.json → domains/security/templates/iam-policy-basic.json} +0 -0
  211. /package/infrastructure/{iam-policy-full.json → domains/security/templates/iam-policy-full.json} +0 -0
  212. /package/infrastructure/{run-discovery.js → scripts/run-discovery.js} +0 -0
@@ -0,0 +1,630 @@
1
+ # PostgreSQL (Aurora) Configuration Guide
2
+
3
+ This guide covers Aurora PostgreSQL provisioning and configuration in Frigg Framework applications.
4
+
5
+ ## Overview
6
+
7
+ Frigg Framework supports automatic provisioning of Amazon Aurora Serverless v2 PostgreSQL databases for your integrations. Aurora databases are deployed in the same VPC as your Lambda functions with secure access via AWS Secrets Manager.
8
+
9
+ ### Key Features
10
+
11
+ - **Aurora Serverless v2**: Cost-efficient auto-scaling database (0.5-1.0 ACU default)
12
+ - **VPC Integration**: Deployed in same private subnets as Lambda functions
13
+ - **Secrets Manager**: Automatic credential management and rotation
14
+ - **Three Management Modes**: discover, create-new, use-existing
15
+ - **Security**: Private subnet deployment with security group isolation
16
+ - **High Availability**: Multi-AZ deployment with automatic failover
17
+
18
+ ---
19
+
20
+ ## Configuration Schema
21
+
22
+ ### App Definition Structure
23
+
24
+ ```javascript
25
+ // backend/index.js
26
+ const appDefinition = {
27
+ name: 'my-frigg-app',
28
+
29
+ // Enable VPC deployment (required for Aurora)
30
+ vpc: {
31
+ enable: true,
32
+ },
33
+
34
+ // Aurora PostgreSQL Configuration
35
+ database: {
36
+ postgres: {
37
+ enable: true,
38
+
39
+ // Management mode: 'discover' | 'create-new' | 'use-existing'
40
+ management: 'discover',
41
+
42
+ // Basic Configuration
43
+ databaseName: 'frigg_db',
44
+ masterUsername: 'frigg_admin',
45
+
46
+ // Engine Configuration
47
+ engine: 'aurora-postgresql',
48
+ engineVersion: '15.3',
49
+
50
+ // Scaling Configuration (Aurora Serverless v2)
51
+ scaling: {
52
+ minCapacity: 0.5, // ACUs (0.5 = ~1GB RAM, ~$43/month)
53
+ maxCapacity: 1.0, // ACUs (1.0 = ~2GB RAM, ~$87/month)
54
+ },
55
+
56
+ // Backup Configuration
57
+ backupRetentionDays: 7,
58
+ preferredBackupWindow: '03:00-04:00',
59
+
60
+ // Security & Advanced
61
+ deletionProtection: true,
62
+ enablePerformanceInsights: false,
63
+
64
+ // For use-existing mode
65
+ clusterIdentifier: 'my-existing-cluster',
66
+ secretArn: 'arn:aws:secretsmanager:...',
67
+ }
68
+ }
69
+ };
70
+
71
+ module.exports = {
72
+ Definition: appDefinition,
73
+ };
74
+ ```
75
+
76
+ ---
77
+
78
+ ## Management Modes
79
+
80
+ ### 1. Discover Mode (Default)
81
+
82
+ Automatically discovers existing Aurora clusters or creates new one if none found.
83
+
84
+ ```javascript
85
+ database: {
86
+ postgres: {
87
+ enable: true,
88
+ management: 'discover', // Default
89
+ }
90
+ }
91
+ ```
92
+
93
+ **Discovery Priority**:
94
+ 1. Frigg-managed cluster with matching service + stage tags
95
+ 2. Any Frigg-managed cluster
96
+ 3. First available Aurora PostgreSQL cluster
97
+ 4. Creates new cluster if none found
98
+
99
+ **Best For**: Development and staging environments where you want automatic setup.
100
+
101
+ ---
102
+
103
+ ### 2. Create-New Mode
104
+
105
+ Always creates a new Aurora cluster, even if existing clusters are found.
106
+
107
+ ```javascript
108
+ database: {
109
+ postgres: {
110
+ enable: true,
111
+ management: 'create-new',
112
+
113
+ // Customization options
114
+ databaseName: 'my_app_db',
115
+ masterUsername: 'admin',
116
+ engineVersion: '15.3',
117
+ scaling: {
118
+ minCapacity: 1.0,
119
+ maxCapacity: 2.0,
120
+ },
121
+ backupRetentionDays: 14,
122
+ deletionProtection: true,
123
+ }
124
+ }
125
+ ```
126
+
127
+ **Best For**: Production environments where you want dedicated database resources.
128
+
129
+ ---
130
+
131
+ ### 3. Use-Existing Mode
132
+
133
+ Uses a specific existing Aurora cluster by identifier.
134
+
135
+ ```javascript
136
+ database: {
137
+ postgres: {
138
+ enable: true,
139
+ management: 'use-existing',
140
+
141
+ // Required: existing cluster identifier
142
+ clusterIdentifier: 'my-existing-aurora-cluster',
143
+
144
+ // Optional: secret ARN (discovered if not provided)
145
+ secretArn: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:my-db-secret',
146
+
147
+ // Database name to connect to
148
+ databaseName: 'frigg_db',
149
+ }
150
+ }
151
+ ```
152
+
153
+ **Best For**: Shared database scenarios or when you manage Aurora outside of Frigg.
154
+
155
+ ---
156
+
157
+ ## Created AWS Resources
158
+
159
+ When provisioning Aurora (`create-new` or `discover` mode without existing cluster), Frigg creates:
160
+
161
+ ### 1. RDS DB Subnet Group
162
+ - **Name**: `{service}-{stage}-db-subnet-group`
163
+ - **Subnets**: Uses same private subnets as Lambda functions
164
+ - **Purpose**: Defines which subnets Aurora can use
165
+
166
+ ### 2. Security Group
167
+ - **Name**: `{service}-{stage}-aurora-sg`
168
+ - **Ingress**: Port 5432 from Lambda security group
169
+ - **Purpose**: Allows Lambda → Aurora communication
170
+
171
+ ### 3. Secrets Manager Secret
172
+ - **Name**: `{service}-{stage}-aurora-credentials`
173
+ - **Contents**: `{ username, password }`
174
+ - **Purpose**: Stores database credentials securely
175
+ - **Rotation**: Automatic (optional, can be configured)
176
+
177
+ ### 4. Aurora Cluster
178
+ - **Engine**: aurora-postgresql (version 15.3 default)
179
+ - **Mode**: Provisioned (Serverless v2)
180
+ - **Scaling**: 0.5-1.0 ACU (configurable)
181
+ - **Backup**: 7-day retention (configurable)
182
+ - **Multi-AZ**: Yes (high availability)
183
+
184
+ ### 5. Aurora Instance
185
+ - **Class**: db.serverless
186
+ - **Cluster**: Attached to cluster above
187
+ - **Public Access**: No (private subnet only)
188
+
189
+ ### 6. IAM Permissions
190
+ - **Secrets Manager**: GetSecretValue, DescribeSecret
191
+ - **Purpose**: Lambda functions can retrieve credentials
192
+
193
+ ---
194
+
195
+ ## Cost Optimization
196
+
197
+ ### Default Configuration (Most Cost-Efficient)
198
+
199
+ ```javascript
200
+ database: {
201
+ postgres: {
202
+ enable: true,
203
+ // Uses defaults:
204
+ // - 0.5 ACU minimum (scales to near-zero during idle)
205
+ // - 1.0 ACU maximum
206
+ // - No Performance Insights
207
+ // - 7-day backup retention
208
+ }
209
+ }
210
+ ```
211
+
212
+ **Estimated Monthly Costs**:
213
+ - **Idle/Low Traffic**: $15-30/month (0.5 ACU minimum)
214
+ - **Moderate Traffic**: $30-60/month (0.5-1.0 ACU average)
215
+ - **Storage**: $0.10/GB-month
216
+ - **Backup Storage**: Free (within retention period)
217
+
218
+ ### Production Configuration
219
+
220
+ ```javascript
221
+ database: {
222
+ postgres: {
223
+ enable: true,
224
+ scaling: {
225
+ minCapacity: 1.0, // Higher baseline for production
226
+ maxCapacity: 4.0, // Handle traffic spikes
227
+ },
228
+ backupRetentionDays: 30, // Longer retention
229
+ enablePerformanceInsights: true, // Monitoring
230
+ deletionProtection: true, // Prevent accidental deletion
231
+ }
232
+ }
233
+ ```
234
+
235
+ **Estimated Monthly Costs**:
236
+ - **Baseline**: $87/month (1.0 ACU minimum)
237
+ - **Peak Traffic**: $348/month (4.0 ACU maximum)
238
+ - **Performance Insights**: $7/month
239
+
240
+ ### Cost-Saving Tips
241
+
242
+ 1. **Use Aurora Serverless v2**: Scales to near-zero during idle periods
243
+ 2. **Right-size ACU limits**: Start with defaults, increase only if needed
244
+ 3. **Disable Performance Insights** in dev/staging
245
+ 4. **Shorter backup retention** for non-production (7 days)
246
+ 5. **Monitor CloudWatch metrics** to optimize scaling configuration
247
+
248
+ ---
249
+
250
+ ## Security Best Practices
251
+
252
+ ### 1. Network Isolation
253
+
254
+ - ✅ **Private Subnets Only**: Aurora deployed in private subnets (no internet access)
255
+ - ✅ **Security Groups**: Restricts access to Lambda security group only
256
+ - ✅ **VPC Endpoints**: Use VPC endpoints for AWS services (no NAT Gateway costs)
257
+
258
+ ### 2. Credential Management
259
+
260
+ - ✅ **Secrets Manager**: Never hardcode database passwords
261
+ - ✅ **Auto-Rotation**: Enable automatic secret rotation (recommended)
262
+ - ✅ **IAM Integration**: Lambda uses IAM role to access secrets
263
+ - ❌ **Never commit** `DATABASE_URL` to source control
264
+
265
+ ### 3. Access Control
266
+
267
+ ```javascript
268
+ // Lambda functions automatically get DATABASE_URL from Secrets Manager
269
+ // No manual credential management required
270
+
271
+ // Example: Prisma client automatically uses DATABASE_URL
272
+ import { prismaClient } from '@friggframework/core/database/prisma';
273
+
274
+ const users = await prismaClient.user.findMany();
275
+ ```
276
+
277
+ ### 4. Deletion Protection
278
+
279
+ ```javascript
280
+ database: {
281
+ postgres: {
282
+ deletionProtection: true, // Prevents accidental deletion
283
+ }
284
+ }
285
+ ```
286
+
287
+ **Important**: When enabled, you must manually disable deletion protection in AWS console before stack deletion.
288
+
289
+ ---
290
+
291
+ ## Environment Variables
292
+
293
+ ### Automatically Set
294
+
295
+ Frigg automatically sets these environment variables for Lambda functions:
296
+
297
+ ```bash
298
+ # Database connection (from Secrets Manager)
299
+ DATABASE_URL=postgresql://user:pass@endpoint:5432/dbname
300
+
301
+ # Database type (for Prisma client selection)
302
+ DB_TYPE=postgresql
303
+
304
+ # Discovery metadata (for debugging)
305
+ AWS_DISCOVERY_AURORA_CLUSTER_ID=my-cluster
306
+ AWS_DISCOVERY_AURORA_ENDPOINT=my-cluster.cluster-abc.us-east-1.rds.amazonaws.com
307
+ AWS_DISCOVERY_AURORA_PORT=5432
308
+ AWS_DISCOVERY_AURORA_SECRET_ARN=arn:aws:secretsmanager:...
309
+ ```
310
+
311
+ ### Usage in Lambda Functions
312
+
313
+ ```javascript
314
+ // No manual configuration needed!
315
+ // DATABASE_URL is automatically available
316
+
317
+ import { prismaClient } from '@friggframework/core/database/prisma';
318
+
319
+ export async function handler(event, context) {
320
+ // Prisma client uses DATABASE_URL automatically
321
+ const result = await prismaClient.user.create({
322
+ data: { email: 'user@example.com' }
323
+ });
324
+
325
+ return { statusCode: 200, body: JSON.stringify(result) };
326
+ }
327
+ ```
328
+
329
+ ---
330
+
331
+ ## Local Development
332
+
333
+ ### Option 1: Docker Compose PostgreSQL
334
+
335
+ ```yaml
336
+ # docker-compose.yml
337
+ version: '3.8'
338
+ services:
339
+ postgres:
340
+ image: postgres:15
341
+ environment:
342
+ POSTGRES_USER: frigg_admin
343
+ POSTGRES_PASSWORD: local_password
344
+ POSTGRES_DB: frigg_db
345
+ ports:
346
+ - "5432:5432"
347
+ volumes:
348
+ - postgres_data:/var/lib/postgresql/data
349
+
350
+ volumes:
351
+ postgres_data:
352
+ ```
353
+
354
+ ```bash
355
+ # .env (local development)
356
+ DATABASE_URL=postgresql://frigg_admin:local_password@localhost:5432/frigg_db
357
+ DB_TYPE=postgresql
358
+ ```
359
+
360
+ ### Option 2: Connect to AWS Aurora (Not Recommended)
361
+
362
+ ```bash
363
+ # .env (staging Aurora - for testing only)
364
+ DATABASE_URL=postgresql://user:pass@staging-cluster.abc.us-east-1.rds.amazonaws.com:5432/frigg_db
365
+ DB_TYPE=postgresql
366
+ ```
367
+
368
+ **Security Note**: Never commit Aurora credentials to source control. Use AWS SSO or parameter store for team access.
369
+
370
+ ---
371
+
372
+ ## Migration Guide
373
+
374
+ ### From External PostgreSQL to Aurora
375
+
376
+ 1. **Backup Existing Database**
377
+ ```bash
378
+ pg_dump -h old-host -U user -d dbname > backup.sql
379
+ ```
380
+
381
+ 2. **Deploy Aurora Cluster**
382
+ ```javascript
383
+ // backend/index.js
384
+ database: {
385
+ postgres: {
386
+ enable: true,
387
+ management: 'create-new',
388
+ }
389
+ }
390
+ ```
391
+
392
+ ```bash
393
+ npm run frigg:deploy
394
+ ```
395
+
396
+ 3. **Restore to Aurora**
397
+ ```bash
398
+ # Get Aurora endpoint from AWS console or deployment output
399
+ psql -h aurora-endpoint.us-east-1.rds.amazonaws.com -U frigg_admin -d frigg_db < backup.sql
400
+ ```
401
+
402
+ 4. **Run Migrations**
403
+ ```bash
404
+ npm run frigg:db:setup
405
+ ```
406
+
407
+ ### From MongoDB to PostgreSQL
408
+
409
+ 1. **Add PostgreSQL Configuration**
410
+ ```javascript
411
+ database: {
412
+ postgres: {
413
+ enable: true,
414
+ management: 'create-new',
415
+ }
416
+ }
417
+ ```
418
+
419
+ 2. **Run Prisma Migrations**
420
+ ```bash
421
+ # Generate Prisma PostgreSQL client
422
+ npm run frigg:db:setup
423
+ ```
424
+
425
+ 3. **Data Migration Script** (custom per application)
426
+ ```javascript
427
+ // migrate-data.js
428
+ const { MongoClient } = require('mongodb');
429
+ const { prismaClient } = require('@friggframework/core/database/prisma');
430
+
431
+ async function migrate() {
432
+ const mongo = await MongoClient.connect(process.env.MONGO_URI);
433
+ const users = await mongo.db().collection('users').find().toArray();
434
+
435
+ for (const user of users) {
436
+ await prismaClient.user.create({
437
+ data: {
438
+ id: user._id.toString(),
439
+ email: user.email,
440
+ // ... map fields
441
+ }
442
+ });
443
+ }
444
+
445
+ await mongo.close();
446
+ }
447
+
448
+ migrate().catch(console.error);
449
+ ```
450
+
451
+ ---
452
+
453
+ ## Troubleshooting
454
+
455
+ ### Issue: "No Aurora cluster found"
456
+
457
+ **Error**:
458
+ ```
459
+ No Aurora cluster found in discovery mode. Set management to "create-new"...
460
+ ```
461
+
462
+ **Solution**:
463
+ 1. Check VPC is enabled: `vpc.enable: true`
464
+ 2. Set management mode: `management: 'create-new'`
465
+ 3. Or provide cluster identifier: `clusterIdentifier: 'my-cluster'`
466
+
467
+ ---
468
+
469
+ ### Issue: "Timeout connecting to database"
470
+
471
+ **Symptoms**: Lambda functions timeout when connecting to Aurora
472
+
473
+ **Possible Causes**:
474
+ 1. **Security Group Misconfiguration**
475
+ - Check Lambda SG can access Aurora SG on port 5432
476
+ - Verify Aurora SG allows inbound from Lambda SG
477
+
478
+ 2. **VPC/Subnet Issues**
479
+ - Ensure Lambda and Aurora in same VPC
480
+ - Verify Aurora in private subnets
481
+ - Check route tables allow internal VPC traffic
482
+
483
+ 3. **Secret Not Found**
484
+ - Verify Secrets Manager secret exists
485
+ - Check IAM role has secretsmanager:GetSecretValue permission
486
+
487
+ **Debug Steps**:
488
+ ```bash
489
+ # Check Aurora cluster status
490
+ aws rds describe-db-clusters --db-cluster-identifier my-cluster
491
+
492
+ # Check security groups
493
+ aws ec2 describe-security-groups --group-ids sg-xxx
494
+
495
+ # Test Lambda → Aurora connectivity (requires VPC endpoint or NAT)
496
+ aws lambda invoke --function-name test-db-connection output.json
497
+ ```
498
+
499
+ ---
500
+
501
+ ### Issue: "Insufficient capacity"
502
+
503
+ **Error**:
504
+ ```
505
+ Cannot create Aurora cluster: InsufficientDBInstanceCapacity
506
+ ```
507
+
508
+ **Solution**:
509
+ 1. Try different availability zones
510
+ 2. Change instance class (though Serverless v2 shouldn't have this issue)
511
+ 3. Contact AWS support for capacity increase
512
+
513
+ ---
514
+
515
+ ### Issue: "Cost unexpectedly high"
516
+
517
+ **Symptoms**: Aurora costs higher than expected
518
+
519
+ **Investigation**:
520
+ 1. **Check ACU Usage**:
521
+ ```bash
522
+ # CloudWatch metric: ServerlessDatabaseCapacity
523
+ aws cloudwatch get-metric-statistics \
524
+ --namespace AWS/RDS \
525
+ --metric-name ServerlessDatabaseCapacity \
526
+ --dimensions Name=DBClusterIdentifier,Value=my-cluster \
527
+ --start-time 2024-01-01T00:00:00Z \
528
+ --end-time 2024-01-02T00:00:00Z \
529
+ --period 3600 \
530
+ --statistics Average
531
+ ```
532
+
533
+ 2. **Review Scaling Configuration**:
534
+ - Lower `maxCapacity` if traffic spikes are rare
535
+ - Increase `minCapacity` only if cold starts are an issue
536
+
537
+ 3. **Check for Long-Running Connections**:
538
+ - Aurora doesn't scale down if connections are open
539
+ - Review application connection pooling
540
+
541
+ 4. **Disable Performance Insights** in non-production
542
+
543
+ ---
544
+
545
+ ## Advanced Configuration
546
+
547
+ ### Custom Backup Window
548
+
549
+ ```javascript
550
+ database: {
551
+ postgres: {
552
+ enable: true,
553
+ backupRetentionDays: 30,
554
+ preferredBackupWindow: '02:00-03:00', // UTC
555
+ }
556
+ }
557
+ ```
558
+
559
+ ### Enhanced Monitoring
560
+
561
+ ```javascript
562
+ database: {
563
+ postgres: {
564
+ enable: true,
565
+ enablePerformanceInsights: true,
566
+ // Performance Insights retention: 7 days (default) or 731 days
567
+ }
568
+ }
569
+ ```
570
+
571
+ ### Custom Engine Version
572
+
573
+ ```javascript
574
+ database: {
575
+ postgres: {
576
+ enable: true,
577
+ engineVersion: '14.6', // Default: 15.3
578
+ }
579
+ }
580
+ ```
581
+
582
+ ### Read Replicas (Not Supported Yet)
583
+
584
+ Frigg currently provisions a single Aurora instance. For read replicas:
585
+
586
+ 1. Manually add instances in AWS console
587
+ 2. Or create custom CloudFormation resources in `backend/infrastructure.js`
588
+
589
+ ---
590
+
591
+ ## Reference
592
+
593
+ ### Aurora Serverless v2 ACU Sizing
594
+
595
+ | ACUs | RAM | Approx Monthly Cost | Use Case |
596
+ |------|-------|---------------------|-----------------------------|
597
+ | 0.5 | 1 GB | $43 | Development, low traffic |
598
+ | 1.0 | 2 GB | $87 | Staging, moderate traffic |
599
+ | 2.0 | 4 GB | $174 | Production, steady traffic |
600
+ | 4.0 | 8 GB | $348 | Production, high traffic |
601
+ | 8.0 | 16 GB | $696 | Production, very high traffic|
602
+
603
+ **Note**: Costs as of 2024, us-east-1 region. Check current pricing at [AWS Pricing](https://aws.amazon.com/rds/aurora/pricing/).
604
+
605
+ ### Supported PostgreSQL Versions
606
+
607
+ - 15.3 (recommended, default)
608
+ - 15.2
609
+ - 14.6
610
+ - 14.5
611
+ - 13.9
612
+
613
+ Check [Aurora PostgreSQL Releases](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraPostgreSQLReleaseNotes/AuroraPostgreSQL.Updates.html) for latest versions.
614
+
615
+ ---
616
+
617
+ ## Related Documentation
618
+
619
+ - [VPC Configuration Guide](VPC-CONFIGURATION.md)
620
+ - [Secrets Manager Integration](SECRETS-MANAGER.md)
621
+ - [Database Migrations](../frigg-cli/DB-SETUP.md)
622
+ - [AWS Discovery Troubleshooting](AWS-DISCOVERY-TROUBLESHOOTING.md)
623
+
624
+ ---
625
+
626
+ ## Support
627
+
628
+ - **Issues**: [GitHub Issues](https://github.com/friggframework/frigg/issues)
629
+ - **Documentation**: [Frigg Framework Docs](https://docs.friggframework.org)
630
+ - **Community**: [Slack Channel](https://friggframework.org/#contact)
@@ -21,7 +21,7 @@ You can deploy the stack using either the AWS Management Console (UI) or AWS CLI
21
21
  3. Click **Create stack** → **With new resources (standard)**
22
22
  4. In the **Specify template** section:
23
23
  - Select **Upload a template file**
24
- - Click **Choose file** and select `frigg-deployment-iam-stack.yaml`
24
+ - Click **Choose file** and select `domains/security/templates/frigg-deployment-iam-stack.yaml`
25
25
  - Click **Next**
26
26
 
27
27
  #### 2. Configure Stack Details
@@ -64,7 +64,7 @@ You can deploy the stack using either the AWS Management Console (UI) or AWS CLI
64
64
 
65
65
  ```bash
66
66
  aws cloudformation deploy \
67
- --template-file frigg-deployment-iam-stack.yaml \
67
+ --template-file domains/security/templates/frigg-deployment-iam-stack.yaml \
68
68
  --stack-name frigg-deployment-iam \
69
69
  --capabilities CAPABILITY_NAMED_IAM \
70
70
  --parameter-overrides \
@@ -215,7 +215,7 @@ To update permissions or parameters:
215
215
  ```bash
216
216
  aws cloudformation update-stack \
217
217
  --stack-name frigg-deployment-iam \
218
- --template-body file://frigg-deployment-iam-stack.yaml \
218
+ --template-body file://domains/security/templates/frigg-deployment-iam-stack.yaml \
219
219
  --capabilities CAPABILITY_NAMED_IAM \
220
220
  --parameter-overrides \
221
221
  EnableVPCSupport=false # Example: disable VPC support
@@ -12,7 +12,7 @@ For immediate deployment, you have two ready-to-use IAM policy options:
12
12
  aws iam put-user-policy \
13
13
  --user-name frigg-deployment-user \
14
14
  --policy-name FriggBasicDeploymentPolicy \
15
- --policy-document file://iam-policy-basic.json
15
+ --policy-document file://domains/security/templates/iam-policy-basic.json
16
16
  ```
17
17
 
18
18
  **Includes permissions for:**
@@ -32,7 +32,7 @@ aws iam put-user-policy \
32
32
  aws iam put-user-policy \
33
33
  --user-name frigg-deployment-user \
34
34
  --policy-name FriggFullDeploymentPolicy \
35
- --policy-document file://iam-policy-full.json
35
+ --policy-document file://domains/security/templates/iam-policy-full.json
36
36
  ```
37
37
 
38
38
  **Includes everything from Basic Policy PLUS:**
@@ -65,7 +65,7 @@ This means your current deployment user doesn't have VPC permissions. You have t
65
65
  aws iam put-user-policy \
66
66
  --user-name frigg-deployment-user \
67
67
  --policy-name FriggFullDeploymentPolicy \
68
- --policy-document file://iam-policy-full.json
68
+ --policy-document file://domains/security/templates/iam-policy-full.json
69
69
  ```
70
70
 
71
71
  ### Alternative: Update CloudFormation Stack
@@ -73,7 +73,7 @@ If you deployed using the CloudFormation template, update it with VPC support:
73
73
  ```bash
74
74
  aws cloudformation update-stack \
75
75
  --stack-name frigg-deployment-iam \
76
- --template-body file://frigg-deployment-iam-stack.yaml \
76
+ --template-body file://domains/security/templates/frigg-deployment-iam-stack.yaml \
77
77
  --parameters ParameterKey=EnableVPCSupport,ParameterValue=true \
78
78
  --capabilities CAPABILITY_IAM
79
79
  ```
@@ -178,12 +178,11 @@ frigg deploy
178
178
 
179
179
  ## Files in this Directory
180
180
 
181
- - `iam-policy-basic.json` - Core Frigg permissions only (JSON format)
182
- - `iam-policy-full.json` - All features enabled (JSON format)
183
- - `frigg-deployment-iam-stack.yaml` - CloudFormation template with conditional parameters
184
- - `iam-generator.js` - Programmatic policy generation with basic/full/auto modes
185
- - `AWS-IAM-CREDENTIAL-NEEDS.md` - Detailed permission explanations and troubleshooting
186
- - `IAM-POLICY-TEMPLATES.md` - This file - Quick start guide and usage examples
181
+ - `../domains/security/templates/iam-policy-basic.json` - Core Frigg permissions only (JSON format)
182
+ - `../domains/security/templates/iam-policy-full.json` - All features enabled (JSON format)
183
+ - `../domains/security/templates/frigg-deployment-iam-stack.yaml` - CloudFormation template with conditional parameters
184
+ - `../domains/security/iam-generator.js` - Programmatic policy generation with basic/full/auto modes
185
+ - This file (`iam-policy-templates.md`) - Quick start guide and usage examples
187
186
 
188
187
  ## Support
189
188