feat: APISIX gateway with Docker Compose orchestration for stock microservices

- APISIX declarative config with versioned API routes (/api/v1/{service}/...)
- proxy-rewrite for path transformation, CORS global rule, rate limiting (100 req/s)
- Active health checks on all 6 upstream services
- Docker Compose with 11 containers: Redis, PostgreSQL, MongoDB, 6 Python services, APISIX, Next.js frontend
- Environment config via .env.example

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
yakenator
2026-02-23 13:50:26 +09:00
commit 042391ae7f
4 changed files with 496 additions and 0 deletions

298
apisix/conf/apisix.yaml Normal file
View File

@ -0,0 +1,298 @@
# APISIX Standalone mode - declarative configuration
# All routes, upstreams, and plugins defined here
routes:
# === DART Collector (port 8001) ===
- id: dart-health
uri: /api/v1/dart/health
upstream_id: dart
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/dart/(.*)", "/$1"]
- id: dart-streams
uri: /api/v1/dart/streams
upstream_id: dart
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/dart/(.*)", "/$1"]
- id: dart-collect
uri: /api/v1/dart/collect/*
methods: [POST]
upstream_id: dart
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/dart/(.*)", "/$1"]
# === KIS Collector (port 8002) ===
- id: kis-health
uri: /api/v1/kis/health
upstream_id: kis
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/kis/(.*)", "/$1"]
- id: kis-streams
uri: /api/v1/kis/streams
upstream_id: kis
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/kis/(.*)", "/$1"]
- id: kis-stocks-list
uri: /api/v1/kis/stocks
methods: [GET]
upstream_id: kis
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/kis/(.*)", "/$1"]
- id: kis-stocks-detail
uri: /api/v1/kis/stocks/*
methods: [GET]
upstream_id: kis
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/kis/(.*)", "/$1"]
- id: kis-collect
uri: /api/v1/kis/collect/*
methods: [POST]
upstream_id: kis
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/kis/(.*)", "/$1"]
# === News Crawler (port 8003) ===
- id: news-health
uri: /api/v1/news/health
upstream_id: news
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/news/(.*)", "/$1"]
- id: news-streams
uri: /api/v1/news/streams
upstream_id: news
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/news/(.*)", "/$1"]
- id: news-collect
uri: /api/v1/news/collect/*
methods: [POST]
upstream_id: news
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/news/(.*)", "/$1"]
# === Screener (port 8004) ===
- id: screener-health
uri: /api/v1/screening/health
upstream_id: screener
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/screening/(.*)", "/$1"]
- id: screener-streams
uri: /api/v1/screening/streams
upstream_id: screener
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/screening/(.*)", "/$1"]
- id: screener-screen
uri: /api/v1/screening/screen
methods: [POST]
upstream_id: screener
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/screening/(.*)", "/$1"]
- id: screener-results
uri: /api/v1/screening/results/*
upstream_id: screener
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/screening/(.*)", "/$1"]
# === Catalyst (port 8005) ===
- id: catalyst-health
uri: /api/v1/catalyst/health
upstream_id: catalyst
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/catalyst/(.*)", "/$1"]
- id: catalyst-streams
uri: /api/v1/catalyst/streams
upstream_id: catalyst
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/catalyst/(.*)", "/$1"]
- id: catalyst-detect
uri: /api/v1/catalyst/detect
methods: [POST]
upstream_id: catalyst
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/catalyst/(.*)", "/$1"]
- id: catalyst-results
uri: /api/v1/catalyst/results/*
upstream_id: catalyst
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/catalyst/(.*)", "/$1"]
# === LLM Analyzer (port 8006) ===
- id: llm-health
uri: /api/v1/analysis/health
upstream_id: llm
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/analysis/(.*)", "/$1"]
- id: llm-streams
uri: /api/v1/analysis/streams
upstream_id: llm
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/analysis/(.*)", "/$1"]
- id: llm-analyze
uri: /api/v1/analysis/analyze
methods: [POST]
upstream_id: llm
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/analysis/(.*)", "/$1"]
- id: llm-results
uri: /api/v1/analysis/results/*
upstream_id: llm
plugins:
proxy-rewrite:
regex_uri: ["^/api/v1/analysis/(.*)", "/$1"]
# === Aggregated health check (version-independent) ===
- id: gateway-health
uri: /api/health
plugins:
serverless-pre-function:
phase: rewrite
functions:
- "return function(conf, ctx) local core = require('apisix.core'); core.response.exit(200, '{\"gateway\":\"ok\",\"version\":\"v1\"}'); end"
upstreams:
- id: dart
type: roundrobin
nodes:
"stock-dart-collector:8001": 1
checks:
active:
type: http
http_path: /health
healthy:
interval: 10
successes: 2
unhealthy:
interval: 5
http_failures: 3
- id: kis
type: roundrobin
nodes:
"stock-kis-collector:8002": 1
checks:
active:
type: http
http_path: /health
healthy:
interval: 10
successes: 2
unhealthy:
interval: 5
http_failures: 3
- id: news
type: roundrobin
nodes:
"stock-news-crawler:8003": 1
checks:
active:
type: http
http_path: /health
healthy:
interval: 10
successes: 2
unhealthy:
interval: 5
http_failures: 3
- id: screener
type: roundrobin
nodes:
"stock-screener:8004": 1
checks:
active:
type: http
http_path: /health
healthy:
interval: 10
successes: 2
unhealthy:
interval: 5
http_failures: 3
- id: catalyst
type: roundrobin
nodes:
"stock-catalyst:8005": 1
checks:
active:
type: http
http_path: /health
healthy:
interval: 10
successes: 2
unhealthy:
interval: 5
http_failures: 3
- id: llm
type: roundrobin
nodes:
"stock-llm-analyzer:8006": 1
checks:
active:
type: http
http_path: /health
healthy:
interval: 10
successes: 2
unhealthy:
interval: 5
http_failures: 3
global_rules:
- id: cors
plugins:
cors:
allow_origins: "*"
allow_methods: "GET,POST,PUT,DELETE,OPTIONS"
allow_headers: "*"
max_age: 3600
- id: rate-limit
plugins:
limit-req:
rate: 100
burst: 50
key_type: var
key: remote_addr
rejected_code: 429
#END