# Data models: traffic and settings

Captured HTTP and WebSocket traffic, and the key-value settings store. Part of the [data model reference](./index.md).

## ProxyFlow

**File:** `proxy_flow.py` · **Table:** `proxy_flows` · **Exposure:** API

One HTTP request/response exchange in a vault's history, captured by the
proxy or sent from the replay tool. See
[HTTP history](../../guides/proxy/history.md#what-is-captured) for how flows are
captured and displayed.

| Field | Type | Notes |
|---|---|---|
| `vault_id` | FK → `vaults.id` | Not null, indexed, `ON DELETE CASCADE` |
| `source` | Enum `FlowSource` | Not null, default `PROXY` |
| `method` | String(16) | Not null |
| `scheme` | String(8) | Not null, `http` or `https` |
| `host` | String(255) | Not null, indexed |
| `port` | Integer | Not null |
| `path` | Text | Not null |
| `query` | Text | Nullable, raw query without `?` |
| `http_version` | String(16) | Nullable |
| `request_headers` | JSON | Default `[]`, ordered `[name, value]` pairs |
| `request_body` | LargeBinary | Nullable, raw bytes up to `PROXY_BODY_LIMIT`, content codings kept |
| `request_size` | Integer | Default `0`, full size seen on the wire |
| `request_truncated` | Boolean | Default `False` |
| `status_code` | Integer | Nullable, indexed; null when no response arrived |
| `response_headers` | JSON | Default `[]`, ordered `[name, value]` pairs |
| `response_body` | LargeBinary | Nullable, as for the request |
| `response_size` | Integer | Default `0` |
| `response_truncated` | Boolean | Default `False` |
| `mime_type` | String(255) | Nullable, response `Content-Type` without parameters |
| `duration_ms` | Integer | Nullable |
| `in_scope` | Boolean | Not null, indexed, default `False`; set from the vault scope at capture time |
| `error` | Text | Nullable, for example `Dropped in intercept` |
| `intercepted` | Boolean | Not null, default `False` (server default `false`): a side was held in intercept |
| `edited` | Boolean | Not null, default `False` (server default `false`): a held side was edited before sending |
| `kind` | String(16) | Not null, default `http` (server default): `websocket` for the handshake of a WebSocket session ([WebSocket sessions](../../guides/proxy/websocket.md)) |

The stored messages are always the ones that were actually sent.

**Indexes:** `ix_flow_vault_id_desc (vault_id, id)` for newest-first paging; `ix_flow_vault_created (vault_id, created_at)` for retention by age ([Capture filters, body limits and retention](../../guides/proxy/capture.md)).

**Relationships:** `vault` (backref `Vault.proxy_flows`, `cascade='all,
delete-orphan'`, `passive_deletes=True`).

**Properties:** `url`, the absolute URL with a non-default port and the
query string.

### `FlowSource`
`PROXY` (`proxy`, captured by the intercepting proxy), `REPLAY` (`replay`,
sent from the replay tool)

### `FlowKind`
`HTTP` (`http`), `WEBSOCKET` (`websocket`); stored as the value.

---

## WsSession, WsFrame

**File:** `websocket.py` · **Tables:** `ws_sessions`, `ws_frames` · **Exposure:** API ([WebSocket sessions](../../guides/proxy/websocket.md))

`WsSession` (BaseModel) is the summary of one WebSocket session: `flow_id`
(FK → `proxy_flows.id`, unique, `ON DELETE CASCADE`), `client_frames`,
`server_frames`, `client_bytes`, `server_bytes`, `stored_bytes`,
`dropped_frames` (integers, server default `0`), `extensions`,
`protocol` (String(255)), `opened_at`, `closed_at` (DateTime tz),
`close_code`, `close_reason`, `closed_by` (`client`/`server`), `error`.

`WsFrame` (plain `Base`, no created/updated stamps) is one message:
`flow_id` (FK → `proxy_flows.id`, `ON DELETE CASCADE`), `seq`, `direction`
(String(8)), `opcode` (SmallInteger, RFC 6455 number), `payload`
(LargeBinary, nullable), `size`, `wire_size`, `truncated`, `masked`,
`compressed`, `inflated`, `fragments`, `close_code`, `close_reason`,
`observed_at` (DateTime tz, not null).

**Constraints and indexes:** `uq_ws_frame_flow_seq (flow_id, seq)` for
keyset paging; `ix_ws_frame_flow_direction (flow_id, direction, seq)`.

---

## AppSetting

**File:** `app_setting.py` · **Table:** `app_settings` · **Exposure:**
indirect

A persisted workstation setting, stored as a JSON value under a dotted key.
Saved values take precedence over environment defaults. It is read and
written through `SettingService` (`app/services/setting_service.py`) and
`AppSettingRepository`. There is no generic settings endpoint.

| Field | Type | Notes |
|---|---|---|
| `key` | String(128) | Not null, unique, indexed |
| `value` | JSON | Not null |

Keys in use:

| Key | Written by | Value |
|---|---|---|
| `proxy.listen` | `PUT /api/v1/proxy/settings` | `{"host": str, "port": int}` |
| `proxy.intercept` | `PUT /api/v1/proxy/intercept` | `{"requests", "responses", "in_scope_only"}` booleans (the switch itself is not persisted) |
| `proxy.intercept.rules` | `PUT /api/v1/proxy/intercept/rules` | Ordered list of intercept filter rules |
| `proxy.capture` | `PUT /api/v1/proxy/capture` | Capture filter, rules and body limits ([Capture filters, body limits and retention](../../guides/proxy/capture.md)) |
| `proxy.retention` | `PUT /api/v1/proxy/retention` | History retention policy ([Capture filters, body limits and retention](../../guides/proxy/capture.md#retention-proxyretention)) |
