# CM Price Kit architecture

## Core rule

The kit is not a market scanner. It is a safe price-file engine.

```text
prices.json input
  ↓
preview/adapt/channel calculations
  ↓
explicit apply or export
  ↓
prices.json output
```

## Layers

```text
lib/bootstrap.php
  generic config, JSON, paths, date helpers

lib/price_copy.php
  copy/adapt preview and safe apply

lib/channel_align.php
  OTA/direct price comparison layer

api/*.php
  thin JSON endpoints

index.php + public/js + public/css
  standalone admin UI
```

## Safety contract

- Preview never writes.
- Apply requires `confirm_apply=true`.
- Apply recalculates preview server-side.
- Browser rows are never trusted as write input.
- Backup is created before writing.
- Per-unit lock prevents concurrent writes.
- Audit log is appended after successful write.

## CM compatibility

The kit supports both common formats:

```json
{
  "2026-08-01": 180
}
```

and:

```json
{
  "prices": {
    "2026-08-01": 180
  }
}
```

It preserves the existing shape when applying changes.
