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63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# ==============================================================================
# Cross-Bank Federated Intelligence (CFI) β€” Local Consortium Sandbox Topology
# Reproducible Multi-Container Local Sandbox: 3 Institutional Workers,
# PSI Coordinator, Operational FastAPI Backend, React Frontend, HTTP Gateway,
# PostgreSQL 16, and Redis 7.2 on isolated Docker bridge networks.
#
# Security & Scope Note:
#   - This file defines a local single-host Docker sandbox for consortium testing.
#   - All host-published ports bind strictly to 127.0.0.1 (localhost only).
#   - PostgreSQL and Redis are internal-only on consortium-core-net (no host ports).
#   - The reverse proxy gateway serves HTTP on 127.0.0.1:80; production TLS/mTLS,
#     HSM key custody, and independent multi-institution infrastructure are
#     explicitly deferred to production security-hardening deployment.
#
# Usage:
#   1. Generate authoritative secrets:
#      python scripts/generate_consortium_deployment_secrets.py --output .env.consortium
#   2. Start consortium environment:
#      docker compose -f docker-compose.consortium.yml --env-file .env.consortium up -d
#   3. Bootstrap consortium governance & private entity vaults:
#      python scripts/bootstrap_consortium_deployment.py --env-file .env.consortium
# ==============================================================================

services:
  # ── 1. Local HTTP Reverse Proxy Gateway ─────────────────────────────────────
  gateway:
    image: nginx:1.27-alpine
    container_name: cfi-gateway
    restart: unless-stopped
    ports:
      - "127.0.0.1:${CFI_PORT_HTTP:-80}:80"
    volumes:
      - ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
    depends_on:
      backend:
        condition: service_healthy
      frontend:
        condition: service_healthy
    networks:
      - consortium-core-net
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://127.0.0.1/gateway-health"]
      interval: 5s
      timeout: 3s
      retries: 5

  # ── 2. Frontend Web Container (React 19 SPA) ────────────────────────────────
  frontend:
    build:
      context: .
      dockerfile: docker/Dockerfile.frontend
    image: cfi-intelligence/frontend:latest
    container_name: cfi-frontend
    restart: unless-stopped
    ports:
      - "127.0.0.1:${CFI_PORT_FRONTEND:-3000}:80"
    networks:
      - consortium-core-net
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://127.0.0.1/health"]
      interval: 5s
      timeout: 3s
      retries: 3

  # ── 3. Database Schema Migrations ───────────────────────────────────────────
  migrations:
    image: cfi-intelligence/backend:latest
    container_name: cfi-consortium-migrations
    restart: "no"
    working_dir: /app/backend
    environment:
      - APP_ENV=production
      - DATABASE_TYPE=postgres
      - POSTGRES_HOST=postgres
      - POSTGRES_PORT=5432
      - POSTGRES_USER=${POSTGRES_USER:-cfi_admin}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB:-cfi_fraud_db}
      - DATABASE_URL=postgresql+asyncpg://${POSTGRES_USER:-cfi_admin}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-cfi_fraud_db}
      - ALEMBIC_DATABASE_URL=postgresql+asyncpg://${POSTGRES_USER:-cfi_admin}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-cfi_fraud_db}
    command: ["alembic", "upgrade", "head"]
    depends_on:
      postgres:
        condition: service_healthy
    networks:
      - consortium-core-net

  # ── 4. Operational FastAPI Backend & Federation Engine ──────────────────────
  backend:
    build:
      context: .
      dockerfile: docker/Dockerfile.backend
    image: cfi-intelligence/backend:latest
    container_name: cfi-api-server
    restart: unless-stopped
    command: ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]
    environment:
      - APP_ENV=production
      - LOG_LEVEL=${LOG_LEVEL:-INFO}
      - DATABASE_TYPE=postgres
      - POSTGRES_HOST=postgres
      - POSTGRES_PORT=5432
      - POSTGRES_USER=${POSTGRES_USER:-cfi_admin}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB:-cfi_fraud_db}
      - DATABASE_URL=postgresql+asyncpg://${POSTGRES_USER:-cfi_admin}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-cfi_fraud_db}
      - TRAINING_JOB_DB_URL=postgresql://${POSTGRES_USER:-cfi_admin}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-cfi_fraud_db}
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - REDIS_PASSWORD=${REDIS_PASSWORD}
      - REDIS_URL=redis://:${REDIS_PASSWORD}@redis:6379/0
      - SECRET_KEY=${SECRET_KEY}
      - JWT_SECRET=${SECRET_KEY}
      - CFI_JWT_SECRET=${SECRET_KEY}
      - CFI_JWT_SIGNING_SECRET=${SECRET_KEY}
      - OIDC_JWT_SIGNING_SECRET=${OIDC_JWT_SIGNING_SECRET}
      - PAYLOAD_SIGNING_SECRET=${PAYLOAD_SIGNING_SECRET}
      - TRAINING_COORDINATOR_TOKEN=${TRAINING_COORDINATOR_TOKEN}
      - TRAINING_WORKER_TOKEN=${TRAINING_WORKER_TOKEN}
      - IDENTITY_STORE_SECRET=${IDENTITY_STORE_SECRET}
      - CFI_IDENTITY_STORE_SECRET=${IDENTITY_STORE_SECRET}
      - CFI_AUDIT_LEDGER_SECRET=${CFI_AUDIT_LEDGER_SECRET}
      - CFI_CONSORTIUM_STORE_SECRET=${CFI_CONSORTIUM_STORE_SECRET}
      - CONSORTIUM_HMAC_SALT=${CONSORTIUM_HMAC_SALT}
      - CFI_REGULATORY_ENVELOPE_SECRET=${CFI_REGULATORY_ENVELOPE_SECRET}
      - CFI_CRON_SECRET=${CFI_CRON_SECRET}
      - CFI_COORDINATOR_URL=http://coordinator:8200
      - CFI_COORDINATOR_SECRET=${CFI_COORDINATOR_SECRET}
      - CFI_INSTITUTIONAL_PUBLIC_KEYS_JSON=${CFI_INSTITUTIONAL_PUBLIC_KEYS_JSON}
      - CFI_STORAGE_DIR=/app/storage
    ports:
      - "127.0.0.1:${CFI_PORT_BACKEND:-8000}:8000"
    volumes:
      - consortium-backend-storage:/app/storage
    networks:
      - consortium-core-net
      - consortium-mesh-net
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      migrations:
        condition: service_completed_successfully
      coordinator:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://127.0.0.1:8000/health"]
      interval: 5s
      timeout: 3s
      start_period: 60s
      retries: 10

  # ── 5. Private Set Intersection (PSI) Coordinator ───────────────────────────
  coordinator:
    build:
      context: .
      dockerfile: docker/Dockerfile.institutional_worker
    image: cfi-institutional-worker:latest
    container_name: cfi-coordinator
    restart: unless-stopped
    command:
      - "python"
      - "-m"
      - "app.application.services.isolated_matching_service"
      - "--role"
      - "coordinator"
      - "--host"
      - "0.0.0.0"
      - "--port"
      - "8200"
      - "--worker-a-bank"
      - "bank_a"
      - "--worker-a-url"
      - "http://worker-bank-a:8100"
      - "--worker-a-token"
      - "${WORKER_BANK_A_MATCHING_TOKEN}"
      - "--worker-b-bank"
      - "bank_b"
      - "--worker-b-url"
      - "http://worker-bank-b:8100"
      - "--worker-b-token"
      - "${WORKER_BANK_B_MATCHING_TOKEN}"
      - "--worker-c-bank"
      - "bank_c"
      - "--worker-c-url"
      - "http://worker-bank-c:8100"
      - "--worker-c-token"
      - "${WORKER_BANK_C_MATCHING_TOKEN}"
    environment:
      - APP_ENV=production
      - CFI_ROLE=coordinator
      - CFI_COORDINATOR_SECRET=${CFI_COORDINATOR_SECRET}
      - CFI_CONSORTIUM_STORE_SECRET=${CFI_CONSORTIUM_STORE_SECRET}
      - CFI_IDENTITY_STORE_SECRET=${IDENTITY_STORE_SECRET}
      - CFI_AUDIT_LEDGER_SECRET=${CFI_AUDIT_LEDGER_SECRET}
      - JWT_SECRET=${SECRET_KEY}
      - CFI_JWT_SECRET=${SECRET_KEY}
      - CFI_JWT_SIGNING_SECRET=${SECRET_KEY}
      - CFI_STORAGE_DIR=/vault
      - CFI_ACCOUNT_STORE_PATH=/vault/auth_identity_store.json
      - CFI_IDENTITY_STORE_PATH=/vault/auth_identity_store.json
      - CFI_CONSORTIUM_STORE_PATH=/vault/consortium_governance_store.json
    volumes:
      - consortium-coordinator-vault:/vault
    ports:
      - "127.0.0.1:${CFI_PORT_COORDINATOR:-8200}:8200"
    networks:
      - consortium-mesh-net
    depends_on:
      worker-bank-a:
        condition: service_healthy
      worker-bank-b:
        condition: service_healthy
      worker-bank-c:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://127.0.0.1:8200/health"]
      interval: 5s
      timeout: 3s
      retries: 5

  # ── 6. Institutional Worker: Bank A ─────────────────────────────────────────
  worker-bank-a:
    image: cfi-institutional-worker:latest
    container_name: cfi-worker-bank-a
    restart: unless-stopped
    command:
      - "python"
      - "-m"
      - "app.application.services.isolated_matching_service"
      - "--role"
      - "worker"
      - "--bank-id"
      - "bank_a"
      - "--port"
      - "8100"
      - "--host"
      - "0.0.0.0"
      - "--storage-root"
      - "/vault"
    environment:
      - APP_ENV=production
      - BANK_ID=bank_a
      - STORAGE_ROOT=/vault
      - CFI_STORAGE_DIR=/vault
      - WORKER_PORT=8100
      - WORKER_HOST=0.0.0.0
      - WORKER_AUTH_SECRET=${WORKER_BANK_A_AUTH_SECRET}
      - WORKER_SIGNING_KEY_FILE=/run/secrets/worker_signing_key.pem
      - WORKER_MATCHING_TOKEN=${WORKER_BANK_A_MATCHING_TOKEN}
      - WORKER_INGESTION_TOKEN=${WORKER_BANK_A_INGESTION_TOKEN}
      - WORKER_ADMIN_TOKEN=${WORKER_BANK_A_ADMIN_TOKEN}
      - WORKER_TRUSTED_PEERS_JSON=${WORKER_BANK_A_TRUSTED_PEERS_JSON}
      - CFI_CONSORTIUM_STORE_SECRET=${CFI_CONSORTIUM_STORE_SECRET}
      - CFI_IDENTITY_STORE_SECRET=${IDENTITY_STORE_SECRET}
      - JWT_SECRET=${SECRET_KEY}
      - CFI_JWT_SECRET=${SECRET_KEY}
      - CFI_JWT_SIGNING_SECRET=${SECRET_KEY}
    ports:
      - "127.0.0.1:${CFI_PORT_WORKER_A:-8101}:8100"
    volumes:
      - consortium-vault-bank-a:/vault
      - ./deploy/consortium/keys/bank_a_signing_key.pem:/run/secrets/worker_signing_key.pem:ro
    networks:
      - consortium-mesh-net
    healthcheck:
      test:
        - "CMD"
        - "python"
        - "-c"
        - "import urllib.request, json, sys; res = json.loads(urllib.request.urlopen('http://127.0.0.1:8100/health', timeout=2).read()); sys.exit(0 if res.get('status') == 'ONLINE' and res.get('ready') is True and bool(str(res.get('signature') or '').strip()) else 1)"
      interval: 5s
      timeout: 3s
      retries: 5

  # ── 7. Institutional Worker: Bank B ─────────────────────────────────────────
  worker-bank-b:
    image: cfi-institutional-worker:latest
    container_name: cfi-worker-bank-b
    restart: unless-stopped
    command:
      - "python"
      - "-m"
      - "app.application.services.isolated_matching_service"
      - "--role"
      - "worker"
      - "--bank-id"
      - "bank_b"
      - "--port"
      - "8100"
      - "--host"
      - "0.0.0.0"
      - "--storage-root"
      - "/vault"
    environment:
      - APP_ENV=production
      - BANK_ID=bank_b
      - STORAGE_ROOT=/vault
      - CFI_STORAGE_DIR=/vault
      - WORKER_PORT=8100
      - WORKER_HOST=0.0.0.0
      - WORKER_AUTH_SECRET=${WORKER_BANK_B_AUTH_SECRET}
      - WORKER_SIGNING_KEY_FILE=/run/secrets/worker_signing_key.pem
      - WORKER_MATCHING_TOKEN=${WORKER_BANK_B_MATCHING_TOKEN}
      - WORKER_INGESTION_TOKEN=${WORKER_BANK_B_INGESTION_TOKEN}
      - WORKER_ADMIN_TOKEN=${WORKER_BANK_B_ADMIN_TOKEN}
      - WORKER_TRUSTED_PEERS_JSON=${WORKER_BANK_B_TRUSTED_PEERS_JSON}
      - CFI_CONSORTIUM_STORE_SECRET=${CFI_CONSORTIUM_STORE_SECRET}
      - CFI_IDENTITY_STORE_SECRET=${IDENTITY_STORE_SECRET}
      - JWT_SECRET=${SECRET_KEY}
      - CFI_JWT_SECRET=${SECRET_KEY}
      - CFI_JWT_SIGNING_SECRET=${SECRET_KEY}
    ports:
      - "127.0.0.1:${CFI_PORT_WORKER_B:-8102}:8100"
    volumes:
      - consortium-vault-bank-b:/vault
      - ./deploy/consortium/keys/bank_b_signing_key.pem:/run/secrets/worker_signing_key.pem:ro
    networks:
      - consortium-mesh-net
    healthcheck:
      test:
        - "CMD"
        - "python"
        - "-c"
        - "import urllib.request, json, sys; res = json.loads(urllib.request.urlopen('http://127.0.0.1:8100/health', timeout=2).read()); sys.exit(0 if res.get('status') == 'ONLINE' and res.get('ready') is True and bool(str(res.get('signature') or '').strip()) else 1)"
      interval: 5s
      timeout: 3s
      retries: 5

  # ── 8. Institutional Worker: Bank C ─────────────────────────────────────────
  worker-bank-c:
    image: cfi-institutional-worker:latest
    container_name: cfi-worker-bank-c
    restart: unless-stopped
    command:
      - "python"
      - "-m"
      - "app.application.services.isolated_matching_service"
      - "--role"
      - "worker"
      - "--bank-id"
      - "bank_c"
      - "--port"
      - "8100"
      - "--host"
      - "0.0.0.0"
      - "--storage-root"
      - "/vault"
    environment:
      - APP_ENV=production
      - BANK_ID=bank_c
      - STORAGE_ROOT=/vault
      - CFI_STORAGE_DIR=/vault
      - WORKER_PORT=8100
      - WORKER_HOST=0.0.0.0
      - WORKER_AUTH_SECRET=${WORKER_BANK_C_AUTH_SECRET}
      - WORKER_SIGNING_KEY_FILE=/run/secrets/worker_signing_key.pem
      - WORKER_MATCHING_TOKEN=${WORKER_BANK_C_MATCHING_TOKEN}
      - WORKER_INGESTION_TOKEN=${WORKER_BANK_C_INGESTION_TOKEN}
      - WORKER_ADMIN_TOKEN=${WORKER_BANK_C_ADMIN_TOKEN}
      - WORKER_TRUSTED_PEERS_JSON=${WORKER_BANK_C_TRUSTED_PEERS_JSON}
      - CFI_CONSORTIUM_STORE_SECRET=${CFI_CONSORTIUM_STORE_SECRET}
      - CFI_IDENTITY_STORE_SECRET=${IDENTITY_STORE_SECRET}
      - JWT_SECRET=${SECRET_KEY}
      - CFI_JWT_SECRET=${SECRET_KEY}
      - CFI_JWT_SIGNING_SECRET=${SECRET_KEY}
    ports:
      - "127.0.0.1:${CFI_PORT_WORKER_C:-8103}:8100"
    volumes:
      - consortium-vault-bank-c:/vault
      - ./deploy/consortium/keys/bank_c_signing_key.pem:/run/secrets/worker_signing_key.pem:ro
    networks:
      - consortium-mesh-net
    healthcheck:
      test:
        - "CMD"
        - "python"
        - "-c"
        - "import urllib.request, json, sys; res = json.loads(urllib.request.urlopen('http://127.0.0.1:8100/health', timeout=2).read()); sys.exit(0 if res.get('status') == 'ONLINE' and res.get('ready') is True and bool(str(res.get('signature') or '').strip()) else 1)"
      interval: 5s
      timeout: 3s
      retries: 5

  # ── 9. PostgreSQL 16 Database (Internal to consortium-core-net) ─────────────
  postgres:
    image: postgres:16-alpine
    container_name: cfi-consortium-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-cfi_admin}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB:-cfi_fraud_db}
    volumes:
      - consortium-postgres-data:/var/lib/postgresql/data
      - ./docker/postgres/01-init.sql:/docker-entrypoint-initdb.d/01-init.sql:ro
    networks:
      - consortium-core-net
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-cfi_admin} -d ${POSTGRES_DB:-cfi_fraud_db}"]
      interval: 5s
      timeout: 3s
      retries: 5

  # ── 10. Redis 7.2 Cache & Broker (Internal to consortium-core-net) ──────────
  redis:
    image: redis:7.2-alpine
    container_name: cfi-consortium-redis
    restart: unless-stopped
    command: >
      redis-server
      --requirepass ${REDIS_PASSWORD}
      --appendonly yes
      --maxmemory 512mb
      --maxmemory-policy volatile-lru
    volumes:
      - consortium-redis-data:/data
    networks:
      - consortium-core-net
    healthcheck:
      test: ["CMD", "redis-cli", "--no-auth-warning", "-a", "${REDIS_PASSWORD}", "ping"]
      interval: 5s
      timeout: 3s
      retries: 3

networks:
  consortium-core-net:
    driver: bridge
    name: cfi-consortium-core-net
  consortium-mesh-net:
    driver: bridge
    name: cfi-consortium-mesh-net

volumes:
  consortium-postgres-data:
  consortium-redis-data:
  consortium-backend-storage:
  consortium-vault-bank-a:
  consortium-vault-bank-b:
  consortium-vault-bank-c:
  consortium-coordinator-vault: