> ## Documentation Index
> Fetch the complete documentation index at: https://sonamu.cartanova.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Tips and Tricks

> How to use Sonamu UI efficiently

Here are **practical tips and best practices** for using Sonamu UI more efficiently.

## Keyboard Shortcuts

Essential shortcuts for quick work:

| Shortcut        | Function   | Description                  |
| --------------- | ---------- | ---------------------------- |
| `⌘K` / `Ctrl+K` | Search     | Open global search modal     |
| `Esc`           | Close      | Close open modal             |
| `⌘S` / `Ctrl+S` | Save       | Save current edit            |
| `Tab`           | Next field | Move to next field in forms  |
| `Enter`         | Confirm    | Submit form or complete edit |

<Tip>**Use search**: Open search with `⌘K` to quickly find Entity names, field names, etc.</Tip>

## Entity Management Tips

### 1. Structure Parent-Child Entities

Organize related Entities in parent-child relationships:

```
Order (parent)
├── OrderItem (child)
├── OrderPayment (child)
└── OrderShipment (child)
```

**Benefits**:

* Displayed hierarchically in sidebar
* Easy to find related Entities
* Logical grouping

### 2. Consistent Naming Conventions

| Type       | Convention  | Example                   |
| ---------- | ----------- | ------------------------- |
| Entity ID  | PascalCase  | `User`, `OrderItem`       |
| Field name | snake\_case | `created_at`, `user_id`   |
| Enum       | PascalCase  | `UserRole`, `OrderStatus` |
| Subset ID  | Uppercase   | `A`, `B`, `C`             |

### 3. Leverage AI Chat

**Writing effective prompts**:

```
❌ Bad example:
"Make a user"

✅ Good example:
"Create an e-commerce User Entity.
Fields: email (unique), name, phone (nullable),
role (enum: admin, user, guest),
created date, last login"
```

**Be specific**:

* Specify field types and constraints
* Describe relationship settings
* Mention index requirements

### 4. Organize Property Order

Arrange fields in meaningful order:

```typescript theme={null}
{
  properties: [
    // 1. Primary Key
    { name: "id", ... },

    // 2. Core information
    { name: "title", ... },
    { name: "content", ... },

    // 3. Foreign keys
    { name: "user_id", ... },
    { name: "category_id", ... },

    // 4. Status/flags
    { name: "status", ... },
    { name: "is_active", ... },

    // 5. Timestamps
    { name: "created_at", ... },
    { name: "updated_at", ... },
  ]
}
```

## Migration Tips

### 1. Run in Small Units Frequently

```
❌ Bad example:
- Modify 10 Entities at once
- Migrate once a week

✅ Good example:
- Modify 1-2 Entities at a time
- Migrate multiple times a day
- Test after each migration
```

### 2. Use Migration Preview

Always check Preview before execution:

**Check items**:

* ✅ Are the columns being added correct?
* ⚠️ Are any columns being deleted?
* 🔄 Are type changes intentional?

### 3. Production Migration Checklist

```
□ Testing complete on Development DB
□ Verification complete on Testing DB
□ Data backup complete
□ Migration Preview checked
□ Rollback plan established
□ Team notified
□ Production DB migration executed
□ Application restarted and verified
```

## Scaffolding Tips

### 1. Batch Generation Strategy

**Project initial**:

```
1. Define all Entities
2. [Select All] → Batch generate Model + Test
3. Add business logic to each Model
```

**During development**:

```
1. Add only one new Entity
2. Select and generate only that Entity
3. Start development immediately
```

### 2. Backup Habit

Backup Models with important business logic before regeneration:

```bash theme={null}
# Backup
cp src/models/User.model.ts src/models/User.model.ts.bak

# Regenerate
[Overwrite in UI]

# Restore needed logic
```

### 3. Utilize Git

Commit generated files immediately to manage change history:

```bash theme={null}
git add src/models/
git commit -m "Generate models for User, Post, Comment"
```

## Subset Usage Tips

### 1. Define Standard Subsets

Define consistent Subsets for all Entities:

```typescript theme={null}
// Apply commonly to all Entities

Subset A: For list
- id
- title (or name)
- 1-2 core fields
- created_at

Subset B: For detail
- All general fields
- Exclude sensitive info
- Include timestamps

Subset C: With relations
- Based on Subset B
- Add needed relations
```

### 2. Performance Optimization

**Include only needed fields**:

```typescript theme={null}
// ❌ Excessive fields
{
  ...allFields,
  author: "User.C",  // All User relations too
  category: "Category.B",
  tags: "Tag.C",
}

// ✅ Optimized
{
  id: true,
  title: true,
  content: true,
  author: "User.A",  // Minimum info only
  category_id: true,
  created_at: true,
}
```

### 3. Subset Selection by API

| API          | Recommended Subset | Reason              |
| ------------ | ------------------ | ------------------- |
| List query   | A                  | Fast response       |
| Detail query | B or C             | Full info           |
| Autocomplete | A (minimized)      | Ultra-fast response |
| Admin page   | C                  | All info            |

## Using Search

### Quick Navigation

Search (`⌘K`) can find:

* **Entity**: `User`, `Post`
* **Fields**: `email`, `created_at`
* **Migration**: Filename search
* **Subset**: `User.Subset A`

**Search tips**:

```
user email       → User Entity's email field
post migration   → Post-related migrations
subset A         → All Subset A's
```

## Workflow Optimization

### New Feature Development Flow

```
1. Define Entity (Entity tab)
   - Quick creation with AI chat
   - Set fields and relations
   ↓
2. Define Subsets (within Entity tab)
   - Create A, B, C standard Subsets
   ↓
3. Run Migration (Migration tab)
   - Check Preview
   - Execute Development → Testing order
   ↓
4. Scaffolding (Scaffolding tab)
   - Generate Model + Test
   ↓
5. Development (code editor)
   - Add Model methods
   - Implement API endpoints
   - Write tests
   ↓
6. Register Fixtures (Fixture tab)
   - Prepare test data
```

### Entity Modification Flow

```
1. Modify Entity (Entity tab)
   - Add/modify/delete fields
   ↓
2. Check Migration Creation (Migration tab)
   - Check auto-generated migration
   ↓
3. Review Preview
   - Confirm intended changes
   - Check data loss risk
   ↓
4. Run Migration
   - Development → Testing order
   ↓
5. Modify Model (if needed)
   - Confirm type auto-sync
   - Add logic using new fields
```

## Using Browser Developer Tools

### Network Tab

Check API calls for debugging:

```
F12 → Network tab

- Migration execution → Check /api/migrate/run
- Entity save → Check /api/entity/save
- Check response content on error
```

### Console Tab

Check error messages:

```
F12 → Console tab

- Check JavaScript errors
- API response error logs
- Network request failure causes
```

## Troubleshooting

### When UI is Slow

**Cause**: Too many Entities or large data
**Solution**:

* Clear browser cache
* Close unnecessary browser tabs
* Restart Sonamu UI

### When Changes Aren't Reflected

**Solution**:

1. Browser refresh (`F5`)
2. Hard reload (`⌘⇧R` / `Ctrl+Shift+R`)
3. Restart API server
4. Restart Sonamu UI

### Entity Save Failed

**Check**:

* Is API server running?
* Do you have file write permission?
* Is field name valid? (reserved word check)
* Is foreign key reference correct?

## Next Steps

<CardGroup cols={2}>
  <Card title="Entity Management" icon="cube" href="/en/tools-and-cli/sonamu-ui/entity-management">
    View Entity management details
  </Card>

  <Card title="Sonamu CLI" icon="terminal" href="/en/tools-and-cli/sonamu-cli">
    Advanced tasks via CLI
  </Card>
</CardGroup>
