# BLUEPRINT: 2_ENTITIES

**Goal:** Define all data models from spec.

**Done when:** All entities defined with fields, access rules, visibility. Exported from index.ts.

**Prerequisite:** Phase 0 (spec) and Phase 1 (scaffold) complete.

---

## Step 1: Review Spec Entities

From your spec, you have a list of entities with fields and access rules.

**READ:** `guides/wai-way/entity_patterns.md` for common schemas:
- UserProfile, Post, Product, Order, Review, Comment
- Category, Settings, Workspace, Invitation, Media, ActivityLog

---

## Step 2: Create Entity Files

For each entity in spec:

1. Find matching pattern in `entity_patterns.md`
2. Copy pattern → `entities/[Entity].ts`
3. Customize fields from spec
4. Set access rules from spec

**READ:** `entities/ExampleEntity.ts` for the base pattern.

```typescript
// entities/Product.ts
import { defineEntity } from '@donotdev/core';

export const productEntity = defineEntity({
  name: 'Product',
  collection: 'products',
  fields: {
    // Fields from spec...
  },
  access: {
    // Access rules from spec...
  },
});
```

---

## Step 3: Export Entities

```typescript
// entities/index.ts
export { productEntity } from './Product';
export { customerEntity } from './Customer';
export { orderEntity } from './Order';
```

---

## Field Type Quick Reference

| Type | Use for |
|------|---------|
| `text` | Single-line text |
| `textarea` | Multi-line text |
| `richtext` | Rich text editor |
| `number` | Numbers |
| `email` | Email addresses |
| `tel` | Phone numbers |
| `url` | URLs |
| `select` | Dropdown with options |
| `combobox` | Searchable dropdown |
| `multiselect` | Multiple selection |
| `switch` | On/off toggle |
| `date` | Date picker |
| `timestamp` | Date + time |
| `image` | Single image |
| `images` | Multiple images |
| `file` | Single file |
| `files` | Multiple files |
| `address` | Address autocomplete |

---

## Access Levels

| Level | Who |
|-------|-----|
| `guest` | Anyone |
| `user` | Authenticated |
| `owner` | Creator only |
| `admin` | Admins |
| `super` | Super admins |
| `never` | No one |

---

## Output

- [ ] All entities from spec defined in `entities/`
- [ ] Fields match spec
- [ ] Access rules match spec
- [ ] Exported from `entities/index.ts`
