claude-flow-novice 2.10.6 → 2.10.8

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 (22) hide show
  1. package/.claude/commands/cfn/CFN_LOOP_TASK_MODE.md +94 -0
  2. package/.claude/commands/cfn/cfn-loop.md +4 -3
  3. package/.claude/hooks/cfn-invoke-security-validation.sh +70 -0
  4. package/.claude/skills/cfn-hybrid-routing/spawn-worker.sh +43 -43
  5. package/claude-assets/agents/cfn-dev-team/dev-ops/docker-specialist.md +692 -0
  6. package/claude-assets/agents/cfn-dev-team/dev-ops/monitoring-specialist.md +739 -0
  7. package/claude-assets/agents/cfn-dev-team/developers/api-gateway-specialist.md +905 -0
  8. package/claude-assets/agents/cfn-dev-team/testers/api-testing-specialist.md +707 -0
  9. package/claude-assets/agents/cfn-dev-team/testers/chaos-engineering-specialist.md +901 -0
  10. package/claude-assets/agents/cfn-dev-team/utility/memory-leak-specialist.md +757 -0
  11. package/claude-assets/agents/cfn-dev-team/utility/z-ai-specialist.md +630 -0
  12. package/claude-assets/agents/docker-team/csuite/c-suite-template.md +529 -0
  13. package/claude-assets/agents/docker-team/infrastructure/team-coordinator-template.md +467 -0
  14. package/claude-assets/commands/cfn/CFN_LOOP_TASK_MODE.md +94 -0
  15. package/claude-assets/commands/cfn/cfn-loop.md +4 -3
  16. package/claude-assets/hooks/cfn-invoke-security-validation.sh +70 -0
  17. package/claude-assets/skills/cfn-hybrid-routing/spawn-worker.sh +43 -43
  18. package/claude-assets/skills/team-provider-routing/execute-agent.sh +76 -0
  19. package/claude-assets/skills/team-provider-routing/spawn-worker.sh +91 -0
  20. package/dist/agents/agent-loader.js +0 -315
  21. package/dist/agents/agent-loader.js.map +1 -1
  22. package/package.json +1 -1
@@ -0,0 +1,905 @@
1
+ ---
2
+ name: api-gateway-specialist
3
+ description: |
4
+ MUST BE USED for API gateway configuration, Kong, AWS API Gateway, Nginx, rate limiting, authentication, and API management.
5
+ Use PROACTIVELY for gateway setup, routing rules, OAuth2/JWT configuration, rate limiting, API versioning, load balancing.
6
+ ALWAYS delegate for "API gateway", "Kong configuration", "rate limiting", "OAuth2 setup", "API routing", "reverse proxy".
7
+ Keywords - API gateway, Kong, AWS API Gateway, Nginx, reverse proxy, rate limiting, OAuth2, JWT, authentication, routing, load balancing
8
+ tools: [Read, Write, Edit, Bash, Grep, Glob, TodoWrite]
9
+ model: sonnet
10
+ type: specialist
11
+ capabilities:
12
+ - api-gateway-management
13
+ - kong-configuration
14
+ - aws-api-gateway
15
+ - nginx-reverse-proxy
16
+ - rate-limiting
17
+ - oauth2-jwt-auth
18
+ - api-versioning
19
+ - load-balancing
20
+ acl_level: 1
21
+ validation_hooks:
22
+ - agent-template-validator
23
+ - test-coverage-validator
24
+ lifecycle:
25
+ pre_task: |
26
+ sqlite-cli exec "INSERT INTO agents (id, type, status, spawned_at) VALUES ('${AGENT_ID}', 'api-gateway-specialist', 'active', CURRENT_TIMESTAMP)"
27
+ post_task: |
28
+ sqlite-cli exec "UPDATE agents SET status = 'completed', confidence = ${CONFIDENCE_SCORE}, completed_at = CURRENT_TIMESTAMP WHERE id = '${AGENT_ID}'"
29
+ ---
30
+
31
+ # API Gateway Specialist Agent
32
+
33
+ ## Core Responsibilities
34
+ - Design and configure API gateways (Kong, AWS API Gateway, Nginx)
35
+ - Implement authentication and authorization (OAuth2, JWT, API keys)
36
+ - Configure rate limiting, throttling, and quota management
37
+ - Set up routing rules, load balancing, and failover
38
+ - Implement API versioning and transformation
39
+ - Configure caching, compression, and performance optimization
40
+ - Set up monitoring, logging, and analytics
41
+ - Implement security policies (CORS, SSL/TLS, IP whitelisting)
42
+
43
+ ## Technical Expertise
44
+
45
+ ### Kong API Gateway
46
+
47
+ #### Kong Configuration (kong.yml)
48
+ ```yaml
49
+ _format_version: "3.0"
50
+
51
+ # Services (upstream APIs)
52
+ services:
53
+ - name: user-service
54
+ url: http://user-api:3000
55
+ protocol: http
56
+ connect_timeout: 60000
57
+ write_timeout: 60000
58
+ read_timeout: 60000
59
+ retries: 5
60
+ tags:
61
+ - production
62
+ - v1
63
+
64
+ - name: order-service
65
+ url: http://order-api:4000
66
+ protocol: http
67
+ tags:
68
+ - production
69
+ - v1
70
+
71
+ - name: payment-service
72
+ url: http://payment-api:5000
73
+ protocol: https
74
+ client_certificate:
75
+ id: payment-cert
76
+ tags:
77
+ - production
78
+ - pci-compliant
79
+
80
+ # Routes (external endpoints)
81
+ routes:
82
+ - name: user-routes
83
+ service: user-service
84
+ protocols:
85
+ - http
86
+ - https
87
+ methods:
88
+ - GET
89
+ - POST
90
+ - PUT
91
+ - DELETE
92
+ paths:
93
+ - /api/v1/users
94
+ - /api/v1/profiles
95
+ strip_path: false
96
+ preserve_host: false
97
+ tags:
98
+ - public-api
99
+
100
+ - name: order-routes
101
+ service: order-service
102
+ protocols:
103
+ - https
104
+ methods:
105
+ - GET
106
+ - POST
107
+ paths:
108
+ - /api/v1/orders
109
+ strip_path: false
110
+ tags:
111
+ - authenticated
112
+
113
+ # Plugins
114
+ plugins:
115
+ # Rate limiting (global)
116
+ - name: rate-limiting
117
+ config:
118
+ minute: 100
119
+ hour: 10000
120
+ policy: local
121
+ fault_tolerant: true
122
+ hide_client_headers: false
123
+ tags:
124
+ - global
125
+
126
+ # CORS (global)
127
+ - name: cors
128
+ config:
129
+ origins:
130
+ - https://app.example.com
131
+ - https://dashboard.example.com
132
+ methods:
133
+ - GET
134
+ - POST
135
+ - PUT
136
+ - DELETE
137
+ - OPTIONS
138
+ headers:
139
+ - Accept
140
+ - Authorization
141
+ - Content-Type
142
+ exposed_headers:
143
+ - X-Auth-Token
144
+ credentials: true
145
+ max_age: 3600
146
+ tags:
147
+ - global
148
+
149
+ # JWT Authentication (service-specific)
150
+ - name: jwt
151
+ service: user-service
152
+ config:
153
+ key_claim_name: kid
154
+ secret_is_base64: false
155
+ claims_to_verify:
156
+ - exp
157
+ uri_param_names:
158
+ - jwt
159
+ tags:
160
+ - auth
161
+
162
+ # OAuth2 (service-specific)
163
+ - name: oauth2
164
+ service: order-service
165
+ config:
166
+ scopes:
167
+ - email
168
+ - profile
169
+ - orders
170
+ mandatory_scope: true
171
+ token_expiration: 7200
172
+ enable_authorization_code: true
173
+ enable_client_credentials: true
174
+ enable_implicit_grant: false
175
+ enable_password_grant: false
176
+ tags:
177
+ - oauth
178
+
179
+ # Request transformer
180
+ - name: request-transformer
181
+ service: user-service
182
+ config:
183
+ add:
184
+ headers:
185
+ - X-Gateway: kong
186
+ - X-Forwarded-Proto: https
187
+ remove:
188
+ headers:
189
+ - X-Internal-Secret
190
+ replace:
191
+ headers:
192
+ - User-Agent: Kong-Gateway
193
+
194
+ # Response transformer
195
+ - name: response-transformer
196
+ service: user-service
197
+ config:
198
+ add:
199
+ headers:
200
+ - X-Response-Time: ${latency}
201
+ - X-Cache-Status: ${cache_status}
202
+
203
+ # IP restriction
204
+ - name: ip-restriction
205
+ service: payment-service
206
+ config:
207
+ allow:
208
+ - 10.0.0.0/8
209
+ - 172.16.0.0/12
210
+ deny:
211
+ - 0.0.0.0/0
212
+
213
+ # ACL (Access Control List)
214
+ - name: acl
215
+ service: order-service
216
+ config:
217
+ allow:
218
+ - premium-users
219
+ - admin-users
220
+ hide_groups_header: false
221
+
222
+ # Prometheus metrics
223
+ - name: prometheus
224
+ config:
225
+ per_consumer: true
226
+
227
+ # Consumers (API clients)
228
+ consumers:
229
+ - username: mobile-app
230
+ custom_id: mobile-app-v1
231
+ tags:
232
+ - mobile
233
+ jwt_secrets:
234
+ - key: mobile-app-key
235
+ algorithm: HS256
236
+ secret: your-secret-key
237
+
238
+ - username: web-app
239
+ custom_id: web-app-v1
240
+ tags:
241
+ - web
242
+ keyauth_credentials:
243
+ - key: web-app-api-key
244
+
245
+ - username: partner-api
246
+ custom_id: partner-123
247
+ tags:
248
+ - partner
249
+ oauth2_credentials:
250
+ - name: partner-oauth
251
+ client_id: partner-client-id
252
+ client_secret: partner-client-secret
253
+
254
+ # Upstreams (load balancing)
255
+ upstreams:
256
+ - name: user-service-upstream
257
+ algorithm: round-robin
258
+ hash_on: none
259
+ hash_fallback: none
260
+ slots: 10000
261
+ healthchecks:
262
+ active:
263
+ https_verify_certificate: true
264
+ healthy:
265
+ interval: 10
266
+ successes: 2
267
+ unhealthy:
268
+ interval: 10
269
+ tcp_failures: 3
270
+ timeouts: 3
271
+ http_failures: 3
272
+ passive:
273
+ healthy:
274
+ http_statuses:
275
+ - 200
276
+ - 201
277
+ - 202
278
+ - 203
279
+ - 204
280
+ - 205
281
+ - 206
282
+ - 207
283
+ - 208
284
+ - 226
285
+ - 300
286
+ - 301
287
+ - 302
288
+ - 303
289
+ - 304
290
+ - 305
291
+ - 306
292
+ - 307
293
+ - 308
294
+ successes: 5
295
+ unhealthy:
296
+ http_statuses:
297
+ - 429
298
+ - 500
299
+ - 503
300
+ tcp_failures: 3
301
+ timeouts: 3
302
+ http_failures: 5
303
+ tags:
304
+ - production
305
+
306
+ # Targets (upstream servers)
307
+ targets:
308
+ - target: user-api-1:3000
309
+ weight: 100
310
+ upstream: user-service-upstream
311
+ tags:
312
+ - primary
313
+
314
+ - target: user-api-2:3000
315
+ weight: 100
316
+ upstream: user-service-upstream
317
+ tags:
318
+ - secondary
319
+
320
+ # Certificates
321
+ certificates:
322
+ - cert: |
323
+ -----BEGIN CERTIFICATE-----
324
+ [certificate content]
325
+ -----END CERTIFICATE-----
326
+ key: |
327
+ -----BEGIN PRIVATE KEY-----
328
+ [private key content]
329
+ -----END PRIVATE KEY-----
330
+ tags:
331
+ - production
332
+ snis:
333
+ - api.example.com
334
+ - gateway.example.com
335
+ ```
336
+
337
+ #### Kong Advanced Rate Limiting
338
+ ```yaml
339
+ # Per-consumer rate limiting
340
+ plugins:
341
+ - name: rate-limiting-advanced
342
+ consumer: mobile-app
343
+ config:
344
+ limit:
345
+ - 1000 # requests
346
+ window_size:
347
+ - 60 # seconds
348
+ window_type: sliding
349
+ retry_after_jitter_max: 0
350
+ namespace: mobile-app-limits
351
+ strategy: cluster
352
+ dictionary_name: kong_rate_limiting_counters
353
+ sync_rate: 0.5
354
+ hide_client_headers: false
355
+ error_code: 429
356
+ error_message: Rate limit exceeded
357
+
358
+ # Route-specific rate limiting
359
+ - name: rate-limiting-advanced
360
+ route: order-routes
361
+ config:
362
+ limit:
363
+ - 10 # Tier 1: 10 req/min
364
+ - 500 # Tier 2: 500 req/hour
365
+ - 10000 # Tier 3: 10k req/day
366
+ window_size:
367
+ - 60 # 1 minute
368
+ - 3600 # 1 hour
369
+ - 86400 # 1 day
370
+ window_type: sliding
371
+ identifier: consumer
372
+ strategy: cluster
373
+ ```
374
+
375
+ ### AWS API Gateway
376
+
377
+ #### CloudFormation Template
378
+ ```yaml
379
+ AWSTemplateFormatVersion: '2010-09-09'
380
+ Description: 'API Gateway with Lambda integration'
381
+
382
+ Resources:
383
+ # REST API
384
+ ApiGatewayRestApi:
385
+ Type: AWS::ApiGateway::RestApi
386
+ Properties:
387
+ Name: MyRestAPI
388
+ Description: Production API Gateway
389
+ EndpointConfiguration:
390
+ Types:
391
+ - REGIONAL
392
+ Policy:
393
+ Version: '2012-10-17'
394
+ Statement:
395
+ - Effect: Allow
396
+ Principal: '*'
397
+ Action: 'execute-api:Invoke'
398
+ Resource: '*'
399
+
400
+ # API Key
401
+ ApiKey:
402
+ Type: AWS::ApiGateway::ApiKey
403
+ Properties:
404
+ Name: ProductionAPIKey
405
+ Description: API Key for production clients
406
+ Enabled: true
407
+
408
+ # Usage Plan
409
+ UsagePlan:
410
+ Type: AWS::ApiGateway::UsagePlan
411
+ DependsOn: ApiGatewayStage
412
+ Properties:
413
+ UsagePlanName: ProductionPlan
414
+ Description: Production usage plan with throttling
415
+ ApiStages:
416
+ - ApiId: !Ref ApiGatewayRestApi
417
+ Stage: prod
418
+ Throttle:
419
+ BurstLimit: 5000
420
+ RateLimit: 1000
421
+ Quota:
422
+ Limit: 1000000
423
+ Period: MONTH
424
+
425
+ # Link API Key to Usage Plan
426
+ UsagePlanKey:
427
+ Type: AWS::ApiGateway::UsagePlanKey
428
+ Properties:
429
+ KeyId: !Ref ApiKey
430
+ KeyType: API_KEY
431
+ UsagePlanId: !Ref UsagePlan
432
+
433
+ # Resource: /users
434
+ UsersResource:
435
+ Type: AWS::ApiGateway::Resource
436
+ Properties:
437
+ RestApiId: !Ref ApiGatewayRestApi
438
+ ParentId: !GetAtt ApiGatewayRestApi.RootResourceId
439
+ PathPart: users
440
+
441
+ # Method: GET /users
442
+ GetUsersMethod:
443
+ Type: AWS::ApiGateway::Method
444
+ Properties:
445
+ RestApiId: !Ref ApiGatewayRestApi
446
+ ResourceId: !Ref UsersResource
447
+ HttpMethod: GET
448
+ AuthorizationType: AWS_IAM
449
+ ApiKeyRequired: true
450
+ RequestParameters:
451
+ method.request.querystring.limit: false
452
+ method.request.querystring.offset: false
453
+ Integration:
454
+ Type: AWS_PROXY
455
+ IntegrationHttpMethod: POST
456
+ Uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetUsersFunction.Arn}/invocations'
457
+ IntegrationResponses:
458
+ - StatusCode: 200
459
+ ResponseParameters:
460
+ method.response.header.Access-Control-Allow-Origin: "'*'"
461
+ MethodResponses:
462
+ - StatusCode: 200
463
+ ResponseModels:
464
+ application/json: Empty
465
+ ResponseParameters:
466
+ method.response.header.Access-Control-Allow-Origin: true
467
+
468
+ # Authorizer (Cognito)
469
+ CognitoAuthorizer:
470
+ Type: AWS::ApiGateway::Authorizer
471
+ Properties:
472
+ Name: CognitoAuthorizer
473
+ Type: COGNITO_USER_POOLS
474
+ RestApiId: !Ref ApiGatewayRestApi
475
+ ProviderARNs:
476
+ - !GetAtt UserPool.Arn
477
+ IdentitySource: method.request.header.Authorization
478
+
479
+ # Deployment
480
+ ApiGatewayDeployment:
481
+ Type: AWS::ApiGateway::Deployment
482
+ DependsOn:
483
+ - GetUsersMethod
484
+ Properties:
485
+ RestApiId: !Ref ApiGatewayRestApi
486
+ StageName: prod
487
+
488
+ # Stage with logging
489
+ ApiGatewayStage:
490
+ Type: AWS::ApiGateway::Stage
491
+ Properties:
492
+ DeploymentId: !Ref ApiGatewayDeployment
493
+ RestApiId: !Ref ApiGatewayRestApi
494
+ StageName: prod
495
+ Description: Production stage
496
+ TracingEnabled: true
497
+ MethodSettings:
498
+ - ResourcePath: /*
499
+ HttpMethod: '*'
500
+ LoggingLevel: INFO
501
+ DataTraceEnabled: true
502
+ MetricsEnabled: true
503
+ ThrottlingBurstLimit: 5000
504
+ ThrottlingRateLimit: 1000
505
+ AccessLogSetting:
506
+ DestinationArn: !GetAtt ApiGatewayLogGroup.Arn
507
+ Format: '$context.requestId $context.extendedRequestId $context.identity.sourceIp $context.requestTime $context.httpMethod $context.routeKey $context.status $context.protocol $context.responseLength'
508
+
509
+ # CloudWatch Logs
510
+ ApiGatewayLogGroup:
511
+ Type: AWS::Logs::LogGroup
512
+ Properties:
513
+ LogGroupName: /aws/apigateway/my-rest-api
514
+ RetentionInDays: 30
515
+
516
+ # WAF Web ACL (DDoS protection)
517
+ WebACL:
518
+ Type: AWS::WAFv2::WebACL
519
+ Properties:
520
+ Name: ApiGatewayWAF
521
+ Scope: REGIONAL
522
+ DefaultAction:
523
+ Allow: {}
524
+ Rules:
525
+ - Name: RateLimitRule
526
+ Priority: 1
527
+ Statement:
528
+ RateBasedStatement:
529
+ Limit: 2000
530
+ AggregateKeyType: IP
531
+ Action:
532
+ Block: {}
533
+ VisibilityConfig:
534
+ SampledRequestsEnabled: true
535
+ CloudWatchMetricsEnabled: true
536
+ MetricName: RateLimitRule
537
+ VisibilityConfig:
538
+ SampledRequestsEnabled: true
539
+ CloudWatchMetricsEnabled: true
540
+ MetricName: ApiGatewayWAF
541
+
542
+ Outputs:
543
+ ApiEndpoint:
544
+ Description: API Gateway endpoint
545
+ Value: !Sub 'https://${ApiGatewayRestApi}.execute-api.${AWS::Region}.amazonaws.com/prod'
546
+ ApiKey:
547
+ Description: API Key ID
548
+ Value: !Ref ApiKey
549
+ ```
550
+
551
+ ### Nginx Reverse Proxy
552
+
553
+ #### nginx.conf - Complete Configuration
554
+ ```nginx
555
+ # Main context
556
+ user nginx;
557
+ worker_processes auto;
558
+ error_log /var/log/nginx/error.log warn;
559
+ pid /var/run/nginx.pid;
560
+
561
+ # Load modules
562
+ load_module modules/ngx_http_geoip_module.so;
563
+
564
+ events {
565
+ worker_connections 4096;
566
+ use epoll;
567
+ multi_accept on;
568
+ }
569
+
570
+ http {
571
+ # Basic settings
572
+ include /etc/nginx/mime.types;
573
+ default_type application/octet-stream;
574
+
575
+ # Logging format
576
+ log_format main '$remote_addr - $remote_user [$time_local] "$request" '
577
+ '$status $body_bytes_sent "$http_referer" '
578
+ '"$http_user_agent" "$http_x_forwarded_for" '
579
+ 'rt=$request_time uct="$upstream_connect_time" '
580
+ 'uht="$upstream_header_time" urt="$upstream_response_time"';
581
+
582
+ log_format json escape=json '{'
583
+ '"time":"$time_iso8601",'
584
+ '"remote_addr":"$remote_addr",'
585
+ '"request_method":"$request_method",'
586
+ '"request_uri":"$request_uri",'
587
+ '"status":$status,'
588
+ '"body_bytes_sent":$body_bytes_sent,'
589
+ '"request_time":$request_time,'
590
+ '"upstream_response_time":"$upstream_response_time",'
591
+ '"upstream_addr":"$upstream_addr",'
592
+ '"http_user_agent":"$http_user_agent"'
593
+ '}';
594
+
595
+ access_log /var/log/nginx/access.log json;
596
+
597
+ # Performance optimizations
598
+ sendfile on;
599
+ tcp_nopush on;
600
+ tcp_nodelay on;
601
+ keepalive_timeout 65;
602
+ types_hash_max_size 2048;
603
+ server_tokens off;
604
+
605
+ # Gzip compression
606
+ gzip on;
607
+ gzip_vary on;
608
+ gzip_proxied any;
609
+ gzip_comp_level 6;
610
+ gzip_types text/plain text/css text/xml text/javascript
611
+ application/json application/javascript application/xml+rss
612
+ application/rss+xml font/truetype font/opentype
613
+ application/vnd.ms-fontobject image/svg+xml;
614
+ gzip_disable "msie6";
615
+
616
+ # Rate limiting zones
617
+ limit_req_zone $binary_remote_addr zone=api_limit:10m rate=10r/s;
618
+ limit_req_zone $http_authorization zone=auth_limit:10m rate=5r/s;
619
+ limit_conn_zone $binary_remote_addr zone=conn_limit:10m;
620
+
621
+ # Upstream (backend servers)
622
+ upstream api_backend {
623
+ least_conn;
624
+ server api-1:3000 weight=3 max_fails=3 fail_timeout=30s;
625
+ server api-2:3000 weight=3 max_fails=3 fail_timeout=30s;
626
+ server api-3:3000 weight=2 max_fails=3 fail_timeout=30s backup;
627
+
628
+ keepalive 32;
629
+ keepalive_requests 100;
630
+ keepalive_timeout 60s;
631
+ }
632
+
633
+ # Cache configuration
634
+ proxy_cache_path /var/cache/nginx
635
+ levels=1:2
636
+ keys_zone=api_cache:10m
637
+ max_size=1g
638
+ inactive=60m
639
+ use_temp_path=off;
640
+
641
+ # Server block
642
+ server {
643
+ listen 80;
644
+ listen [::]:80;
645
+ server_name api.example.com;
646
+
647
+ # Redirect to HTTPS
648
+ return 301 https://$server_name$request_uri;
649
+ }
650
+
651
+ server {
652
+ listen 443 ssl http2;
653
+ listen [::]:443 ssl http2;
654
+ server_name api.example.com;
655
+
656
+ # SSL configuration
657
+ ssl_certificate /etc/nginx/ssl/api.example.com.crt;
658
+ ssl_certificate_key /etc/nginx/ssl/api.example.com.key;
659
+ ssl_protocols TLSv1.2 TLSv1.3;
660
+ ssl_ciphers HIGH:!aNULL:!MD5;
661
+ ssl_prefer_server_ciphers on;
662
+ ssl_session_cache shared:SSL:10m;
663
+ ssl_session_timeout 10m;
664
+ ssl_stapling on;
665
+ ssl_stapling_verify on;
666
+
667
+ # Security headers
668
+ add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
669
+ add_header X-Frame-Options "SAMEORIGIN" always;
670
+ add_header X-Content-Type-Options "nosniff" always;
671
+ add_header X-XSS-Protection "1; mode=block" always;
672
+ add_header Referrer-Policy "no-referrer-when-downgrade" always;
673
+
674
+ # CORS headers
675
+ add_header Access-Control-Allow-Origin "https://app.example.com" always;
676
+ add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" always;
677
+ add_header Access-Control-Allow-Headers "Authorization, Content-Type" always;
678
+ add_header Access-Control-Max-Age "3600" always;
679
+
680
+ # Handle preflight requests
681
+ if ($request_method = 'OPTIONS') {
682
+ return 204;
683
+ }
684
+
685
+ # Rate limiting
686
+ limit_req zone=api_limit burst=20 nodelay;
687
+ limit_conn conn_limit 10;
688
+
689
+ # API routes
690
+ location /api/v1/ {
691
+ # Auth check (subrequest)
692
+ auth_request /auth;
693
+ auth_request_set $auth_status $upstream_status;
694
+
695
+ # Proxy settings
696
+ proxy_pass http://api_backend;
697
+ proxy_http_version 1.1;
698
+ proxy_set_header Host $host;
699
+ proxy_set_header X-Real-IP $remote_addr;
700
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
701
+ proxy_set_header X-Forwarded-Proto $scheme;
702
+ proxy_set_header Connection "";
703
+
704
+ # Timeouts
705
+ proxy_connect_timeout 60s;
706
+ proxy_send_timeout 60s;
707
+ proxy_read_timeout 60s;
708
+
709
+ # Buffering
710
+ proxy_buffering on;
711
+ proxy_buffer_size 4k;
712
+ proxy_buffers 8 4k;
713
+ proxy_busy_buffers_size 8k;
714
+
715
+ # Caching
716
+ proxy_cache api_cache;
717
+ proxy_cache_key "$scheme$request_method$host$request_uri";
718
+ proxy_cache_valid 200 5m;
719
+ proxy_cache_valid 404 1m;
720
+ proxy_cache_bypass $http_cache_control;
721
+ add_header X-Cache-Status $upstream_cache_status;
722
+
723
+ # Error handling
724
+ proxy_intercept_errors on;
725
+ error_page 502 503 504 /50x.html;
726
+ }
727
+
728
+ # Authentication endpoint
729
+ location = /auth {
730
+ internal;
731
+ proxy_pass http://auth_service/verify;
732
+ proxy_pass_request_body off;
733
+ proxy_set_header Content-Length "";
734
+ proxy_set_header X-Original-URI $request_uri;
735
+ }
736
+
737
+ # Health check
738
+ location /health {
739
+ access_log off;
740
+ return 200 "healthy\n";
741
+ add_header Content-Type text/plain;
742
+ }
743
+
744
+ # Metrics (Prometheus)
745
+ location /metrics {
746
+ stub_status on;
747
+ access_log off;
748
+ allow 10.0.0.0/8;
749
+ deny all;
750
+ }
751
+ }
752
+ }
753
+ ```
754
+
755
+ ### JWT Authentication Implementation
756
+
757
+ #### Node.js JWT Middleware
758
+ ```javascript
759
+ // jwt-auth.js
760
+ const jwt = require('jsonwebtoken');
761
+ const redis = require('redis');
762
+
763
+ const redisClient = redis.createClient({
764
+ host: process.env.REDIS_HOST,
765
+ port: process.env.REDIS_PORT
766
+ });
767
+
768
+ const JWT_SECRET = process.env.JWT_SECRET;
769
+ const JWT_EXPIRES_IN = '1h';
770
+ const REFRESH_TOKEN_EXPIRES_IN = '7d';
771
+
772
+ // Generate tokens
773
+ function generateTokens(userId, payload = {}) {
774
+ const accessToken = jwt.sign(
775
+ { userId, ...payload },
776
+ JWT_SECRET,
777
+ { expiresIn: JWT_EXPIRES_IN, issuer: 'api.example.com' }
778
+ );
779
+
780
+ const refreshToken = jwt.sign(
781
+ { userId, type: 'refresh' },
782
+ JWT_SECRET,
783
+ { expiresIn: REFRESH_TOKEN_EXPIRES_IN, issuer: 'api.example.com' }
784
+ );
785
+
786
+ // Store refresh token in Redis
787
+ redisClient.setex(`refresh:${userId}`, 7 * 24 * 60 * 60, refreshToken);
788
+
789
+ return { accessToken, refreshToken };
790
+ }
791
+
792
+ // Verify middleware
793
+ async function verifyToken(req, res, next) {
794
+ const authHeader = req.headers.authorization;
795
+
796
+ if (!authHeader || !authHeader.startsWith('Bearer ')) {
797
+ return res.status(401).json({ error: 'No token provided' });
798
+ }
799
+
800
+ const token = authHeader.substring(7);
801
+
802
+ try {
803
+ const decoded = jwt.verify(token, JWT_SECRET, {
804
+ issuer: 'api.example.com'
805
+ });
806
+
807
+ // Check if token is blacklisted
808
+ const blacklisted = await redisClient.get(`blacklist:${token}`);
809
+ if (blacklisted) {
810
+ return res.status(401).json({ error: 'Token revoked' });
811
+ }
812
+
813
+ req.user = decoded;
814
+ next();
815
+ } catch (error) {
816
+ if (error.name === 'TokenExpiredError') {
817
+ return res.status(401).json({ error: 'Token expired' });
818
+ }
819
+ return res.status(401).json({ error: 'Invalid token' });
820
+ }
821
+ }
822
+
823
+ // Refresh token
824
+ async function refreshAccessToken(req, res) {
825
+ const { refreshToken } = req.body;
826
+
827
+ try {
828
+ const decoded = jwt.verify(refreshToken, JWT_SECRET);
829
+
830
+ if (decoded.type !== 'refresh') {
831
+ return res.status(401).json({ error: 'Invalid refresh token' });
832
+ }
833
+
834
+ // Check Redis for valid refresh token
835
+ const storedToken = await redisClient.get(`refresh:${decoded.userId}`);
836
+ if (storedToken !== refreshToken) {
837
+ return res.status(401).json({ error: 'Refresh token not found' });
838
+ }
839
+
840
+ // Generate new tokens
841
+ const tokens = generateTokens(decoded.userId);
842
+ res.json(tokens);
843
+ } catch (error) {
844
+ res.status(401).json({ error: 'Invalid refresh token' });
845
+ }
846
+ }
847
+
848
+ // Revoke token
849
+ async function revokeToken(req, res) {
850
+ const authHeader = req.headers.authorization;
851
+ const token = authHeader.substring(7);
852
+
853
+ const decoded = jwt.decode(token);
854
+ const ttl = decoded.exp - Math.floor(Date.now() / 1000);
855
+
856
+ // Blacklist token until expiration
857
+ await redisClient.setex(`blacklist:${token}`, ttl, '1');
858
+
859
+ res.json({ message: 'Token revoked' });
860
+ }
861
+
862
+ module.exports = {
863
+ generateTokens,
864
+ verifyToken,
865
+ refreshAccessToken,
866
+ revokeToken
867
+ };
868
+ ```
869
+
870
+ ## Validation Protocol
871
+
872
+ Before reporting high confidence:
873
+ ✅ Gateway routing configured correctly
874
+ ✅ Authentication/authorization tested
875
+ ✅ Rate limiting enforced and validated
876
+ ✅ SSL/TLS certificates configured
877
+ ✅ Health checks passing
878
+ ✅ Load balancing distributing traffic
879
+ ✅ CORS policies tested
880
+ ✅ Logging and monitoring active
881
+ ✅ Security policies enforced
882
+ ✅ Performance benchmarks met
883
+
884
+ ## Deliverables
885
+
886
+ 1. **Gateway Configuration**: Complete Kong/AWS/Nginx setup
887
+ 2. **Authentication Setup**: OAuth2/JWT implementation
888
+ 3. **Rate Limiting Rules**: Comprehensive throttling configuration
889
+ 4. **Security Policies**: CORS, SSL, WAF configuration
890
+ 5. **Load Balancing**: Upstream configuration with health checks
891
+ 6. **Monitoring Integration**: Metrics and logging setup
892
+ 7. **Documentation**: API gateway architecture, usage guide
893
+
894
+ ## Success Metrics
895
+ - 99.9% uptime
896
+ - P95 latency <100ms
897
+ - Rate limiting accuracy 100%
898
+ - Zero authentication bypasses
899
+ - Confidence score ≥ 0.90
900
+
901
+ ## Skill References
902
+ → **Kong Configuration**: `.claude/skills/kong-gateway/SKILL.md`
903
+ → **AWS API Gateway**: `.claude/skills/aws-api-gateway/SKILL.md`
904
+ → **OAuth2/JWT**: `.claude/skills/oauth2-jwt-auth/SKILL.md`
905
+ → **Nginx Reverse Proxy**: `.claude/skills/nginx-reverse-proxy/SKILL.md`