# Data Model

## Design principles

- components are metadata-driven
- placement data is separate from catalog data
- plugin-imported components must behave like built-in components
- cable links are first-class entities

## Core entities

### RackTemplate

Describes a rack type that can be instantiated in projects.

Suggested fields:

- `id`
- `name`
- `rack_standard` as `10_inch` or `19_inch`
- `total_u`
- `usable_depth_mm`
- `max_weight_kg`
- `mounting_style`

### Project

- `id`
- `name`
- `owner_id`
- `created_at`
- `updated_at`
- `status`

### RackInstance

- `id`
- `project_id`
- `rack_template_id`
- `label`
- `position_index`

### ComponentDefinition

Catalog entry for a reusable part.

- `id`
- `source_type` as `builtin` or `plugin`
- `plugin_id`
- `manufacturer`
- `part_number`
- `name`
- `category`
- `rack_standard`
- `height_u`
- `width_mm`
- `depth_mm`
- `weight_kg`
- `power_w`
- `price_net`
- `currency`
- `front_svg_asset_id`
- `preview_3d_asset_id`

### ComponentInstance

Placed component inside a rack.

- `id`
- `project_id`
- `rack_instance_id`
- `component_definition_id`
- `start_u`
- `orientation`
- `notes`

### PortDefinition

Optional port model for cable planning.

- `id`
- `component_definition_id`
- `name`
- `side` as `front` or `rear`
- `offset_x_mm`
- `offset_y_mm`
- `offset_z_mm`
- `port_type`

### CableLink

- `id`
- `project_id`
- `from_component_instance_id`
- `from_port_definition_id`
- `to_component_instance_id`
- `to_port_definition_id`
- `cable_type`
- `estimated_length_mm`
- `slack_percent`
- `manual_override_length_mm`

### PluginPack

- `id`
- `name`
- `version`
- `vendor`
- `manifest_version`
- `status`
- `imported_at`

## Validation rules

- `ComponentDefinition.rack_standard` must match `RackTemplate.rack_standard`
- `ComponentInstance.start_u` plus `height_u` must not exceed rack height
- placed components must not overlap
- cable links should only reference valid ports belonging to the selected components

## BOM generation logic

The BOM should aggregate by:

- `manufacturer`
- `part_number`
- optional variant attributes such as color or length

The BOM should be able to combine:

- placed components
- accessory parts
- calculated cables

## Future extensions

- multi-rack room coordinates
- thermal zones
- separate front and rear accessories
- stock and supplier integration
