4runr-os 2.9.136 → 2.10.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 (32) hide show
  1. package/apps/gateway/README.md +275 -258
  2. package/apps/gateway/dist/apps/gateway/src/db/docker-manager.d.ts +16 -0
  3. package/apps/gateway/dist/apps/gateway/src/db/docker-manager.d.ts.map +1 -0
  4. package/apps/gateway/dist/apps/gateway/src/db/docker-manager.js +136 -0
  5. package/apps/gateway/dist/apps/gateway/src/db/docker-manager.js.map +1 -0
  6. package/apps/gateway/dist/apps/gateway/src/db/init.d.ts +11 -0
  7. package/apps/gateway/dist/apps/gateway/src/db/init.d.ts.map +1 -0
  8. package/apps/gateway/dist/apps/gateway/src/db/init.js +186 -0
  9. package/apps/gateway/dist/apps/gateway/src/db/init.js.map +1 -0
  10. package/apps/gateway/dist/apps/gateway/src/index.js +39 -2
  11. package/apps/gateway/dist/apps/gateway/src/index.js.map +1 -1
  12. package/apps/gateway/dist/apps/gateway/src/middleware/ddos-protection.d.ts.map +1 -1
  13. package/apps/gateway/dist/apps/gateway/src/middleware/ddos-protection.js +9 -0
  14. package/apps/gateway/dist/apps/gateway/src/middleware/ddos-protection.js.map +1 -1
  15. package/apps/gateway/docker-compose.local.yml +43 -0
  16. package/apps/gateway/package-lock.json +289 -233
  17. package/apps/gateway/src/db/docker-manager.ts +203 -0
  18. package/apps/gateway/src/db/init.ts +270 -0
  19. package/apps/gateway/src/index.ts +34 -2
  20. package/package.json +2 -2
  21. package/packages/shared/dist/env.d.ts +6 -4
  22. package/packages/shared/dist/env.d.ts.map +1 -1
  23. package/packages/shared/dist/env.js +4 -2
  24. package/packages/shared/dist/env.js.map +1 -1
  25. package/packages/shared/dist/index.d.ts +1 -0
  26. package/packages/shared/dist/index.d.ts.map +1 -1
  27. package/packages/shared/dist/index.js +7 -1
  28. package/packages/shared/dist/index.js.map +1 -1
  29. package/packages/shared/dist/platform-paths.d.ts +6 -0
  30. package/packages/shared/dist/platform-paths.d.ts.map +1 -0
  31. package/packages/shared/dist/platform-paths.js +81 -0
  32. package/packages/shared/dist/platform-paths.js.map +1 -0
@@ -1,351 +1,368 @@
1
1
  # 4Runr Gateway
2
2
 
3
- The 4Runr Gateway is a production-ready API gateway for managing AI agent runs with comprehensive features including authentication, rate limiting, queue management, idempotency, security hardening, and Sentinel AI safety integration.
4
-
5
- ## Features
6
-
7
- ### Core Features
8
- - **Run Management**: Create, start, monitor, and manage AI agent runs
9
- - **PostgreSQL Persistence**: Persistent storage with Prisma ORM
10
- - **Memory Mode**: Lightweight mode for testing without database
11
- - **Queue System**: BullMQ-based job queue with priority support
12
- - **Real-time Updates**: Server-Sent Events (SSE) for run logs and status
13
-
14
- ### Security & Authentication
15
- - **Multiple Auth Modes**: API key, JWT, or mixed authentication
16
- - **Security Headers**: CSP, HSTS, X-Frame-Options, and more
17
- - **Secrets Validation**: Automatic validation of security configuration
18
- - **Rate Limiting**: Per-tenant rate limiting with Redis backing
19
- - **Idempotency**: Prevent duplicate requests with Redis-backed idempotency keys
20
-
21
- ### Observability
22
- - **Structured Logging**: Centralized logging with correlation IDs
23
- - **Prometheus Metrics**: Comprehensive metrics for monitoring
24
- - **Health Checks**: Liveness, readiness, and startup probes
25
- - **Error Handling**: Global error handler with production masking
26
-
27
- ### AI Safety
28
- - **Sentinel Integration**: AI agent safety monitoring and enforcement
29
- - **Policy Enforcement**: Max duration, token limits, and custom policies
30
- - **Kill Switch**: Emergency run termination
31
- - **Audit Trails**: Complete audit logging
3
+ The 4Runr Gateway is a production-ready HTTP server for AI agent orchestration and execution management.
32
4
 
33
5
  ## Quick Start
34
6
 
35
- ### Prerequisites
36
- - Node.js >= 18.0.0
37
- - Docker and Docker Compose (for containerized deployment)
38
- - PostgreSQL (for persistent mode)
39
- - Redis (for queue, rate limiting, and idempotency)
7
+ ### Local Development (with Docker)
40
8
 
41
- ### Local Development
42
-
43
- 1. **Clone and install dependencies:**
44
9
  ```bash
45
- git clone <repository>
46
- cd 4Runr-AI-Agent-OS
47
- pnpm install
48
- ```
10
+ # Prerequisites: Docker Desktop (Windows/macOS) or Docker Engine (Linux)
49
11
 
50
- 2. **Set up environment:**
51
- ```bash
12
+ # 1. Install dependencies
13
+ npm install
14
+
15
+ # 2. Build Gateway
52
16
  cd apps/gateway
53
- cp ../../infra/env.example ../../infra/.env
54
- # Edit infra/.env with your configuration
55
- ```
17
+ npm run build
56
18
 
57
- 3. **Start services:**
58
- ```bash
59
- cd ../../infra
60
- docker-compose up -d postgres redis
61
- ```
19
+ # 3. Start Gateway (auto-starts Docker containers)
20
+ npm run dev
21
+ # Or from workspace root:
22
+ npm run gateway:dev
62
23
 
63
- 4. **Generate Prisma client:**
64
- ```bash
65
- cd ../apps/gateway
66
- pnpm db:generate
24
+ # Gateway starts on http://localhost:3001
25
+ # Postgres on localhost:5432, Redis on localhost:6379
67
26
  ```
68
27
 
69
- 5. **Run migrations:**
70
- ```bash
71
- pnpm db:migrate
72
- ```
28
+ ### Development without Docker (Memory Mode)
73
29
 
74
- 6. **Start the gateway:**
75
30
  ```bash
76
- pnpm dev
31
+ export GATEWAY_PERSISTENCE=memory
32
+ export AUTH_ENABLED=false
33
+ npm run dev
77
34
  ```
78
35
 
79
- The gateway will be available at `http://localhost:3000`
36
+ ## Environment Variables
80
37
 
81
- ### Docker Deployment
38
+ ### Core Configuration
82
39
 
83
- ```bash
84
- cd infra
85
- docker-compose up -d
86
- ```
40
+ | Variable | Values | Default | Description |
41
+ |----------|--------|---------|-------------|
42
+ | `NODE_ENV` | `development`, `production` | `development` | Environment mode |
43
+ | `PORT` | `1-65535` | `3001` | HTTP server port |
44
+ | `HOST` | IP address | `127.0.0.1` | Server bind address |
45
+ | `LOG_LEVEL` | `error`, `warn`, `info`, `debug` | `info` | Logging verbosity |
87
46
 
88
- ## Configuration
47
+ ### Persistence & Database
89
48
 
90
- ### Environment Variables
49
+ | Variable | Values | Default | Description |
50
+ |----------|--------|---------|-------------|
51
+ | `GATEWAY_PERSISTENCE` | `auto`, `memory`, `file`, `postgres` | `auto` | Persistence mode |
52
+ | `DATABASE_URL` | PostgreSQL connection string | `postgresql://4runr:4runr_dev_pass@localhost:5432/4runr_local` | Database connection |
53
+ | `REDIS_URL` | Redis connection string | `redis://localhost:6379` | Redis connection |
91
54
 
92
- See [ENV_VARIABLES.md](./ENV_VARIABLES.md) for complete documentation.
55
+ **Persistence Modes:**
56
+ - **`auto`** (recommended): Detects Docker and auto-starts Postgres+Redis
57
+ - **`memory`**: In-memory only, no persistence (fast, ephemeral)
58
+ - **`postgres`**: Explicit PostgreSQL mode (production)
59
+ - **`file`**: Reserved for future SQLite support
93
60
 
94
- **Quick Configuration:**
95
- ```bash
96
- # Minimal development setup
97
- NODE_ENV=development
98
- GATEWAY_PERSISTENCE=postgres
99
- DATABASE_URL=postgresql://user:password@localhost:5432/4runr_gateway
100
- REDIS_URL=redis://localhost:6379
101
- AUTH_ENABLED=true
102
- AUTH_MODE=api_key
103
- JWT_SECRET=your-secret-min-32-chars
104
- ```
61
+ ### Authentication & Security
105
62
 
106
- ### Persistence Modes
63
+ | Variable | Values | Default | Description |
64
+ |----------|--------|---------|-------------|
65
+ | `AUTH_ENABLED` | `true`, `false` | `true` | Enable authentication |
66
+ | `AUTH_MODE` | `api_key`, `jwt`, `mixed` | `api_key` | Authentication method |
67
+ | `JWT_SECRET` | String | (required in production) | JWT signing secret |
68
+ | `ENCRYPTION_KEY` | String | (required in production) | Data encryption key |
69
+ | `API_KEYS` | Comma-separated | (none) | Valid API keys |
107
70
 
108
- - **`memory`**: No database/filesystem writes (testing only)
109
- - **`postgres`** or **`persistent`**: PostgreSQL database (production)
71
+ ### Rate Limiting
110
72
 
111
- ### Authentication Modes
73
+ | Variable | Values | Default | Description |
74
+ |----------|--------|---------|-------------|
75
+ | `RATE_LIMIT_ENABLED` | `true`, `false` | `true` | Enable rate limiting |
76
+ | `RATE_LIMIT_WINDOW_MS` | Number (ms) | `60000` | Rate limit window (1 min) |
77
+ | `RATE_LIMIT_MAX` | Number | `60` | Max requests per window |
112
78
 
113
- - **`api_key`**: API key authentication only
114
- - **`jwt`**: JWT token authentication only
115
- - **`mixed`**: Accept either API key or JWT
79
+ ### Features
116
80
 
117
- ## API Endpoints
81
+ | Variable | Values | Default | Description |
82
+ |----------|--------|---------|-------------|
83
+ | `DEVKIT_ENABLED` | `true`, `false` | `false` | Enable DevKit routes |
84
+ | `METRICS_ENABLED` | `true`, `false` | `true` | Enable Prometheus metrics |
85
+ | `METRICS_PORT` | `1-65535` | `9090` | Metrics endpoint port |
86
+ | `CACHE_ENABLED` | `true`, `false` | `false` | Enable response caching |
87
+ | `IDEMPOTENCY_ENABLED` | `true`, `false` | `false` | Enable idempotency |
118
88
 
119
- ### Run Management
89
+ ### Sentinel (AI Safety)
120
90
 
121
- - `POST /api/runs` - Create a new run
122
- - `GET /api/runs` - List runs (with filtering)
123
- - `GET /api/runs/:id` - Get run details
124
- - `POST /api/runs/:id/start` - Start a run (queues if queue system available)
125
- - `POST /api/runs/:id/cancel` - Cancel a run
126
- - `GET /api/runs/:id/logs/stream` - SSE stream for run logs
91
+ | Variable | Values | Default | Description |
92
+ |----------|--------|---------|-------------|
93
+ | `SENTINEL_ENABLED` | `true`, `false` | `true` | Enable Sentinel checks |
94
+ | `SENTINEL_MODE` | `live`, `mock` | `live` | Sentinel mode |
95
+ | `SENTINEL_SHIELD_MODE` | `enforce`, `monitor`, `off` | `enforce` | Shield behavior |
96
+ | `SHIELD_TOKEN_CAP` | Number | (optional) | Max tokens per request |
97
+ | `RUN_MAX_TOKENS` | Number | (optional) | Max tokens per run |
127
98
 
128
- ### Health & Monitoring
99
+ ### CORS & Security Headers
129
100
 
130
- - `GET /health` - Liveness probe
131
- - `GET /ready` - Readiness probe (checks dependencies)
132
- - `GET /startup` - Startup probe
133
- - `GET /metrics` - Prometheus metrics
101
+ | Variable | Values | Default | Description |
102
+ |----------|--------|---------|-------------|
103
+ | `CORS_ENABLED` | `true`, `false` | `false` | Enable CORS |
104
+ | `CORS_ORIGIN` | String | `*` | Allowed origins |
105
+ | `ALLOW_LOCALHOST_ONLY` | `true`, `false` | `true` | Restrict to localhost |
134
106
 
135
- ### Authentication
107
+ ## Docker Setup
136
108
 
137
- All `/api/*` endpoints require authentication (unless `AUTH_ENABLED=false`).
109
+ ### Auto-Managed (Recommended)
138
110
 
139
- **API Key:**
140
- ```bash
141
- curl -H "x-api-key: your-api-key" http://localhost:3000/api/runs
142
- ```
111
+ Gateway automatically manages Docker containers when `GATEWAY_PERSISTENCE=auto`:
143
112
 
144
- **JWT:**
145
- ```bash
146
- curl -H "Authorization: Bearer your-jwt-token" http://localhost:3000/api/runs
147
- ```
113
+ **What happens:**
114
+ 1. Gateway checks for Docker availability
115
+ 2. Looks for existing `4runr-postgres` and `4runr-redis` containers
116
+ 3. If not found, runs `docker-compose up -d`
117
+ 4. Waits for health checks
118
+ 5. Runs database migrations
119
+ 6. Connects and starts
148
120
 
149
- ## Queue System
121
+ **Containers created:**
122
+ - `4runr-postgres`: PostgreSQL 15 Alpine (~25MB)
123
+ - `4runr-redis`: Redis 7 Alpine (~15MB)
150
124
 
151
- The gateway includes a BullMQ-based queue system for asynchronous run execution:
125
+ **Data persistence:**
126
+ - `4runr-postgres-data`: Docker volume (survives Gateway restarts and npm updates)
127
+ - `4runr-redis-data`: Docker volume (survives Gateway restarts and npm updates)
152
128
 
153
- - **Priority Support**: High, normal, and low priority queues
154
- - **Retry Logic**: Automatic retries with exponential backoff
155
- - **Job Status**: Track job state (waiting, active, completed, failed)
156
- - **Graceful Shutdown**: Jobs are properly handled during shutdown
129
+ ### Manual Docker Management
157
130
 
158
- Queue is automatically enabled when Redis is available. Falls back to synchronous execution if Redis is unavailable.
131
+ ```bash
132
+ # Start containers manually (from apps/gateway/)
133
+ docker-compose -f docker-compose.local.yml up -d
134
+
135
+ # Check status
136
+ docker ps --filter "name=4runr"
159
137
 
160
- ## Rate Limiting
138
+ # Check health
139
+ docker inspect 4runr-postgres --format='{{.State.Health.Status}}'
161
140
 
162
- Rate limiting is enforced per identity (API key, JWT sub, or IP address):
141
+ # View logs
142
+ docker logs -f 4runr-postgres
143
+ docker logs -f 4runr-redis
163
144
 
164
- - **Read Operations**: Full limit (default: 60/min)
165
- - **Write Operations**: 75% of limit (default: 45/min)
166
- - **Expensive Operations**: 50% of limit (default: 30/min)
145
+ # Stop containers (data persists)
146
+ docker-compose -f docker-compose.local.yml down
147
+
148
+ # Stop and remove data
149
+ docker-compose -f docker-compose.local.yml down -v
150
+ ```
167
151
 
168
- Rate limit errors include retry information:
169
- ```json
170
- {
171
- "error": "rate_limited",
172
- "retry_after_ms": 45000,
173
- "limit": 60,
174
- "window_ms": 60000
175
- }
152
+ ### Docker Compose Configuration
153
+
154
+ Location: `apps/gateway/docker-compose.local.yml`
155
+
156
+ ```yaml
157
+ services:
158
+ postgres:
159
+ image: postgres:15-alpine
160
+ container_name: 4runr-postgres
161
+ environment:
162
+ POSTGRES_DB: 4runr_local
163
+ POSTGRES_USER: 4runr
164
+ POSTGRES_PASSWORD: ${DB_PASSWORD:-4runr_dev_pass}
165
+ ports:
166
+ - "5432:5432"
167
+ volumes:
168
+ - 4runr-postgres-data:/var/lib/postgresql/data
169
+ healthcheck:
170
+ test: ["CMD-SHELL", "pg_isready -U 4runr"]
171
+ interval: 5s
172
+ timeout: 5s
173
+ retries: 5
174
+
175
+ redis:
176
+ image: redis:7-alpine
177
+ container_name: 4runr-redis
178
+ ports:
179
+ - "6379:6379"
180
+ volumes:
181
+ - 4runr-redis-data:/data
182
+ command: redis-server --appendonly yes
183
+ healthcheck:
184
+ test: ["CMD", "redis-cli", "ping"]
185
+ interval: 5s
186
+ timeout: 3s
187
+ retries: 5
176
188
  ```
177
189
 
178
- ## Idempotency
190
+ ## Database Migrations
179
191
 
180
- Prevent duplicate requests using idempotency keys:
192
+ Migrations run automatically on Gateway startup when Docker mode is active.
181
193
 
194
+ **Manual migrations:**
182
195
  ```bash
183
- curl -X POST http://localhost:3000/api/runs \
184
- -H "x-api-key: your-key" \
185
- -H "Idempotency-Key: unique-key-123" \
186
- -H "Content-Type: application/json" \
187
- -d '{"name": "My Run", "input": {}}'
188
- ```
196
+ # Generate Prisma client
197
+ cd apps/gateway
198
+ npx prisma generate
189
199
 
190
- Subsequent requests with the same idempotency key return the cached response.
200
+ # Create new migration
201
+ npx prisma migrate dev --name migration_name
191
202
 
192
- ## Security Features
203
+ # Deploy migrations (production)
204
+ npx prisma migrate deploy
193
205
 
194
- ### Security Headers
195
- - Content Security Policy (CSP)
196
- - HTTP Strict Transport Security (HSTS)
197
- - X-Content-Type-Options
198
- - X-Frame-Options
199
- - X-XSS-Protection
200
- - Referrer-Policy
201
- - Permissions-Policy
202
- - Cross-Origin policies (COEP, COOP, CORP)
206
+ # Reset database (development only, deletes all data)
207
+ npx prisma migrate reset
208
+ ```
203
209
 
204
- ### Error Handling
205
- - Production error masking (500 errors hidden from clients)
206
- - Correlation IDs for error tracking
207
- - Consistent error response format
208
- - Validation error details
210
+ **Schema location:** `prisma/schema.prisma`
209
211
 
210
- ## Testing
212
+ ## API Endpoints
211
213
 
212
- ### Unit Tests
213
- ```bash
214
- pnpm test
215
- ```
214
+ ### Health & Status
216
215
 
217
- ### Integration Tests
218
- ```bash
219
- # Start services first
220
- bash scripts/setup-test-env.sh
216
+ - `GET /health` - Health check (always available)
217
+ - `GET /ready` - Readiness check (checks dependencies)
218
+ - `GET /metrics` - Prometheus metrics (port 9090)
221
219
 
222
- # Run integration tests
223
- pnpm test:integration
224
- ```
220
+ ### Runs API
225
221
 
226
- ### Load Testing
227
- ```bash
228
- # Install k6 first: https://k6.io/docs/getting-started/installation/
229
- export GATEWAY_URL="http://localhost:3000"
230
- export API_KEY="your-api-key"
231
- pnpm load-test
232
- ```
222
+ - `POST /api/runs` - Create a new run
223
+ - `POST /api/runs/:id/start` - Start a run
224
+ - `POST /api/runs/:id/cancel` - Cancel a running run
225
+ - `GET /api/runs/:id/status` - Get run status
226
+ - `GET /api/runs/:id/stream` - SSE stream for run events
233
227
 
234
- See [PHASE5-TESTING.md](./PHASE5-TESTING.md) for detailed testing documentation.
228
+ ### DevKit API (requires database)
235
229
 
236
- ## Deployment
230
+ - `GET /devkit/api/status` - System status
231
+ - `GET /devkit/api/health` - Detailed health checks
232
+ - `GET /devkit/api/config` - Non-sensitive configuration
233
+ - `GET /devkit/api/runs` - List recent runs
234
+ - `GET /devkit/api/runs/:id` - Get run details
235
+ - `GET /devkit/api/metrics/summary` - Parsed metrics summary
237
236
 
238
- See [DEPLOYMENT.md](./DEPLOYMENT.md) for comprehensive deployment guide.
237
+ **Note:** DevKit routes are automatically disabled in memory mode.
239
238
 
240
- ### Quick Production Deployment
239
+ ## Troubleshooting
241
240
 
242
- 1. **Set up environment variables:**
243
- ```bash
244
- cp infra/env.example infra/.env.production
245
- # Edit with production values
246
- ```
241
+ ### "Docker not available"
247
242
 
248
- 2. **Build and deploy:**
249
- ```bash
250
- docker-compose -f infra/docker-compose.prod.yml up -d
243
+ **Symptom:**
251
244
  ```
252
-
253
- 3. **Verify deployment:**
254
- ```bash
255
- curl http://your-server/health
256
- curl http://your-server/ready
245
+ [WARN] ⚠️ Docker not available. Running in memory-only mode.
257
246
  ```
258
247
 
259
- ## Monitoring
248
+ **Solutions:**
249
+ 1. Install Docker Desktop (Windows/macOS) or Docker Engine (Linux)
250
+ 2. Start Docker: `docker info` should return server info
251
+ 3. Check user permissions (Linux): `sudo usermod -aG docker $USER`
252
+ 4. WSL2 (Windows): Enable in Docker Desktop settings
253
+
254
+ ### "Port 5432 already allocated"
255
+
256
+ **Symptom:**
257
+ ```
258
+ Error: Bind for 0.0.0.0:5432 failed: port is already allocated
259
+ ```
260
260
 
261
- ### Metrics
261
+ **Solutions:**
262
+ 1. Find conflicting container: `docker ps --filter "publish=5432"`
263
+ 2. Stop it: `docker stop CONTAINER_NAME`
264
+ 3. Or change 4Runr port in `docker-compose.local.yml`
262
265
 
263
- Prometheus metrics are available at `/metrics`:
266
+ ### "Container did not become healthy"
264
267
 
265
- - HTTP request metrics (duration, total, errors)
266
- - Run metrics (created, started, completed, duration)
267
- - SSE connection metrics
268
- - Idempotency metrics
269
- - Rate limiting metrics
270
- - Authentication metrics
271
- - Queue job metrics
268
+ **Symptom:**
269
+ ```
270
+ [ERROR] Container 4runr-postgres did not become healthy within 60000ms
271
+ ```
272
272
 
273
- ### Health Checks
273
+ **Solutions:**
274
+ 1. Pre-pull images: `docker-compose -f docker-compose.local.yml pull`
275
+ 2. Start containers manually first: `docker-compose up -d`
276
+ 3. Wait for health: `docker ps` shows "(healthy)" status
274
277
 
275
- - **Liveness** (`/health`): Server is running
276
- - **Readiness** (`/ready`): Server and dependencies are ready
277
- - **Startup** (`/startup`): Server has completed startup
278
+ ### More Help
278
279
 
279
- ### Logging
280
+ See [`docs/TROUBLESHOOTING.md`](../../docs/TROUBLESHOOTING.md) for comprehensive troubleshooting guide.
280
281
 
281
- Structured JSON logging with correlation IDs. Log levels:
282
- - `error`: Errors only
283
- - `warn`: Warnings and errors
284
- - `info`: Info, warnings, and errors (default)
285
- - `debug`: All logs
282
+ ## Development Workflow
286
283
 
287
- ## Troubleshooting
284
+ ### Building
288
285
 
289
- See [TROUBLESHOOTING.md](./TROUBLESHOOTING.md) for common issues and solutions.
286
+ ```bash
287
+ # Build Gateway only
288
+ cd apps/gateway
289
+ npm run build
290
290
 
291
- ## Architecture
291
+ # Build all packages
292
+ cd ../..
293
+ npm run build
294
+ ```
292
295
 
293
- ### Components
296
+ ### Running
294
297
 
295
- - **Fastify Server**: High-performance web framework
296
- - **Prisma ORM**: Database access layer
297
- - **BullMQ**: Job queue system
298
- - **Redis**: Caching, rate limiting, idempotency
299
- - **Sentinel**: AI safety monitoring
300
- - **Prometheus**: Metrics collection
298
+ ```bash
299
+ # Development mode (auto-reload)
300
+ npm run dev
301
301
 
302
- ### Data Flow
302
+ # Production mode
303
+ NODE_ENV=production npm start
304
+ ```
303
305
 
304
- 1. Request → Authentication → Rate Limiting
305
- 2. Idempotency Check → Route Handler
306
- 3. Run Creation → Queue (if available) → Processor
307
- 4. Status Updates → SSE Events → Client
308
- 5. Completion → Metrics Update → Logging
306
+ ### Testing
309
307
 
310
- ## Development
308
+ ```bash
309
+ # Run tests
310
+ npm test
311
311
 
312
- ### Project Structure
312
+ # Run with coverage
313
+ npm run test:coverage
313
314
 
315
+ # Run specific test
316
+ npm test -- --grep "idempotency"
314
317
  ```
315
- apps/gateway/
316
- ├── src/
317
- │ ├── __tests__/ # Test files
318
- │ ├── adapters/ # External service adapters
319
- │ ├── config/ # Configuration
320
- │ ├── db/ # Database clients
321
- │ ├── health/ # Health check logic
322
- │ ├── metrics/ # Prometheus metrics
323
- │ ├── middleware/ # Express/Fastify middleware
324
- │ ├── queue/ # Queue system
325
- │ ├── runs/ # Run store implementations
326
- │ ├── schemas/ # Zod validation schemas
327
- │ └── index.ts # Main entry point
328
- ├── scripts/ # Utility scripts
329
- ├── load-tests/ # Load testing scripts
330
- └── Dockerfile # Container definition
318
+
319
+ ### Linting
320
+
321
+ ```bash
322
+ # Lint
323
+ npm run lint
324
+
325
+ # Lint and fix
326
+ npm run lint:fix
331
327
  ```
332
328
 
333
- ### Adding New Features
329
+ ## Production Deployment
334
330
 
335
- 1. Create feature branch
336
- 2. Implement feature with tests
337
- 3. Update documentation
338
- 4. Run tests and linting
339
- 5. Submit PR
331
+ See [`docs/GATEWAY-PRODUCTION-READINESS-PLAN.md`](../../docs/GATEWAY-PRODUCTION-READINESS-PLAN.md) for production deployment guide.
340
332
 
341
- ## License
333
+ **Key production requirements:**
334
+ - Set `NODE_ENV=production`
335
+ - Provide `JWT_SECRET` and `ENCRYPTION_KEY`
336
+ - Use external PostgreSQL and Redis
337
+ - Enable TLS/HTTPS
338
+ - Configure monitoring and observability
339
+ - Set up proper rate limiting
340
+ - Review security checklist
342
341
 
343
- [Your License Here]
342
+ ## Project Structure
344
343
 
345
- ## Support
344
+ ```
345
+ apps/gateway/
346
+ ├── src/
347
+ │ ├── index.ts # Entry point
348
+ │ ├── db/
349
+ │ │ ├── init.ts # Database initialization
350
+ │ │ ├── docker-manager.ts # Docker container management
351
+ │ │ └── memory-db.ts # In-memory fallback
352
+ │ ├── routes/ # API route handlers
353
+ │ ├── middleware/ # Fastify middleware
354
+ │ ├── devkit/ # DevKit routes
355
+ │ └── ai-providers/ # AI provider integrations
356
+ ├── prisma/
357
+ │ └── schema.prisma # Database schema
358
+ ├── docker-compose.local.yml # Local Docker setup
359
+ └── package.json
360
+ ```
346
361
 
347
- For issues and questions:
348
- - GitHub Issues: [repository-url]/issues
349
- - Documentation: See `docs/` directory
350
- - Troubleshooting: See [TROUBLESHOOTING.md](./TROUBLESHOOTING.md)
362
+ ## Additional Documentation
351
363
 
364
+ - **Implementation Plan:** [`docs/4RUNR-DB-IMPLEMENTATION-PLAN.md`](../../docs/4RUNR-DB-IMPLEMENTATION-PLAN.md)
365
+ - **Test Results:** [`docs/PHASE-4-TEST-RESULTS.md`](../../docs/PHASE-4-TEST-RESULTS.md)
366
+ - **Troubleshooting:** [`docs/TROUBLESHOOTING.md`](../../docs/TROUBLESHOOTING.md)
367
+ - **Decisions:** [`docs/decisions.md`](../../docs/decisions.md)
368
+ - **Status:** [`docs/status.md`](../../docs/status.md)
@@ -0,0 +1,16 @@
1
+ export declare function isDockerAvailable(): Promise<boolean>;
2
+ export declare function isDockerRunning(): Promise<boolean>;
3
+ export declare function areContainersRunning(): Promise<boolean>;
4
+ export declare function startDockerCompose(composeFilePath: string): Promise<void>;
5
+ export declare function stopDockerCompose(composeFilePath: string): Promise<void>;
6
+ export declare function waitForHealthy(containerName: string, timeoutMs?: number): Promise<void>;
7
+ export declare function isPortInUse(port: number): Promise<boolean>;
8
+ export declare function getContainerLogs(containerName: string, lines?: number): string;
9
+ export interface DockerStatus {
10
+ available: boolean;
11
+ running: boolean;
12
+ containersRunning: boolean;
13
+ error?: string;
14
+ }
15
+ export declare function getDockerStatus(): Promise<DockerStatus>;
16
+ //# sourceMappingURL=docker-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docker-manager.d.ts","sourceRoot":"","sources":["../../../../../src/db/docker-manager.ts"],"names":[],"mappings":"AAMA,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC,CAW1D;AAKD,wBAAsB,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC,CAWxD;AAKD,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC,CAW7D;AAMD,wBAAsB,kBAAkB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAK/E;AAMD,wBAAsB,iBAAiB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAK9E;AAOD,wBAAsB,cAAc,CAAC,aAAa,EAAE,MAAM,EAAE,SAAS,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAuCpG;AAMD,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAchE;AAOD,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,GAAE,MAAW,GAAG,MAAM,CAUlF;AAYD,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAKD,wBAAsB,eAAe,IAAI,OAAO,CAAC,YAAY,CAAC,CA0B7D"}