@friggframework/devtools 2.0.0--canary.702.ef0dc8c.0 → 2.0.0--canary.710.7cfcf12.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.
Files changed (86) hide show
  1. package/README.md +0 -1
  2. package/frigg-cli/README.md +78 -76
  3. package/frigg-cli/__tests__/unit/commands/build.test.js +0 -3
  4. package/frigg-cli/__tests__/unit/commands/deploy.test.js +30 -27
  5. package/frigg-cli/__tests__/unit/commands/doctor.test.js +10 -6
  6. package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +18 -0
  7. package/frigg-cli/__tests__/unit/commands/init.test.js +688 -0
  8. package/frigg-cli/__tests__/unit/commands/install.test.js +601 -341
  9. package/frigg-cli/__tests__/unit/commands/ui.test.js +31 -30
  10. package/frigg-cli/__tests__/unit/dependencies.test.js +6 -2
  11. package/frigg-cli/build-command/index.js +0 -6
  12. package/frigg-cli/deploy-command/index.js +0 -6
  13. package/frigg-cli/generate-command/index.js +1 -0
  14. package/frigg-cli/generate-iam-command.js +1 -0
  15. package/frigg-cli/index.js +10 -23
  16. package/frigg-cli/init-command/backend-first-handler.js +395 -531
  17. package/frigg-cli/init-command/deployment-modes.js +7 -0
  18. package/frigg-cli/init-command/index.js +82 -35
  19. package/frigg-cli/init-command/safe-path.js +58 -0
  20. package/frigg-cli/init-command/scaffold-dependencies.js +202 -0
  21. package/frigg-cli/install-command/app-definition.js +174 -0
  22. package/frigg-cli/install-command/commit-changes.js +40 -8
  23. package/frigg-cli/install-command/environment-variables.js +15 -0
  24. package/frigg-cli/install-command/index.js +96 -21
  25. package/frigg-cli/install-command/install-package.js +77 -4
  26. package/frigg-cli/install-command/integration-file.js +20 -11
  27. package/frigg-cli/install-command/resolve-module.js +69 -0
  28. package/frigg-cli/install-command/template.js +102 -75
  29. package/frigg-cli/install-command/validate-package.js +36 -4
  30. package/frigg-cli/package.json +1 -1
  31. package/frigg-cli/start-command/index.js +0 -4
  32. package/frigg-cli/start-command/start-command.test.js +0 -3
  33. package/frigg-cli/templates/backend/README.md +267 -0
  34. package/frigg-cli/templates/backend/env.example +20 -0
  35. package/frigg-cli/templates/backend/gitignore +10 -0
  36. package/frigg-cli/templates/backend/index.js +114 -0
  37. package/frigg-cli/templates/backend/infrastructure.js +20 -0
  38. package/frigg-cli/test/init-command.test.js +9 -2
  39. package/infrastructure/__tests__/postgres-config.test.js +241 -835
  40. package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +148 -0
  41. package/infrastructure/__tests__/template-generation.test.js +36 -8
  42. package/infrastructure/create-frigg-infrastructure.js +1 -4
  43. package/infrastructure/docs/POSTGRES-CONFIGURATION.md +118 -60
  44. package/infrastructure/domains/database/aurora-builder.js +13 -2
  45. package/infrastructure/domains/database/aurora-builder.test.js +22 -0
  46. package/infrastructure/domains/health/application/use-cases/__tests__/mismatch-analyzer-method-name.test.js +12 -8
  47. package/infrastructure/domains/health/application/use-cases/__tests__/repair-via-import-use-case.test.js +19 -7
  48. package/infrastructure/domains/health/application/use-cases/run-health-check-use-case.test.js +12 -8
  49. package/infrastructure/domains/health/domain/services/__tests__/import-progress-monitor.test.js +17 -18
  50. package/infrastructure/domains/health/domain/services/__tests__/update-progress-monitor.test.js +12 -2
  51. package/infrastructure/domains/health/infrastructure/adapters/__tests__/orphan-detection-relationship-analysis.test.js +8 -1
  52. package/infrastructure/domains/health/infrastructure/adapters/aws-property-reconciler.test.js +4 -2
  53. package/infrastructure/domains/health/infrastructure/adapters/aws-resource-detector.test.js +10 -0
  54. package/infrastructure/domains/networking/vpc-builder.js +18 -8
  55. package/infrastructure/domains/networking/vpc-builder.test.js +26 -12
  56. package/infrastructure/domains/security/iam-generator.js +112 -5
  57. package/infrastructure/domains/security/iam-generator.test.js +94 -0
  58. package/infrastructure/domains/shared/cloudformation-discovery.test.js +36 -6
  59. package/infrastructure/domains/shared/utilities/base-definition-factory.js +7 -2
  60. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +21 -0
  61. package/infrastructure/infrastructure-composer.test.js +268 -794
  62. package/infrastructure/scripts/build-prisma-layer.test.js +28 -7
  63. package/infrastructure/scripts/build-time-discovery.test.js +18 -3
  64. package/package.json +10 -8
  65. package/frigg-cli/__tests__/unit/commands/validate-wiring.test.js +0 -92
  66. package/frigg-cli/index.test.js +0 -158
  67. package/frigg-cli/validate-command/__tests__/init-validation.test.js +0 -63
  68. package/frigg-cli/validate-command/__tests__/integrations-checks.test.js +0 -133
  69. package/frigg-cli/validate-command/__tests__/validate-app-definition.test.js +0 -326
  70. package/frigg-cli/validate-command/__tests__/validate-command.test.js +0 -241
  71. package/frigg-cli/validate-command/__tests__/validate-module-command.test.js +0 -119
  72. package/frigg-cli/validate-command/checks/config.js +0 -468
  73. package/frigg-cli/validate-command/checks/integrations.js +0 -274
  74. package/frigg-cli/validate-command/fixtures/bad-module/index.js +0 -18
  75. package/frigg-cli/validate-command/fixtures/fathom-module/definition.js +0 -76
  76. package/frigg-cli/validate-command/fixtures/fathom-module/index.js +0 -6
  77. package/frigg-cli/validate-command/format-report.js +0 -60
  78. package/frigg-cli/validate-command/index.js +0 -151
  79. package/frigg-cli/validate-command/load-app-definition.js +0 -93
  80. package/frigg-cli/validate-command/load-module-definition.js +0 -64
  81. package/frigg-cli/validate-command/schema-issues.js +0 -154
  82. package/frigg-cli/validate-command/validate-app-definition.js +0 -60
  83. package/frigg-cli/validate-command/validate-module-definition.js +0 -46
  84. package/infrastructure/app-definition-schema-contract.test.js +0 -607
  85. package/infrastructure/create-frigg-infrastructure.test.js +0 -51
  86. package/infrastructure/integration.test.js +0 -381
@@ -0,0 +1,148 @@
1
+ /**
2
+ * The app scaffolded by `frigg init` must deploy with no always-on AWS cost.
3
+ *
4
+ * Scaffolds the backend template, loads its Definition and composes it the way
5
+ * `frigg deploy` does (AWS discovery stubbed), then asserts the template has
6
+ * no VPC, NAT gateway, Elastic IP, VPC endpoint or RDS/Aurora resource, that
7
+ * no Lambda is attached to a VPC, and that field-level encryption still gets
8
+ * its KMS key.
9
+ */
10
+
11
+ const os = require('os');
12
+ const path = require('path');
13
+ const fs = require('fs-extra');
14
+
15
+ jest.mock('../domains/shared/resource-discovery', () => ({
16
+ ...jest.requireActual('../domains/shared/resource-discovery'),
17
+ gatherDiscoveredResources: jest.fn(),
18
+ }));
19
+ jest.mock('../domains/shared/utilities/prisma-layer-manager', () => ({
20
+ ensurePrismaLayerExists: jest.fn().mockResolvedValue(undefined),
21
+ }));
22
+
23
+ const {
24
+ gatherDiscoveredResources,
25
+ } = require('../domains/shared/resource-discovery');
26
+ const { composeServerlessDefinition } = require('../infrastructure-composer');
27
+ const BackendFirstHandler = require('../../frigg-cli/init-command/backend-first-handler');
28
+
29
+ const FORBIDDEN_RESOURCE_TYPES = [
30
+ 'AWS::EC2::VPC',
31
+ 'AWS::EC2::NatGateway',
32
+ 'AWS::EC2::EIP',
33
+ 'AWS::EC2::VPCEndpoint',
34
+ 'AWS::RDS::DBCluster',
35
+ 'AWS::RDS::DBInstance',
36
+ 'AWS::RDS::DBSubnetGroup',
37
+ ];
38
+
39
+ // An account that already holds a default VPC, subnets, a NAT gateway and an
40
+ // Aurora cluster: none of it may leak into the scaffolded app's template.
41
+ const BUSY_ACCOUNT_DISCOVERY = {
42
+ defaultVpcId: 'vpc-123456',
43
+ vpcCidr: '172.31.0.0/16',
44
+ defaultSecurityGroupId: 'sg-123456',
45
+ privateSubnetId1: 'subnet-123456',
46
+ privateSubnetId2: 'subnet-789012',
47
+ publicSubnetId1: 'subnet-public-1',
48
+ publicSubnetId2: 'subnet-public-2',
49
+ defaultRouteTableId: 'rtb-123456',
50
+ existingNatGatewayId: 'nat-default123',
51
+ auroraClusterEndpoint: 'c.cluster-abc123.us-east-1.rds.amazonaws.com',
52
+ auroraPort: 5432,
53
+ auroraEngine: 'aurora-postgresql',
54
+ };
55
+
56
+ describe('frigg init default infrastructure', () => {
57
+ let tmpDir;
58
+ let Definition;
59
+ let logSpy;
60
+
61
+ beforeAll(async () => {
62
+ logSpy = jest.spyOn(console, 'log').mockImplementation();
63
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-default-infra-'));
64
+ const target = path.join(tmpDir, 'demo-app');
65
+ await new BackendFirstHandler(target, {
66
+ yes: true,
67
+ install: false,
68
+ git: false,
69
+ }).initialize();
70
+ ({ Definition } = require(path.join(target, 'index.js')));
71
+ });
72
+
73
+ afterAll(() => {
74
+ fs.removeSync(tmpDir);
75
+ logSpy.mockRestore();
76
+ });
77
+
78
+ beforeEach(() => {
79
+ delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
80
+ process.argv = ['node', 'test'];
81
+ });
82
+
83
+ const compose = async (discovery) => {
84
+ gatherDiscoveredResources.mockResolvedValue(discovery);
85
+ // The composer mutates nested parts of the definition.
86
+ return composeServerlessDefinition(
87
+ JSON.parse(JSON.stringify(Definition))
88
+ );
89
+ };
90
+
91
+ const resourceTypes = (definition) =>
92
+ Object.values(definition.resources.Resources).map((r) => r.Type);
93
+
94
+ it('passes the app-definition schema', () => {
95
+ const { validateAppDefinition } = require('@friggframework/schemas');
96
+ expect(validateAppDefinition(Definition).valid).toBe(true);
97
+ });
98
+
99
+ it.each([
100
+ ['an empty account', {}],
101
+ ['an account with existing VPC/NAT/Aurora', BUSY_ACCOUNT_DISCOVERY],
102
+ ])('composes no always-on resources in %s', async (_label, discovery) => {
103
+ const definition = await compose(discovery);
104
+ const types = resourceTypes(definition);
105
+
106
+ for (const forbidden of FORBIDDEN_RESOURCE_TYPES) {
107
+ expect(types).not.toContain(forbidden);
108
+ }
109
+
110
+ // No Lambda is attached to a VPC.
111
+ expect(definition.provider.vpc).toBeUndefined();
112
+ for (const fn of Object.values(definition.functions)) {
113
+ expect(fn.vpc).toBeUndefined();
114
+ }
115
+ for (const resource of Object.values(definition.resources.Resources)) {
116
+ expect(resource.Properties?.VpcConfig).toBeUndefined();
117
+ }
118
+ });
119
+
120
+ it('keeps field-level encryption on with a per-stage KMS key', async () => {
121
+ const definition = await compose({});
122
+
123
+ expect(definition.resources.Resources.FriggKMSKey.Type).toBe(
124
+ 'AWS::KMS::Key'
125
+ );
126
+ expect(definition.provider.environment.KMS_KEY_ARN).toEqual({
127
+ 'Fn::GetAtt': ['FriggKMSKey', 'Arn'],
128
+ });
129
+ });
130
+
131
+ it('connects to the external database through DATABASE_URL', async () => {
132
+ const definition = await compose({});
133
+
134
+ expect(definition.provider.environment.DATABASE_URL).toBe(
135
+ "${env:DATABASE_URL, ''}"
136
+ );
137
+ expect(definition.provider.environment.DB_TYPE).toBe('postgresql');
138
+ expect(definition.resources.Resources.FriggDBSecret).toBeUndefined();
139
+ });
140
+
141
+ it('expires Lambda logs after 14 days', async () => {
142
+ // Without provider.logRetentionInDays, osls creates log groups that
143
+ // never expire, so CloudWatch storage grows forever.
144
+ const definition = await compose({});
145
+
146
+ expect(definition.provider.logRetentionInDays).toBe(14);
147
+ });
148
+ });
@@ -5,6 +5,17 @@
5
5
  * valid, consistent CloudFormation templates.
6
6
  */
7
7
 
8
+ // Never touch AWS or the real Prisma layer from a unit test: discovery returns
9
+ // nothing (a fresh account), and the layer build (npm install into
10
+ // layers/prisma) is stubbed out.
11
+ jest.mock('../domains/shared/resource-discovery', () => ({
12
+ ...jest.requireActual('../domains/shared/resource-discovery'),
13
+ gatherDiscoveredResources: jest.fn().mockResolvedValue({}),
14
+ }));
15
+ jest.mock('../domains/shared/utilities/prisma-layer-manager', () => ({
16
+ ensurePrismaLayerExists: jest.fn().mockResolvedValue(undefined),
17
+ }));
18
+
8
19
  const { composeServerlessDefinition } = require('../infrastructure-composer');
9
20
 
10
21
  describe('CloudFormation Template Generation', () => {
@@ -86,11 +97,16 @@ describe('CloudFormation Template Generation', () => {
86
97
 
87
98
  // Framework-generated resources (created by Serverless Framework, not our builders)
88
99
  const frameworkResources = ['HttpApi', 'HttpApiLogGroup'];
100
+ // Serverless names each function's resource `<Name>LambdaFunction`
101
+ // (e.g. dbMigrationWorker -> DbMigrationWorkerLambdaFunction).
102
+ const functionResources = Object.keys(result.functions || {}).map(
103
+ (name) => `${name.charAt(0).toUpperCase()}${name.slice(1)}LambdaFunction`
104
+ );
89
105
 
90
- // Verify all Refs point to existing resources, layers, or framework resources
106
+ // Verify all Refs point to existing resources, layers, functions or framework resources
91
107
  refs.forEach(ref => {
92
108
  if (!frameworkResources.includes(ref)) {
93
- expect(allIds).toContain(ref);
109
+ expect([...allIds, ...functionResources]).toContain(ref);
94
110
  }
95
111
  });
96
112
  });
@@ -123,7 +139,9 @@ describe('CloudFormation Template Generation', () => {
123
139
  integrations: [
124
140
  { Definition: { name: 'slack' } }
125
141
  ],
126
- vpc: { enable: true },
142
+ // Discovery is stubbed to an empty account, so the VPC must be
143
+ // created explicitly; `auto` with no VPC found is a hard error.
144
+ vpc: { enable: true, management: 'create-new' },
127
145
  encryption: { fieldLevelEncryptionMethod: 'kms' }
128
146
  };
129
147
 
@@ -251,7 +269,9 @@ describe('CloudFormation Template Generation', () => {
251
269
  it('should create VPC resources when enabled', async () => {
252
270
  const appDefinition = {
253
271
  name: 'test-app',
254
- vpc: { enable: true },
272
+ // Discovery is stubbed to an empty account, so the VPC must be
273
+ // created explicitly; `auto` with no VPC found is a hard error.
274
+ vpc: { enable: true, management: 'create-new' },
255
275
  integrations: []
256
276
  };
257
277
 
@@ -264,7 +284,9 @@ describe('CloudFormation Template Generation', () => {
264
284
  it('should create subnets in VPC', async () => {
265
285
  const appDefinition = {
266
286
  name: 'test-app',
267
- vpc: { enable: true },
287
+ // Discovery is stubbed to an empty account, so the VPC must be
288
+ // created explicitly; `auto` with no VPC found is a hard error.
289
+ vpc: { enable: true, management: 'create-new' },
268
290
  integrations: []
269
291
  };
270
292
 
@@ -277,7 +299,9 @@ describe('CloudFormation Template Generation', () => {
277
299
  it('should create security group in VPC', async () => {
278
300
  const appDefinition = {
279
301
  name: 'test-app',
280
- vpc: { enable: true },
302
+ // Discovery is stubbed to an empty account, so the VPC must be
303
+ // created explicitly; `auto` with no VPC found is a hard error.
304
+ vpc: { enable: true, management: 'create-new' },
281
305
  integrations: []
282
306
  };
283
307
 
@@ -290,7 +314,9 @@ describe('CloudFormation Template Generation', () => {
290
314
  it('should configure Lambda functions with VPC', async () => {
291
315
  const appDefinition = {
292
316
  name: 'test-app',
293
- vpc: { enable: true },
317
+ // Discovery is stubbed to an empty account, so the VPC must be
318
+ // created explicitly; `auto` with no VPC found is a hard error.
319
+ vpc: { enable: true, management: 'create-new' },
294
320
  integrations: [
295
321
  { Definition: { name: 'slack' } }
296
322
  ]
@@ -427,7 +453,9 @@ describe('CloudFormation Template Generation', () => {
427
453
  { Definition: { name: 'slack' } },
428
454
  { Definition: { name: 'hubspot' } }
429
455
  ],
430
- vpc: { enable: true },
456
+ // Discovery is stubbed to an empty account, so the VPC must be
457
+ // created explicitly; `auto` with no VPC found is a hard error.
458
+ vpc: { enable: true, management: 'create-new' },
431
459
  encryption: { useDefaultKMSForFieldLevelEncryption: true },
432
460
  database: {
433
461
  type: 'postgresql',
@@ -3,7 +3,6 @@ const fs = require('fs-extra');
3
3
  const crypto = require('crypto');
4
4
  const { composeServerlessDefinition } = require('./infrastructure-composer');
5
5
  const { findNearestBackendPackageJson } = require('@friggframework/core');
6
- const { applyAppDefinitionDefaults } = require('@friggframework/schemas');
7
6
 
8
7
  // Filesystem-based cache to persist across osls require cache clears
9
8
  const getCachePath = (backendDir) => {
@@ -103,9 +102,7 @@ async function createFriggInfrastructure() {
103
102
 
104
103
  try {
105
104
  const backend = require(backendFilePath);
106
- // Same defaults step as core's loadAppDefinition (ADR-051), so the
107
- // builders and the runtime see the same definition.
108
- const appDefinition = applyAppDefinitionDefaults(backend.Definition);
105
+ const appDefinition = backend.Definition;
109
106
 
110
107
  const definition = await composeServerlessDefinition(
111
108
  appDefinition,
@@ -8,29 +8,45 @@ Frigg Framework supports automatic provisioning of Amazon Aurora Serverless v2 P
8
8
 
9
9
  ### Key Features
10
10
 
11
- - **Aurora Serverless v2**: Cost-efficient auto-scaling database (0.5-4 ACU default)
11
+ - **Aurora Serverless v2**: Cost-efficient auto-scaling database (0.5-1.0 ACU default)
12
12
  - **VPC Integration**: Deployed in same private subnets as Lambda functions
13
13
  - **Secrets Manager**: Automatic credential management and rotation
14
- - **Three Management Modes**: discover, managed, use-existing
14
+ - **Management Modes**: discover, create-new, use-existing, external (bring your own `DATABASE_URL`)
15
15
  - **Security**: Private subnet deployment with security group isolation
16
16
  - **High Availability**: Multi-AZ deployment with automatic failover
17
17
 
18
+ ### Bring your own PostgreSQL (`management: 'external'`)
19
+
20
+ To connect to a PostgreSQL that Frigg does not manage (any hosted provider, or
21
+ a database you run yourself), set `management: 'external'`. Frigg then creates
22
+ and discovers no database resources (no RDS/Aurora, no Secrets Manager secret)
23
+ and needs no VPC for the database; the app connects through `DATABASE_URL`.
24
+ This check takes precedence over a top-level `managementMode`. The migration
25
+ infrastructure is still composed, so migrations run against `DATABASE_URL`.
26
+
27
+ ```javascript
28
+ const appDefinition = {
29
+ vpc: { enable: false },
30
+ database: { postgres: { enable: true, management: 'external' } },
31
+ environment: { DATABASE_URL: true }, // read from the shell that runs `frigg deploy` (not .env)
32
+ };
33
+ ```
34
+
35
+ Use `sslmode=require` in the URL. This is the default for apps scaffolded by
36
+ `frigg init`.
37
+
18
38
  ---
19
39
 
20
40
  ## Configuration Schema
21
41
 
22
42
  ### App Definition Structure
23
43
 
24
- These are the keys the Aurora builder reads (see `database.postgres` in
25
- `packages/schemas/schemas/app-definition.schema.json`). `frigg validate`
26
- rejects any other key under `database.postgres`.
27
-
28
44
  ```javascript
29
45
  // backend/index.js
30
46
  const appDefinition = {
31
47
  name: 'my-frigg-app',
32
48
 
33
- // VPC Configuration (required for Aurora)
49
+ // Enable VPC deployment (required for Aurora)
34
50
  vpc: {
35
51
  enable: true,
36
52
  },
@@ -40,24 +56,34 @@ const appDefinition = {
40
56
  postgres: {
41
57
  enable: true,
42
58
 
43
- // 'discover' (also when omitted) | 'managed' | 'use-existing'
44
- // Ignored when managementMode is 'managed' or 'existing'.
59
+ // Management mode: 'discover' | 'create-new' | 'use-existing'
45
60
  management: 'discover',
46
61
 
47
- database: 'frigg', // database name (default 'frigg')
48
- username: 'postgres', // master user (default 'postgres')
49
- engineVersion: '15.13', // Aurora PostgreSQL version (default '15.13')
62
+ // Basic Configuration
63
+ databaseName: 'frigg_db',
64
+ masterUsername: 'frigg_admin',
65
+
66
+ // Engine Configuration
67
+ engine: 'aurora-postgresql',
68
+ engineVersion: '15.3',
69
+
70
+ // Scaling Configuration (Aurora Serverless v2)
71
+ scaling: {
72
+ minCapacity: 0.5, // ACUs (0.5 = ~1GB RAM, ~$43/month)
73
+ maxCapacity: 1.0, // ACUs (1.0 = ~2GB RAM, ~$87/month)
74
+ },
50
75
 
51
- // Aurora Serverless v2 capacity, in ACUs (0.5-128)
52
- minCapacity: 0.5, // default 0.5
53
- maxCapacity: 4, // default 4
76
+ // Backup Configuration
77
+ backupRetentionDays: 7,
78
+ preferredBackupWindow: '03:00-04:00',
54
79
 
55
- publiclyAccessible: false, // default false (private subnets)
56
- autoCreateCredentials: false, // discover only: create a secret for a discovered cluster
80
+ // Security & Advanced
81
+ deletionProtection: true,
82
+ enablePerformanceInsights: false,
57
83
 
58
- // use-existing only
59
- // endpoint: 'mydb.cluster-abc123.us-east-1.rds.amazonaws.com',
60
- // port: 5432,
84
+ // For use-existing mode
85
+ clusterIdentifier: 'my-existing-cluster',
86
+ secretArn: 'arn:aws:secretsmanager:...',
61
87
  }
62
88
  }
63
89
  };
@@ -67,17 +93,13 @@ module.exports = {
67
93
  };
68
94
  ```
69
95
 
70
- Backup retention (7 days), the backup and maintenance windows and deletion
71
- settings are fixed by the builder and are not configurable through the app
72
- definition.
73
-
74
96
  ---
75
97
 
76
98
  ## Management Modes
77
99
 
78
100
  ### 1. Discover Mode (Default)
79
101
 
80
- Discovers an existing Aurora cluster, or creates a new one in the stack if none is found.
102
+ Automatically discovers existing Aurora clusters or creates new one if none found.
81
103
 
82
104
  ```javascript
83
105
  database: {
@@ -98,56 +120,63 @@ database: {
98
120
 
99
121
  ---
100
122
 
101
- ### 2. Managed Mode
123
+ ### 2. Create-New Mode
102
124
 
103
- Creates the cluster, instance, subnet group and secret in the stack.
125
+ Always creates a new Aurora cluster, even if existing clusters are found.
104
126
 
105
127
  ```javascript
106
128
  database: {
107
129
  postgres: {
108
130
  enable: true,
109
- management: 'managed',
110
- minCapacity: 1,
111
- maxCapacity: 2,
131
+ management: 'create-new',
132
+
133
+ // Customization options
134
+ databaseName: 'my_app_db',
135
+ masterUsername: 'admin',
136
+ engineVersion: '15.3',
137
+ scaling: {
138
+ minCapacity: 1.0,
139
+ maxCapacity: 2.0,
140
+ },
141
+ backupRetentionDays: 14,
142
+ deletionProtection: true,
112
143
  }
113
144
  }
114
145
  ```
115
146
 
116
- With the top-level `managementMode: 'managed'` (and `vpcIsolation: 'isolated'`),
117
- Frigg manages the database per stage and `database.postgres.management` is ignored.
118
-
119
147
  **Best For**: Production environments where you want dedicated database resources.
120
148
 
121
149
  ---
122
150
 
123
151
  ### 3. Use-Existing Mode
124
152
 
125
- Connects to an existing PostgreSQL endpoint without creating database resources.
153
+ Uses a specific existing Aurora cluster by identifier.
126
154
 
127
155
  ```javascript
128
156
  database: {
129
157
  postgres: {
130
158
  enable: true,
131
159
  management: 'use-existing',
132
- endpoint: 'my-cluster.cluster-abc123.us-east-1.rds.amazonaws.com', // required
133
- port: 5432,
134
- database: 'frigg_db',
135
- username: 'frigg_admin',
160
+
161
+ // Required: existing cluster identifier
162
+ clusterIdentifier: 'my-existing-aurora-cluster',
163
+
164
+ // Optional: secret ARN (discovered if not provided)
165
+ secretArn: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:my-db-secret',
166
+
167
+ // Database name to connect to
168
+ databaseName: 'frigg_db',
136
169
  }
137
170
  }
138
171
  ```
139
172
 
140
- To use an existing cluster by identifier instead, use the ownership form:
141
- `ownership: { cluster: 'external', instance: 'external' }` with
142
- `external: { clusterIdentifier, instanceIdentifier, secretArn }`.
143
-
144
173
  **Best For**: Shared database scenarios or when you manage Aurora outside of Frigg.
145
174
 
146
175
  ---
147
176
 
148
177
  ## Created AWS Resources
149
178
 
150
- When provisioning Aurora (`managed`, or `discover` mode without an existing cluster), Frigg creates:
179
+ When provisioning Aurora (`create-new` or `discover` mode without existing cluster), Frigg creates:
151
180
 
152
181
  ### 1. RDS DB Subnet Group
153
182
  - **Name**: `{service}-{stage}-db-subnet-group`
@@ -212,15 +241,17 @@ database: {
212
241
  database: {
213
242
  postgres: {
214
243
  enable: true,
215
- minCapacity: 1, // Higher baseline for production
216
- maxCapacity: 4, // Handle traffic spikes
244
+ scaling: {
245
+ minCapacity: 1.0, // Higher baseline for production
246
+ maxCapacity: 4.0, // Handle traffic spikes
247
+ },
248
+ backupRetentionDays: 30, // Longer retention
249
+ enablePerformanceInsights: true, // Monitoring
250
+ deletionProtection: true, // Prevent accidental deletion
217
251
  }
218
252
  }
219
253
  ```
220
254
 
221
- Backup retention, Performance Insights and deletion protection are not
222
- configurable through the app definition; change them on the cluster.
223
-
224
255
  **Estimated Monthly Costs**:
225
256
  - **Baseline**: $87/month (1.0 ACU minimum)
226
257
  - **Peak Traffic**: $348/month (4.0 ACU maximum)
@@ -265,9 +296,15 @@ const users = await prismaClient.user.findMany();
265
296
 
266
297
  ### 4. Deletion Protection
267
298
 
268
- Deletion protection is not configurable through the app definition. Enable it
269
- on the cluster in the AWS console (or with the AWS CLI); you must then disable
270
- it before deleting the stack.
299
+ ```javascript
300
+ database: {
301
+ postgres: {
302
+ deletionProtection: true, // Prevents accidental deletion
303
+ }
304
+ }
305
+ ```
306
+
307
+ **Important**: When enabled, you must manually disable deletion protection in AWS console before stack deletion.
271
308
 
272
309
  ---
273
310
 
@@ -367,7 +404,7 @@ DB_TYPE=postgresql
367
404
  database: {
368
405
  postgres: {
369
406
  enable: true,
370
- management: 'managed',
407
+ management: 'create-new',
371
408
  }
372
409
  }
373
410
  ```
@@ -394,7 +431,7 @@ DB_TYPE=postgresql
394
431
  database: {
395
432
  postgres: {
396
433
  enable: true,
397
- management: 'managed',
434
+ management: 'create-new',
398
435
  }
399
436
  }
400
437
  ```
@@ -439,13 +476,13 @@ DB_TYPE=postgresql
439
476
 
440
477
  **Error**:
441
478
  ```
442
- No Aurora cluster found in discovery mode. Set management to "managed" or provide endpoint with "use-existing".
479
+ No Aurora cluster found in discovery mode. Set management to "create-new"...
443
480
  ```
444
481
 
445
482
  **Solution**:
446
483
  1. Check VPC is enabled: `vpc.enable: true`
447
- 2. Set management mode: `management: 'managed'`
448
- 3. Or connect to a known endpoint: `management: 'use-existing'`, `endpoint: '...'`
484
+ 2. Set management mode: `management: 'create-new'`
485
+ 3. Or provide cluster identifier: `clusterIdentifier: 'my-cluster'`
449
486
 
450
487
  ---
451
488
 
@@ -527,19 +564,40 @@ Cannot create Aurora cluster: InsufficientDBInstanceCapacity
527
564
 
528
565
  ## Advanced Configuration
529
566
 
530
- ### Custom Engine Version
567
+ ### Custom Backup Window
568
+
569
+ ```javascript
570
+ database: {
571
+ postgres: {
572
+ enable: true,
573
+ backupRetentionDays: 30,
574
+ preferredBackupWindow: '02:00-03:00', // UTC
575
+ }
576
+ }
577
+ ```
578
+
579
+ ### Enhanced Monitoring
531
580
 
532
581
  ```javascript
533
582
  database: {
534
583
  postgres: {
535
584
  enable: true,
536
- engineVersion: '16.4', // Default: 15.13
585
+ enablePerformanceInsights: true,
586
+ // Performance Insights retention: 7 days (default) or 731 days
537
587
  }
538
588
  }
539
589
  ```
540
590
 
541
- The backup window, backup retention and Performance Insights are set by the
542
- builder and are not configurable through the app definition.
591
+ ### Custom Engine Version
592
+
593
+ ```javascript
594
+ database: {
595
+ postgres: {
596
+ enable: true,
597
+ engineVersion: '14.6', // Default: 15.3
598
+ }
599
+ }
600
+ ```
543
601
 
544
602
  ### Read Replicas (Not Supported Yet)
545
603
 
@@ -64,7 +64,18 @@ class AuroraBuilder extends InfrastructureBuilder {
64
64
  return false;
65
65
  }
66
66
 
67
- return appDefinition.database?.postgres?.enable === true;
67
+ const postgres = appDefinition.database?.postgres;
68
+
69
+ // management='external': the app brings its own PostgreSQL (any
70
+ // provider) and connects through DATABASE_URL. Frigg creates and
71
+ // discovers no database resources and needs no VPC for it. This
72
+ // check precedes managementMode, which otherwise always manages
73
+ // Aurora. Migrations still run (MigrationBuilder) against DATABASE_URL.
74
+ if (postgres?.management === 'external') {
75
+ return false;
76
+ }
77
+
78
+ return postgres?.enable === true;
68
79
  }
69
80
 
70
81
  getDependencies() {
@@ -82,7 +93,7 @@ class AuroraBuilder extends InfrastructureBuilder {
82
93
  const dbConfig = appDefinition.database.postgres;
83
94
 
84
95
  // Validate management mode
85
- const validModes = ['discover', 'managed', 'use-existing'];
96
+ const validModes = ['discover', 'managed', 'use-existing', 'external'];
86
97
  const management = dbConfig.management || 'discover';
87
98
  if (!validModes.includes(management)) {
88
99
  result.addError(`Invalid database.postgres.management: "${management}"`);
@@ -42,6 +42,28 @@ describe('AuroraBuilder', () => {
42
42
  expect(auroraBuilder.shouldExecute(appDefinition)).toBe(false);
43
43
  });
44
44
 
45
+ it('should return false when Postgres is external (bring your own DATABASE_URL)', () => {
46
+ const appDefinition = {
47
+ database: {
48
+ postgres: { enable: true, management: 'external' },
49
+ },
50
+ };
51
+
52
+ expect(auroraBuilder.shouldExecute(appDefinition)).toBe(false);
53
+ });
54
+
55
+ it('should return false for external Postgres even with managementMode=managed', () => {
56
+ const appDefinition = {
57
+ managementMode: 'managed',
58
+ vpcIsolation: 'isolated',
59
+ database: {
60
+ postgres: { enable: true, management: 'external' },
61
+ },
62
+ };
63
+
64
+ expect(auroraBuilder.shouldExecute(appDefinition)).toBe(false);
65
+ });
66
+
45
67
  it('should return false when database is not defined', () => {
46
68
  const appDefinition = {};
47
69