s9n-devops-agent 2.0.13 → 2.0.18-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/House_Rules_Contracts/API_CONTRACT.md +612 -0
- package/House_Rules_Contracts/DATABASE_SCHEMA_CONTRACT.md +373 -0
- package/House_Rules_Contracts/DEVOPS_AGENT_INSTRUCTIONS.md +743 -0
- package/House_Rules_Contracts/FEATURES_CONTRACT.md +655 -0
- package/House_Rules_Contracts/INFRA_CONTRACT.md +638 -0
- package/House_Rules_Contracts/README.md +671 -0
- package/House_Rules_Contracts/SQL_CONTRACT.json +346 -0
- package/House_Rules_Contracts/THIRD_PARTY_INTEGRATIONS.md +604 -0
- package/bin/cs-devops-agent +20 -2
- package/houserules.md +1412 -0
- package/houserules_structured.md +1442 -0
- package/package.json +6 -2
- package/scripts/generate-ai-commit.js +135 -0
- package/scripts/local-install.sh +42 -0
- package/src/agent-chat.js +457 -0
- package/src/credentials-manager.js +1 -1
- package/src/cs-devops-agent-worker.js +84 -4
- package/src/house-rules-manager.js +4 -14
- package/src/instruction-formatter.js +9 -1
- package/src/session-coordinator.js +170 -15
- package/src/setup-cs-devops-agent.js +214 -236
- package/src/worktree-manager.js +2 -1
- package/start-devops-session.sh +9 -2
|
@@ -0,0 +1,638 @@
|
|
|
1
|
+
# Infrastructure Contract
|
|
2
|
+
|
|
3
|
+
**Last Updated:** 2024-12-02
|
|
4
|
+
**Version:** 1.0.0
|
|
5
|
+
**Status:** Initial Template
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Purpose
|
|
10
|
+
|
|
11
|
+
This contract documents **all infrastructure configuration, environment variables, and deployment settings**. Coding agents **MUST check this file before adding configuration** to:
|
|
12
|
+
- **Prevent duplicate environment variables**
|
|
13
|
+
- **Maintain single source of truth** for all config
|
|
14
|
+
- **Avoid configuration conflicts** between modules
|
|
15
|
+
- **Ensure consistent naming conventions**
|
|
16
|
+
- **Prevent multiple versions** of the same config
|
|
17
|
+
- **Centralize secrets management**
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Change Log
|
|
22
|
+
|
|
23
|
+
| Date | Version | Agent/Author | Changes | Impact |
|
|
24
|
+
|------|---------|--------------|---------|--------|
|
|
25
|
+
| 2024-12-02 | 1.0.0 | DevOps Agent | Initial template creation | N/A - Template only |
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Environment Variables
|
|
30
|
+
|
|
31
|
+
### Variable Naming Convention
|
|
32
|
+
|
|
33
|
+
**Format:** `[CATEGORY]_[SUBCATEGORY]_[NAME]`
|
|
34
|
+
|
|
35
|
+
**Examples:**
|
|
36
|
+
- `DATABASE_PRIMARY_URL`
|
|
37
|
+
- `REDIS_CACHE_URL`
|
|
38
|
+
- `AWS_S3_BUCKET_NAME`
|
|
39
|
+
- `SENDGRID_API_KEY`
|
|
40
|
+
- `JWT_SECRET_KEY`
|
|
41
|
+
- `FEATURE_AUTH_ENABLED`
|
|
42
|
+
|
|
43
|
+
**Categories:**
|
|
44
|
+
- `DATABASE_*` - Database connections
|
|
45
|
+
- `REDIS_*` - Redis/caching
|
|
46
|
+
- `AWS_*` - AWS services
|
|
47
|
+
- `[SERVICE]_*` - Third-party services (SENDGRID_, STRIPE_, etc.)
|
|
48
|
+
- `JWT_*` - Authentication/JWT
|
|
49
|
+
- `API_*` - API configuration
|
|
50
|
+
- `FEATURE_*` - Feature flags
|
|
51
|
+
- `LOG_*` - Logging configuration
|
|
52
|
+
- `SMTP_*` - Email configuration
|
|
53
|
+
- `APP_*` - Application settings
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
### Core Application Variables
|
|
58
|
+
|
|
59
|
+
| Variable | Type | Required | Default | Description | Example | Used By |
|
|
60
|
+
|----------|------|----------|---------|-------------|---------|---------|
|
|
61
|
+
| `NODE_ENV` | string | YES | `development` | Environment name | `production`, `staging`, `development` | All modules |
|
|
62
|
+
| `APP_NAME` | string | YES | - | Application name | `MyApp` | Logging, emails |
|
|
63
|
+
| `APP_VERSION` | string | NO | `1.0.0` | Application version | `1.2.3` | Monitoring, headers |
|
|
64
|
+
| `APP_URL` | string | YES | - | Application base URL | `https://app.example.com` | Email links, redirects |
|
|
65
|
+
| `APP_PORT` | integer | YES | `3000` | Server port | `3000`, `8080` | Server startup |
|
|
66
|
+
| `APP_HOST` | string | NO | `0.0.0.0` | Server host | `0.0.0.0`, `localhost` | Server binding |
|
|
67
|
+
|
|
68
|
+
**Added:** 2024-01-15
|
|
69
|
+
**Last Modified:** 2024-01-15
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
### Database Configuration
|
|
74
|
+
|
|
75
|
+
| Variable | Type | Required | Default | Description | Example | Used By |
|
|
76
|
+
|----------|------|----------|---------|-------------|---------|---------|
|
|
77
|
+
| `DATABASE_URL` | string | YES | - | Primary database connection string | `postgresql://user:pass@host:5432/db` | All DB modules |
|
|
78
|
+
| `DATABASE_HOST` | string | NO | `localhost` | Database host | `db.example.com` | DB connection |
|
|
79
|
+
| `DATABASE_PORT` | integer | NO | `5432` | Database port | `5432` (PostgreSQL) | DB connection |
|
|
80
|
+
| `DATABASE_NAME` | string | NO | - | Database name | `myapp_production` | DB connection |
|
|
81
|
+
| `DATABASE_USER` | string | NO | - | Database username | `dbuser` | DB connection |
|
|
82
|
+
| `DATABASE_PASSWORD` | string | NO | - | Database password | `securepass123` | DB connection |
|
|
83
|
+
| `DATABASE_POOL_MIN` | integer | NO | `2` | Min connection pool size | `2` | Connection pooling |
|
|
84
|
+
| `DATABASE_POOL_MAX` | integer | NO | `20` | Max connection pool size | `20` | Connection pooling |
|
|
85
|
+
| `DATABASE_SSL` | boolean | NO | `true` | Enable SSL connection | `true`, `false` | DB connection |
|
|
86
|
+
|
|
87
|
+
**Added:** 2024-01-15
|
|
88
|
+
**Last Modified:** 2024-01-15
|
|
89
|
+
**See Also:** DATABASE_SCHEMA_CONTRACT.md
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
### Redis / Caching Configuration
|
|
94
|
+
|
|
95
|
+
| Variable | Type | Required | Default | Description | Example | Used By |
|
|
96
|
+
|----------|------|----------|---------|-------------|---------|---------|
|
|
97
|
+
| `REDIS_URL` | string | YES | - | Redis connection string | `redis://user:pass@host:6379` | Caching, sessions |
|
|
98
|
+
| `REDIS_HOST` | string | NO | `localhost` | Redis host | `redis.example.com` | Redis connection |
|
|
99
|
+
| `REDIS_PORT` | integer | NO | `6379` | Redis port | `6379` | Redis connection |
|
|
100
|
+
| `REDIS_PASSWORD` | string | NO | - | Redis password | `redispass123` | Redis connection |
|
|
101
|
+
| `REDIS_DB` | integer | NO | `0` | Redis database number | `0`, `1`, `2` | Redis connection |
|
|
102
|
+
| `CACHE_TTL` | integer | NO | `300` | Default cache TTL (seconds) | `300` (5 minutes) | Caching layer |
|
|
103
|
+
| `CACHE_ENABLED` | boolean | NO | `true` | Enable caching | `true`, `false` | Caching layer |
|
|
104
|
+
|
|
105
|
+
**Added:** 2024-01-15
|
|
106
|
+
**Last Modified:** 2024-01-15
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
### Authentication / JWT Configuration
|
|
111
|
+
|
|
112
|
+
| Variable | Type | Required | Default | Description | Example | Used By |
|
|
113
|
+
|----------|------|----------|---------|-------------|---------|---------|
|
|
114
|
+
| `JWT_SECRET` | string | YES | - | JWT signing secret | `your-256-bit-secret` | Auth module |
|
|
115
|
+
| `JWT_EXPIRATION` | string | NO | `24h` | JWT token expiration | `24h`, `7d`, `3600` (seconds) | Auth module |
|
|
116
|
+
| `JWT_REFRESH_EXPIRATION` | string | NO | `7d` | Refresh token expiration | `7d`, `30d` | Auth module |
|
|
117
|
+
| `JWT_ALGORITHM` | string | NO | `HS256` | JWT signing algorithm | `HS256`, `RS256` | Auth module |
|
|
118
|
+
| `PASSWORD_RESET_EXPIRATION` | integer | NO | `3600` | Password reset token TTL (seconds) | `3600` (1 hour) | Auth module |
|
|
119
|
+
| `MAX_LOGIN_ATTEMPTS` | integer | NO | `5` | Max failed login attempts | `5` | Auth module |
|
|
120
|
+
| `LOCKOUT_DURATION` | integer | NO | `900` | Account lockout duration (seconds) | `900` (15 minutes) | Auth module |
|
|
121
|
+
|
|
122
|
+
**Added:** 2024-01-15
|
|
123
|
+
**Last Modified:** 2024-01-15
|
|
124
|
+
**See Also:** FEATURES_CONTRACT.md (F-001 - User Authentication)
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
### Third-Party Service Configuration
|
|
129
|
+
|
|
130
|
+
#### SendGrid (Email)
|
|
131
|
+
|
|
132
|
+
| Variable | Type | Required | Default | Description | Example | Used By |
|
|
133
|
+
|----------|------|----------|---------|-------------|---------|---------|
|
|
134
|
+
| `SENDGRID_API_KEY` | string | YES | - | SendGrid API key | `SG.xxx...` | Email service |
|
|
135
|
+
| `SENDGRID_FROM_EMAIL` | string | YES | - | Default sender email | `noreply@example.com` | Email service |
|
|
136
|
+
| `SENDGRID_FROM_NAME` | string | NO | `APP_NAME` | Default sender name | `MyApp` | Email service |
|
|
137
|
+
|
|
138
|
+
**Added:** 2024-01-15
|
|
139
|
+
**See Also:** THIRD_PARTY_INTEGRATIONS.md (SendGrid)
|
|
140
|
+
|
|
141
|
+
#### Stripe (Payments)
|
|
142
|
+
|
|
143
|
+
| Variable | Type | Required | Default | Description | Example | Used By |
|
|
144
|
+
|----------|------|----------|---------|-------------|---------|---------|
|
|
145
|
+
| `STRIPE_SECRET_KEY` | string | YES | - | Stripe secret API key | `sk_live_...` | Payment service |
|
|
146
|
+
| `STRIPE_PUBLISHABLE_KEY` | string | YES | - | Stripe publishable key | `pk_live_...` | Frontend |
|
|
147
|
+
| `STRIPE_WEBHOOK_SECRET` | string | YES | - | Stripe webhook secret | `whsec_...` | Webhook handler |
|
|
148
|
+
|
|
149
|
+
**Added:** 2024-01-20
|
|
150
|
+
**See Also:** THIRD_PARTY_INTEGRATIONS.md (Stripe)
|
|
151
|
+
|
|
152
|
+
#### AWS S3 (Storage)
|
|
153
|
+
|
|
154
|
+
| Variable | Type | Required | Default | Description | Example | Used By |
|
|
155
|
+
|----------|------|----------|---------|-------------|---------|---------|
|
|
156
|
+
| `AWS_ACCESS_KEY_ID` | string | YES | - | AWS access key | `AKIAIOSFODNN7EXAMPLE` | S3 service |
|
|
157
|
+
| `AWS_SECRET_ACCESS_KEY` | string | YES | - | AWS secret key | `wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY` | S3 service |
|
|
158
|
+
| `AWS_REGION` | string | YES | - | AWS region | `us-east-1` | S3 service |
|
|
159
|
+
| `AWS_S3_BUCKET` | string | YES | - | S3 bucket name | `myapp-production` | S3 service |
|
|
160
|
+
|
|
161
|
+
**Added:** 2024-01-10
|
|
162
|
+
**See Also:** THIRD_PARTY_INTEGRATIONS.md (AWS S3)
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
### API Configuration
|
|
167
|
+
|
|
168
|
+
| Variable | Type | Required | Default | Description | Example | Used By |
|
|
169
|
+
|----------|------|----------|---------|-------------|---------|---------|
|
|
170
|
+
| `API_VERSION` | string | NO | `v1` | API version prefix | `v1`, `v2` | API routes |
|
|
171
|
+
| `API_RATE_LIMIT_WINDOW` | integer | NO | `3600` | Rate limit window (seconds) | `3600` (1 hour) | Rate limiter |
|
|
172
|
+
| `API_RATE_LIMIT_MAX` | integer | NO | `1000` | Max requests per window | `1000` | Rate limiter |
|
|
173
|
+
| `API_TIMEOUT` | integer | NO | `30000` | API request timeout (ms) | `30000` (30 seconds) | API middleware |
|
|
174
|
+
| `API_CORS_ORIGIN` | string | NO | `*` | CORS allowed origins | `https://example.com` | CORS middleware |
|
|
175
|
+
|
|
176
|
+
**Added:** 2024-01-15
|
|
177
|
+
**Last Modified:** 2024-01-15
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
### Logging Configuration
|
|
182
|
+
|
|
183
|
+
| Variable | Type | Required | Default | Description | Example | Used By |
|
|
184
|
+
|----------|------|----------|---------|-------------|---------|---------|
|
|
185
|
+
| `LOG_LEVEL` | string | NO | `info` | Logging level | `debug`, `info`, `warn`, `error` | Logger |
|
|
186
|
+
| `LOG_FORMAT` | string | NO | `json` | Log output format | `json`, `text` | Logger |
|
|
187
|
+
| `LOG_FILE_PATH` | string | NO | `logs/app.log` | Log file location | `logs/app.log` | File logger |
|
|
188
|
+
| `LOG_MAX_SIZE` | string | NO | `10m` | Max log file size | `10m`, `100m` | Log rotation |
|
|
189
|
+
| `LOG_MAX_FILES` | integer | NO | `7` | Max log files to keep | `7` | Log rotation |
|
|
190
|
+
| `LOG_CONSOLE_ENABLED` | boolean | NO | `true` | Enable console logging | `true`, `false` | Logger |
|
|
191
|
+
|
|
192
|
+
**Added:** 2024-01-15
|
|
193
|
+
**Last Modified:** 2024-01-15
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
### Feature Flags
|
|
198
|
+
|
|
199
|
+
| Variable | Type | Required | Default | Description | Example | Used By |
|
|
200
|
+
|----------|------|----------|---------|-------------|---------|---------|
|
|
201
|
+
| `FEATURE_AUTH_EMAIL_VERIFICATION` | boolean | NO | `true` | Require email verification | `true`, `false` | Auth module |
|
|
202
|
+
| `FEATURE_AUTH_2FA` | boolean | NO | `false` | Enable 2FA | `true`, `false` | Auth module |
|
|
203
|
+
| `FEATURE_SOCIAL_LOGIN` | boolean | NO | `false` | Enable social login | `true`, `false` | Auth module |
|
|
204
|
+
| `FEATURE_[NAME]_ENABLED` | boolean | NO | `false` | Enable specific feature | `true`, `false` | Feature module |
|
|
205
|
+
|
|
206
|
+
**Added:** 2024-01-15
|
|
207
|
+
**Last Modified:** 2024-02-10
|
|
208
|
+
**See Also:** FEATURES_CONTRACT.md
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Configuration Files
|
|
213
|
+
|
|
214
|
+
### Application Configuration
|
|
215
|
+
|
|
216
|
+
**File:** `config/app.js`
|
|
217
|
+
**Purpose:** Main application configuration
|
|
218
|
+
**Environment Variables Used:**
|
|
219
|
+
- `NODE_ENV`
|
|
220
|
+
- `APP_NAME`
|
|
221
|
+
- `APP_VERSION`
|
|
222
|
+
- `APP_URL`
|
|
223
|
+
- `APP_PORT`
|
|
224
|
+
- `APP_HOST`
|
|
225
|
+
|
|
226
|
+
**Structure:**
|
|
227
|
+
```javascript
|
|
228
|
+
module.exports = {
|
|
229
|
+
env: process.env.NODE_ENV || 'development',
|
|
230
|
+
name: process.env.APP_NAME,
|
|
231
|
+
version: process.env.APP_VERSION || '1.0.0',
|
|
232
|
+
url: process.env.APP_URL,
|
|
233
|
+
port: parseInt(process.env.APP_PORT, 10) || 3000,
|
|
234
|
+
host: process.env.APP_HOST || '0.0.0.0'
|
|
235
|
+
};
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
### Database Configuration
|
|
241
|
+
|
|
242
|
+
**File:** `config/database.js`
|
|
243
|
+
**Purpose:** Database connection configuration
|
|
244
|
+
**Environment Variables Used:**
|
|
245
|
+
- `DATABASE_URL`
|
|
246
|
+
- `DATABASE_HOST`
|
|
247
|
+
- `DATABASE_PORT`
|
|
248
|
+
- `DATABASE_NAME`
|
|
249
|
+
- `DATABASE_USER`
|
|
250
|
+
- `DATABASE_PASSWORD`
|
|
251
|
+
- `DATABASE_POOL_MIN`
|
|
252
|
+
- `DATABASE_POOL_MAX`
|
|
253
|
+
- `DATABASE_SSL`
|
|
254
|
+
|
|
255
|
+
**Structure:**
|
|
256
|
+
```javascript
|
|
257
|
+
module.exports = {
|
|
258
|
+
url: process.env.DATABASE_URL,
|
|
259
|
+
host: process.env.DATABASE_HOST || 'localhost',
|
|
260
|
+
port: parseInt(process.env.DATABASE_PORT, 10) || 5432,
|
|
261
|
+
database: process.env.DATABASE_NAME,
|
|
262
|
+
user: process.env.DATABASE_USER,
|
|
263
|
+
password: process.env.DATABASE_PASSWORD,
|
|
264
|
+
pool: {
|
|
265
|
+
min: parseInt(process.env.DATABASE_POOL_MIN, 10) || 2,
|
|
266
|
+
max: parseInt(process.env.DATABASE_POOL_MAX, 10) || 20
|
|
267
|
+
},
|
|
268
|
+
ssl: process.env.DATABASE_SSL === 'true'
|
|
269
|
+
};
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
**See Also:** DATABASE_SCHEMA_CONTRACT.md
|
|
273
|
+
|
|
274
|
+
---
|
|
275
|
+
|
|
276
|
+
### Redis Configuration
|
|
277
|
+
|
|
278
|
+
**File:** `config/redis.js`
|
|
279
|
+
**Purpose:** Redis connection configuration
|
|
280
|
+
**Environment Variables Used:**
|
|
281
|
+
- `REDIS_URL`
|
|
282
|
+
- `REDIS_HOST`
|
|
283
|
+
- `REDIS_PORT`
|
|
284
|
+
- `REDIS_PASSWORD`
|
|
285
|
+
- `REDIS_DB`
|
|
286
|
+
- `CACHE_TTL`
|
|
287
|
+
- `CACHE_ENABLED`
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Environment Files
|
|
292
|
+
|
|
293
|
+
### `.env.example`
|
|
294
|
+
|
|
295
|
+
**Purpose:** Template for environment variables (committed to repo)
|
|
296
|
+
**Location:** Project root
|
|
297
|
+
**Usage:** Copy to `.env` and fill in actual values
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
# Application
|
|
301
|
+
NODE_ENV=development
|
|
302
|
+
APP_NAME=MyApp
|
|
303
|
+
APP_VERSION=1.0.0
|
|
304
|
+
APP_URL=http://localhost:3000
|
|
305
|
+
APP_PORT=3000
|
|
306
|
+
|
|
307
|
+
# Database
|
|
308
|
+
DATABASE_URL=postgresql://user:password@localhost:5432/myapp_dev
|
|
309
|
+
DATABASE_POOL_MIN=2
|
|
310
|
+
DATABASE_POOL_MAX=20
|
|
311
|
+
|
|
312
|
+
# Redis
|
|
313
|
+
REDIS_URL=redis://localhost:6379
|
|
314
|
+
CACHE_TTL=300
|
|
315
|
+
CACHE_ENABLED=true
|
|
316
|
+
|
|
317
|
+
# Authentication
|
|
318
|
+
JWT_SECRET=your-256-bit-secret-change-this
|
|
319
|
+
JWT_EXPIRATION=24h
|
|
320
|
+
MAX_LOGIN_ATTEMPTS=5
|
|
321
|
+
|
|
322
|
+
# SendGrid
|
|
323
|
+
SENDGRID_API_KEY=your-sendgrid-api-key
|
|
324
|
+
SENDGRID_FROM_EMAIL=noreply@example.com
|
|
325
|
+
|
|
326
|
+
# AWS S3
|
|
327
|
+
AWS_ACCESS_KEY_ID=your-aws-access-key
|
|
328
|
+
AWS_SECRET_ACCESS_KEY=your-aws-secret-key
|
|
329
|
+
AWS_REGION=us-east-1
|
|
330
|
+
AWS_S3_BUCKET=myapp-dev
|
|
331
|
+
|
|
332
|
+
# Feature Flags
|
|
333
|
+
FEATURE_AUTH_EMAIL_VERIFICATION=true
|
|
334
|
+
FEATURE_AUTH_2FA=false
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
### `.env` (Local Development)
|
|
340
|
+
|
|
341
|
+
**Purpose:** Local development environment variables (gitignored)
|
|
342
|
+
**Location:** Project root
|
|
343
|
+
**Usage:** Copy from `.env.example` and customize
|
|
344
|
+
|
|
345
|
+
⚠️ **NEVER commit this file to git!**
|
|
346
|
+
|
|
347
|
+
---
|
|
348
|
+
|
|
349
|
+
### `.env.production`
|
|
350
|
+
|
|
351
|
+
**Purpose:** Production environment variables template
|
|
352
|
+
**Location:** Project root or deployment config
|
|
353
|
+
**Usage:** Used by deployment pipeline
|
|
354
|
+
|
|
355
|
+
⚠️ **Contains sensitive data - store in secrets manager!**
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
### `.env.staging`
|
|
360
|
+
|
|
361
|
+
**Purpose:** Staging environment variables template
|
|
362
|
+
**Location:** Project root or deployment config
|
|
363
|
+
**Usage:** Used by staging deployment
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
## Secrets Management
|
|
368
|
+
|
|
369
|
+
### Development
|
|
370
|
+
|
|
371
|
+
**Method:** `.env` file (gitignored)
|
|
372
|
+
**Storage:** Local filesystem
|
|
373
|
+
**Access:** Developers only
|
|
374
|
+
|
|
375
|
+
### Staging
|
|
376
|
+
|
|
377
|
+
**Method:** Environment variables in deployment platform
|
|
378
|
+
**Storage:** Heroku Config Vars / Vercel Environment Variables
|
|
379
|
+
**Access:** DevOps team
|
|
380
|
+
|
|
381
|
+
### Production
|
|
382
|
+
|
|
383
|
+
**Method:** Secrets manager
|
|
384
|
+
**Storage:** AWS Secrets Manager / HashiCorp Vault
|
|
385
|
+
**Access:** Automated deployment pipeline only
|
|
386
|
+
**Rotation:** Quarterly for API keys, monthly for passwords
|
|
387
|
+
|
|
388
|
+
---
|
|
389
|
+
|
|
390
|
+
## Deployment Configuration
|
|
391
|
+
|
|
392
|
+
### Environments
|
|
393
|
+
|
|
394
|
+
| Environment | URL | Branch | Auto-Deploy | Database | Purpose |
|
|
395
|
+
|-------------|-----|--------|-------------|----------|---------|
|
|
396
|
+
| Development | `http://localhost:3000` | - | No | Local | Local dev |
|
|
397
|
+
| Staging | `https://staging.example.com` | `develop` | Yes | Staging DB | Testing |
|
|
398
|
+
| Production | `https://app.example.com` | `main` | No | Production DB | Live users |
|
|
399
|
+
|
|
400
|
+
---
|
|
401
|
+
|
|
402
|
+
### CI/CD Configuration
|
|
403
|
+
|
|
404
|
+
**File:** `.github/workflows/deploy.yml`
|
|
405
|
+
**Purpose:** GitHub Actions deployment workflow
|
|
406
|
+
|
|
407
|
+
**Environment Variables Set in GitHub Secrets:**
|
|
408
|
+
- `DATABASE_URL`
|
|
409
|
+
- `JWT_SECRET`
|
|
410
|
+
- `SENDGRID_API_KEY`
|
|
411
|
+
- `STRIPE_SECRET_KEY`
|
|
412
|
+
- `AWS_ACCESS_KEY_ID`
|
|
413
|
+
- `AWS_SECRET_ACCESS_KEY`
|
|
414
|
+
- All other sensitive variables
|
|
415
|
+
|
|
416
|
+
---
|
|
417
|
+
|
|
418
|
+
### Docker Configuration
|
|
419
|
+
|
|
420
|
+
**File:** `Dockerfile`
|
|
421
|
+
**Purpose:** Container image definition
|
|
422
|
+
|
|
423
|
+
**Environment Variables:**
|
|
424
|
+
- Passed via `docker run -e` or `docker-compose.yml`
|
|
425
|
+
- Never hardcoded in Dockerfile
|
|
426
|
+
|
|
427
|
+
**File:** `docker-compose.yml`
|
|
428
|
+
**Purpose:** Local development with Docker
|
|
429
|
+
|
|
430
|
+
```yaml
|
|
431
|
+
version: '3.8'
|
|
432
|
+
services:
|
|
433
|
+
app:
|
|
434
|
+
build: .
|
|
435
|
+
ports:
|
|
436
|
+
- "${APP_PORT}:3000"
|
|
437
|
+
environment:
|
|
438
|
+
- NODE_ENV=${NODE_ENV}
|
|
439
|
+
- DATABASE_URL=${DATABASE_URL}
|
|
440
|
+
- REDIS_URL=${REDIS_URL}
|
|
441
|
+
- JWT_SECRET=${JWT_SECRET}
|
|
442
|
+
env_file:
|
|
443
|
+
- .env
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
---
|
|
447
|
+
|
|
448
|
+
## Infrastructure Resources
|
|
449
|
+
|
|
450
|
+
### Hosting
|
|
451
|
+
|
|
452
|
+
| Resource | Provider | Plan | Cost | Purpose |
|
|
453
|
+
|----------|----------|------|------|---------|
|
|
454
|
+
| Web Server | Heroku / Vercel | Pro | $X/month | Host application |
|
|
455
|
+
| Database | AWS RDS / Heroku Postgres | Standard | $X/month | PostgreSQL database |
|
|
456
|
+
| Cache | Redis Cloud / Heroku Redis | Standard | $X/month | Redis cache |
|
|
457
|
+
| Storage | AWS S3 | Pay-as-you-go | $X/month | File storage |
|
|
458
|
+
|
|
459
|
+
---
|
|
460
|
+
|
|
461
|
+
### Monitoring & Logging
|
|
462
|
+
|
|
463
|
+
| Resource | Provider | Plan | Cost | Purpose |
|
|
464
|
+
|----------|----------|------|------|---------|
|
|
465
|
+
| Error Tracking | Sentry | Team | $X/month | Error monitoring |
|
|
466
|
+
| Logging | LogDNA / Papertrail | Standard | $X/month | Centralized logs |
|
|
467
|
+
| Uptime Monitoring | Pingdom / UptimeRobot | Pro | $X/month | Uptime checks |
|
|
468
|
+
| Performance | New Relic / DataDog | Standard | $X/month | APM monitoring |
|
|
469
|
+
|
|
470
|
+
---
|
|
471
|
+
|
|
472
|
+
## Notes for Coding Agents
|
|
473
|
+
|
|
474
|
+
### 🚨 CRITICAL RULES:
|
|
475
|
+
|
|
476
|
+
1. **ALWAYS check this contract before adding environment variables**
|
|
477
|
+
2. **NEVER create duplicate environment variables** with different names
|
|
478
|
+
3. **FOLLOW naming convention** - `[CATEGORY]_[SUBCATEGORY]_[NAME]`
|
|
479
|
+
4. **NEVER hardcode secrets** - always use environment variables
|
|
480
|
+
5. **UPDATE this contract immediately** when adding new variables
|
|
481
|
+
6. **CROSS-REFERENCE:**
|
|
482
|
+
- THIRD_PARTY_INTEGRATIONS.md for service API keys
|
|
483
|
+
- FEATURES_CONTRACT.md for feature flags
|
|
484
|
+
- DATABASE_SCHEMA_CONTRACT.md for database config
|
|
485
|
+
7. **ADD to `.env.example`** when adding new required variables
|
|
486
|
+
8. **DOCUMENT default values** and examples
|
|
487
|
+
9. **SPECIFY which modules use** each variable
|
|
488
|
+
10. **INCREMENT version number** for any infrastructure changes
|
|
489
|
+
|
|
490
|
+
### Workflow to Prevent Duplicate Configuration:
|
|
491
|
+
|
|
492
|
+
```
|
|
493
|
+
BEFORE ADDING ANY ENVIRONMENT VARIABLE:
|
|
494
|
+
|
|
495
|
+
1. Read INFRA_CONTRACT.md completely
|
|
496
|
+
2. Search for existing variables by:
|
|
497
|
+
- Category (DATABASE_, REDIS_, AWS_, etc.)
|
|
498
|
+
- Purpose (authentication, caching, storage)
|
|
499
|
+
- Service name (SendGrid, Stripe, etc.)
|
|
500
|
+
|
|
501
|
+
3. If similar variable exists:
|
|
502
|
+
❌ DO NOT create duplicate variable
|
|
503
|
+
✅ USE the existing variable
|
|
504
|
+
✅ ADD your module to "Used By" column
|
|
505
|
+
✅ DOCUMENT your usage
|
|
506
|
+
|
|
507
|
+
4. If variable doesn't exist:
|
|
508
|
+
✅ FOLLOW naming convention
|
|
509
|
+
✅ ADD to appropriate category section
|
|
510
|
+
✅ DOCUMENT type, required, default, description, example
|
|
511
|
+
✅ LIST which modules use it
|
|
512
|
+
✅ ADD to .env.example
|
|
513
|
+
✅ CROSS-REFERENCE related contracts
|
|
514
|
+
✅ INCREMENT version number
|
|
515
|
+
✅ ADD changelog entry
|
|
516
|
+
|
|
517
|
+
5. For third-party services:
|
|
518
|
+
✅ CHECK THIRD_PARTY_INTEGRATIONS.md first
|
|
519
|
+
✅ ENSURE service is documented there
|
|
520
|
+
✅ CROSS-REFERENCE both contracts
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
### Common Mistakes to Avoid:
|
|
524
|
+
|
|
525
|
+
❌ **DON'T:**
|
|
526
|
+
- Create `SENDGRID_KEY` when `SENDGRID_API_KEY` exists
|
|
527
|
+
- Create `DB_URL` when `DATABASE_URL` exists
|
|
528
|
+
- Create `REDIS_URI` when `REDIS_URL` exists
|
|
529
|
+
- Hardcode values in code instead of using env vars
|
|
530
|
+
- Commit `.env` file to git
|
|
531
|
+
- Use inconsistent naming (mix of snake_case, camelCase)
|
|
532
|
+
- Add env vars without documenting them
|
|
533
|
+
|
|
534
|
+
✅ **DO:**
|
|
535
|
+
- Search this contract first
|
|
536
|
+
- Reuse existing variables
|
|
537
|
+
- Follow naming convention
|
|
538
|
+
- Document thoroughly
|
|
539
|
+
- Update .env.example
|
|
540
|
+
- Cross-reference other contracts
|
|
541
|
+
- Use descriptive names
|
|
542
|
+
|
|
543
|
+
### Benefits:
|
|
544
|
+
|
|
545
|
+
✅ **Single Source of Truth** - All config in one place
|
|
546
|
+
✅ **No Duplicate Variables** - Prevents multiple names for same config
|
|
547
|
+
✅ **No Conflicts** - Agents don't overwrite each other's config
|
|
548
|
+
✅ **Consistent Naming** - Easy to find and understand
|
|
549
|
+
✅ **Easy Onboarding** - New developers know all config options
|
|
550
|
+
✅ **Security** - Centralized secrets management
|
|
551
|
+
✅ **Documentation** - Every variable documented with examples
|
|
552
|
+
|
|
553
|
+
---
|
|
554
|
+
|
|
555
|
+
## Initial Population Instructions
|
|
556
|
+
|
|
557
|
+
**For DevOps Agent / Coding Agents:**
|
|
558
|
+
|
|
559
|
+
When populating this template for the first time:
|
|
560
|
+
|
|
561
|
+
### Phase 1: Discover All Environment Variables
|
|
562
|
+
|
|
563
|
+
1. **Search codebase for `process.env`:**
|
|
564
|
+
```bash
|
|
565
|
+
grep -r "process.env" src/ --include="*.js"
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
2. **Check configuration files:**
|
|
569
|
+
- `config/*.js`
|
|
570
|
+
- `.env.example`
|
|
571
|
+
- `docker-compose.yml`
|
|
572
|
+
- CI/CD config files
|
|
573
|
+
|
|
574
|
+
3. **Review third-party integrations:**
|
|
575
|
+
- Check THIRD_PARTY_INTEGRATIONS.md
|
|
576
|
+
- Look for API client initialization
|
|
577
|
+
- Find authentication code
|
|
578
|
+
|
|
579
|
+
4. **Scan for hardcoded values:**
|
|
580
|
+
- Database connection strings
|
|
581
|
+
- API endpoints
|
|
582
|
+
- Secret keys (security issue!)
|
|
583
|
+
|
|
584
|
+
### Phase 2: Categorize Variables
|
|
585
|
+
|
|
586
|
+
1. **Group by category:**
|
|
587
|
+
- Application (APP_*)
|
|
588
|
+
- Database (DATABASE_*)
|
|
589
|
+
- Cache (REDIS_*)
|
|
590
|
+
- Authentication (JWT_*)
|
|
591
|
+
- Third-party services
|
|
592
|
+
- Feature flags (FEATURE_*)
|
|
593
|
+
- Logging (LOG_*)
|
|
594
|
+
|
|
595
|
+
2. **Document each variable:**
|
|
596
|
+
- Name
|
|
597
|
+
- Type (string, integer, boolean)
|
|
598
|
+
- Required or optional
|
|
599
|
+
- Default value
|
|
600
|
+
- Description
|
|
601
|
+
- Example
|
|
602
|
+
- Which modules use it
|
|
603
|
+
|
|
604
|
+
### Phase 3: Create Configuration Files
|
|
605
|
+
|
|
606
|
+
1. **Generate `.env.example`:**
|
|
607
|
+
- Include all variables
|
|
608
|
+
- Use placeholder values
|
|
609
|
+
- Add comments for clarity
|
|
610
|
+
|
|
611
|
+
2. **Document config files:**
|
|
612
|
+
- List all `config/*.js` files
|
|
613
|
+
- Show which env vars they use
|
|
614
|
+
- Provide code examples
|
|
615
|
+
|
|
616
|
+
### Phase 4: Cross-Reference Contracts
|
|
617
|
+
|
|
618
|
+
1. **Link to THIRD_PARTY_INTEGRATIONS.md:**
|
|
619
|
+
- For each service, link to its integration doc
|
|
620
|
+
- Ensure API keys are documented in both places
|
|
621
|
+
|
|
622
|
+
2. **Link to FEATURES_CONTRACT.md:**
|
|
623
|
+
- For each feature flag, link to the feature
|
|
624
|
+
- Ensure features document their config needs
|
|
625
|
+
|
|
626
|
+
3. **Link to DATABASE_SCHEMA_CONTRACT.md:**
|
|
627
|
+
- For database config, link to schema doc
|
|
628
|
+
|
|
629
|
+
**Search Patterns:**
|
|
630
|
+
- `process.env.`
|
|
631
|
+
- `config/*.js`
|
|
632
|
+
- `.env.example`, `.env.production`
|
|
633
|
+
- `docker-compose.yml`
|
|
634
|
+
- CI/CD configs: `.github/workflows/`, `.gitlab-ci.yml`
|
|
635
|
+
|
|
636
|
+
---
|
|
637
|
+
|
|
638
|
+
*This contract is a living document. Update it with every infrastructure change.*
|