Deliver BAT-002: slot-core daemon + HTTP intent API + PostgreSQL

Implement REQ-005~009 (dcy-002 slice 1) as an onion stack on top of the
BAT-001 pure domain:
- application: IntentService (admission + single-writer transition +
  intent_id idempotency via durable intent_log)
- adapters/persistence: PostgreSQLSlotRepository + PostgreSQLIntentStore +
  trex-core-owned migrations (daily_slot per Appendix A, daily_symbol_entries,
  slot_transition_log, intent_log) + in-memory intent store
- adapters/api: FastAPI /v1 (healthz, intents/buy|sell|{id}, slots, capacity)
- runtime: trex-core-daemon entrypoint with lifespan migrate+preallocate

Verification (against local PostgreSQL 18): 74 passed, ruff clean, domain
import sweep shows zero web/db deps (NFR-1), 20-thread concurrency admits
exactly the idle count (NFR-2), idempotent resubmit causes no double
transition (NFR-3), EXPECTED_SLOT_FIELDS<->information_schema drift test
(realizes dcy-001 OQ-2's deferred DB-side check), and a daemon E2E smoke.

Align all four baseline docs to the new daemon/API/persistence layers.
BAT-002 -> release-candidate; REQ-005~009 -> Implemented. Full async outbox,
broker execution, safety floor, and strategy daemons remain deferred to a
follow-up Discovery.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-04 13:46:08 +09:00
co-authored by Claude Opus 4.8
parent a44f9fddb7
commit a4e263c8e7
41 changed files with 1778 additions and 38 deletions
+23 -17
View File
@@ -21,10 +21,11 @@
- storage-agnostic 순수 도메인 (현재 in-memory repository, PostgreSQL/psycopg 는 향후 영속화 단계에서 도입 예정)
## Primary Runtime
- Type: library
- Planned Entry Points:
- SlotService :: 슬롯 생명주기 도메인 서비스 — preallocate / transit / capacity / entry-count 의 in-process API
- SlotRepository (Protocol) :: 저장소 추상화 경계 — 구현체(in-memory, 향후 PostgreSQL)를 주입받는 영속화 계약
- Type: daemon (HTTP API) + library (slot 도메인)
- Entry Points:
- `trex-core-daemon` (console_script → `trex_core.runtime.daemon:main`) :: 슬롯 코어 데몬 — migrate+preallocate lifecycle 후 FastAPI/uvicorn 으로 `/v1` API 서빙 (BAT-002)
- HTTP `/v1` :: 매수·매도 전략 데몬용 intent 제출/조회 경계 (docs/interface-contract.md)
- SlotService / SlotRepository (Protocol) :: in-process 도메인 서비스 + 저장소 경계(라이브러리 사용)
## Purpose
- This document is the current approved repository and package structure baseline.
@@ -55,24 +56,28 @@
│ ├── project-structure.md
│ └── runtime-flows.md
├── CLAUDE.md # SDLC governance instructions
├── pyproject.toml # 패키지 메타(배포명 trex-core) + pytest/ruff 설정
├── pyproject.toml # 패키지 메타(배포명 trex-core) + console_scripts(trex-core-daemon) + deps
├── trex_core/
│ ├── __init__.py
│ └── domain/
│ ├── __init__.py
│ └── slot/ # slot 순수 도메인 (BAT-001 이식)
│ ├── __init__.py # 공개 API (인프라 심볼 없음)
│ ├── state.py # SlotState 6상태 + 전이
│ ├── models.py # Slot/SlotCapacity/SlotTransitionRecord + EXPECTED_SLOT_FIELDS
│ ├── errors.py # 도메인 예외 4종
│ ├── repository.py # SlotRepository Protocol
│ ├── service.py # SlotService
│ └── in_memory_repository.py
│ ├── domain/slot/ # slot 순수 도메인 (BAT-001, 무의존)
│ │ ├── __init__.py · state.py · models.py(+EXPECTED_SLOT_FIELDS) · errors.py
│ │ ├── repository.py(Protocol) · service.py · in_memory_repository.py
│ ├── application/ # 유스케이스 (BAT-002)
│ │ ├── ports.py # IntentStore Protocol
│ │ └── intents.py # IntentService / BuyIntent / SellIntent / IntentDecision
│ ├── adapters/ # 인프라 어댑터 (BAT-002)
│ │ ├── api/ # FastAPI: app.py(create_app /v1) · schemas.py
│ │ └── persistence/ # postgresql.py · in_memory_intent_store.py · migrate.py · sql/
│ └── runtime/ # 데몬 (BAT-002)
│ ├── config.py # DaemonConfig(env)
│ └── daemon.py # build_app + lifespan(migrate/preallocate) + main(uvicorn)
└── tests/
└── domain/slot/ # test_state / test_service / test_contract
├── domain/slot/ # test_state / test_service / test_contract
├── application/ # test_intent_concurrency (단일 writer)
└── adapters/{api,persistence}/ # API(in-memory) · PG repo/migration/drift
```
> 참고: `trex_core/`·`tests/`·`pyproject.toml` 은 BAT-001(dcy-001 FR-1~FR-5)에서 실제 생성되었다. 영속화·CLI·config 는 이번 범위 밖이다.
> 참고: domain(BAT-001)은 무의존 코어. application/adapters/runtime 은 BAT-002(dcy-002 FR-1~FR-6)에서 추가. 웹/DB 의존(fastapi/uvicorn/psycopg)은 adapters/runtime 에만 격리(NFR-1).
## Package / Module Responsibilities
@@ -115,3 +120,4 @@
- 2026-06-03 :: bootstrap-baseline 으로 초기 구조 baseline 생성(mixed: trex-orbit 코드 관찰 + 이관 계획 선언).
- 2026-06-03 :: dcy-001 OQ-1 결정 반영 — planned 네임스페이스를 `app/` → `trex_core/` 로 정정(배포명 `trex-core`).
- 2026-06-03 :: BAT-001 이식 완료 반영 — `trex_core/`·`tests/`·`pyproject.toml` planned→실제 정합(REQ-004).
- 2026-06-03 :: BAT-002 — application/adapters/runtime 레이어(데몬+HTTP API+PostgreSQL) 추가, Primary Runtime=daemon+library(REQ-005~009).