---
domain: domain-model
last_rule_review_commit: 1f1527d7c6b8f115ba12c951c9919d779f071b23
last_rule_updated_at: 2026-06-01
---

# domain-model

## 목적 / 책임

ALT의 핵심 business vocabulary를 Go 타입으로 표현한다. market, instrument, price, bar, backtest run, strategy, portfolio state, and analysis result concepts stay transport- and storage-free here.

## 포함 경로

- `packages/domain/` - shared Go domain model module
- `packages/domain/market/` - market, venue, currency, instrument, OHLCV bar types
- `packages/domain/backtest/` - backtest run spec, run state, result types

## 제외 경로

- `packages/contracts/` - external protobuf schema representation
- `services/api/` - socket transport and API boundary
- `services/worker/` - execution and scheduled job boundary

## 주요 구성 요소

- `market.Instrument` - tradable instrument identity and provider symbol mapping
- `market.UniverseSelector` - provider import universe vocabulary
- `market.Bar` - timeframe OHLCV market data point
- `backtest.RunSpec` - strategy, market, timeframe, period inputs for a run
- `backtest.Run` - backtest lifecycle state
- `backtest.Result` - backtest financial summary, trades, positions, summary metrics, and equity curve
- `backtest.Strategy`, `backtest.StrategyInput`, `backtest.OrderIntent` - strategy execution vocabulary
- `backtest.PortfolioState`, `backtest.Fill`, `backtest.Position` - portfolio accounting state and fill application
- `backtest.TotalReturn` - decimal return calculation helper backed by rational arithmetic

## 유지할 패턴

- Domain type names should stay concise and market-neutral unless a market-specific rule is unavoidable.
- Decimal values are represented as strings through `market.Decimal`; avoid float types for prices and quantities.
- Portfolio and return calculations use exact decimal/rational conversion, not floating point arithmetic.
- Keep package dependencies inward: domain packages should not import API, worker, CLI, Flutter, protobuf generated code, database drivers, or proto-socket.

## 다른 도메인과의 경계

- **contracts**: domain-model owns internal Go vocabulary; contracts owns protobuf wire schema and compatibility.
- **worker**: domain-model defines the shapes; worker executes imports, normalization, backtests, persistence, and socket mapping.
- **api**: domain-model may be mapped to responses, but API transport details stay outside this module.

## 금지 사항

- Do not add persistence annotations, socket parser logic, or environment configuration here.
- Do not introduce generated protobuf code into this package.
- Do not use `float32` or `float64` for money, price, or quantity values.
