# Note3 Data Structures

## Block

A block is the fundamental content unit in note3. Each block represents a discrete piece of information.

**Properties:**

- `type` - Block type: `'text'`, `'smartlist'`, or `'tabs'`
- `content` - TiptapContent: Rich text editor content with `content` and `type` fields
- `mirrors` - Optional string marking if block is mirrored
- `pullUrl` - Optional URL for pulling block content from external source

**In applogs**, Block properties are stored with `block/` prefix:

- `block/type`
- `block/content`
- `block/mirrors`
- `block/pullUrl`

**Notes:**

- Each block has an `en` (entity ID) - a unique identifier
- Block content is edited through the TiptapContent structure (tiptap editor format)
- Content changes are persisted via applogs with debouncing

## Relation

A relation defines the hierarchical structure and ordering of blocks. It's the relationship between a block and its parent.

**Properties:**

- `block` - The child block ID
- `childOf` - The parent block ID
- `after` - Optional sibling block ID; indicates this block comes after the specified sibling
- `isExpanded` - Optional boolean; UI state for whether block is expanded
- `isReply` - Optional boolean; marks this as a reply block
- `isMirror` - Optional boolean; marks this as a mirrored block

**In applogs**, Relation properties are stored with `relation/` prefix:

- `relation/block`
- `relation/childOf`
- `relation/after`
- `relation/isExpanded`
- `relation/isReply`
- `relation/isMirror`

**Notes:**

- Each relation has an `en` (entity ID) - a unique identifier
- A relation represents a single parent-child link with ordering information
- `after` enables ordered lists: child blocks are sorted by their `after` reference

## Entity

Both Block and Relation inherit from Entity.

**Properties:**

- `isDeleted` - Optional boolean; soft delete flag

## How They Work Together

```
Block (id: parent-123)
├─ Relation (id: rel-1, childOf: parent-123, block: child-456, after: null)
│  └─ Block (id: child-456)
├─ Relation (id: rel-2, childOf: parent-123, block: child-789, after: child-456)
│  └─ Block (id: child-789)
```

- Each block can have multiple relations pointing to it as parent (`childOf`)
- Multiple relations can reference the same block (`block`), creating multiple placement contexts
- Relations establish tree structure with sibling ordering via `after` field
- VMs (ViewModels) wrap these structures for reactive UI binding

**Storage:**

- Data is stored as applogs (append-only event logs)
- Each property change creates a new applog entry
- Applogs use `at` (attribute), `vl` (value), `en` (entity ID), and `ag` (agent ID)
