# ADR-006: Chart window + drawing architecture (F4)

**Status:** Accepted  
**Date:** 2026-10-03

## Context

F3 bounded warehouse queries. F4 needs pan-back historical loading and TradingView-like drawings without replacing lightweight-charts or storing drawings in SQLite yet.

## Decision

1. **Historical window** — Candle buffer in a ref; initial warehouse fetch uses **latest N** bars; older bars fetched with `beforeMs` + chunk size; logical range shifted on prepend to preserve viewport.
2. **Drawings** — Provider-independent JSON model anchored on `{ timeSec, price }`; rendered on HTML canvas aligned to chart; hit-testing in canvas module.
3. **Persistence** — `localStorage` key `tradingbite:drawings:v1:{symbol}:{timeframe}`; future account storage can reuse payload shape.
4. **Scoping** — Drawings do not follow symbol/timeframe changes (separate storage keys).
5. **Security** — Text labels sanitized; no `innerHTML` for annotations.

## Rejected

- TradingView APIs / scraping
- Pixel-only anchors
- Server-side drawing DB in F4
- Unbounded candle arrays in React state

## Consequences

- More drawing types = extend type union + canvas renderer.
- Live OANDA remains single bounded request (no pan-back to provider in F4).
