Skip to content
3 changes: 2 additions & 1 deletion content/docs/references/ai/meta.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"title": "AI Protocol"
"title": "AI Protocol",
"root": true
}
1 change: 1 addition & 0 deletions content/docs/references/data/meta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"title": "Data Protocol",
"root": true,
"pages": [
"core",
"logic",
Expand Down
1 change: 0 additions & 1 deletion content/docs/references/meta.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"label": "Protocol Reference",
"root": true,
"order": 100,
"pages": [
"data",
Expand Down
1 change: 1 addition & 0 deletions content/docs/references/system/meta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"title": "System Protocol",
"root": true,
"pages": [
"identity",
"integration",
Expand Down
1 change: 1 addition & 0 deletions content/docs/references/ui/meta.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"title": "UI Protocol",
"root": true,
"pages": [
"app",
"views",
Expand Down
204 changes: 199 additions & 5 deletions examples/crm/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,210 @@
# ObjectStack CRM Example

This is a reference implementation of a simple CRM schema using the ObjectStack Protocol.
这是一个全面的 CRM (客户关系管理) 示例,展示了 ObjectStack 协议的所有核心功能。
This is a comprehensive CRM (Customer Relationship Management) example that demonstrates all core features of the ObjectStack Protocol.

## Structure
## 🎯 Features Demonstrated

* `src/domains/crm/` - Contains the Object definitions (`Account`, `Contact`, `Opportunity`).
* `objectstack.config.ts` - The application manifest that bundles the objects into an app.
### Data Protocol (数据协议)

## Usage
#### Objects (对象)
- **Account** - 客户账户 (Companies and organizations)
- **Contact** - 联系人 (People associated with accounts)
- **Opportunity** - 销售机会 (Sales opportunities and deals)
- **Lead** - 潜在客户 (Potential customers)
- **Case** - 客户支持案例 (Customer support cases)
- **Task** - 任务活动 (Activities and to-do items)

#### Field Types (字段类型)
- ✅ **Text/String**: text, textarea, email, url, phone, password
- ✅ **Rich Content**: markdown, html
- ✅ **Numbers**: number, currency, percent
- ✅ **Date/Time**: date, datetime, time
- ✅ **Logic**: boolean
- ✅ **Selection**: select, multiselect
- ✅ **Relational**: lookup, master_detail
- ✅ **Media**: avatar, image, file
- ✅ **Calculated**: formula, summary, autonumber

#### Advanced Features (高级功能)
- ✅ **Validation Rules** - Script, uniqueness, state machine, format validation
- ✅ **Workflow Rules** - Field updates, email alerts, automated actions
- ✅ **Permissions** - Object-level and field-level security
- ✅ **History Tracking** - Audit trail for field changes
- ✅ **Relationships** - Lookup and master-detail relationships
- ✅ **Indexes** - Database performance optimization

### UI Protocol (用户界面协议)

#### List Views (列表视图)
- ✅ **Grid View** - Traditional table view
- ✅ **Kanban View** - Card-based workflow view
- ✅ **Calendar View** - Date-based visualization
- ✅ **Gantt View** - Timeline/project view

#### Form Views (表单视图)
- ✅ **Simple Forms** - Single page layout
- ✅ **Tabbed Forms** - Multi-section layout
- ✅ **Dynamic Sections** - Collapsible sections

#### Actions (操作)
- ✅ **Script Actions** - JavaScript execution
- ✅ **URL Actions** - Navigation
- ✅ **Modal Actions** - Popup forms
- ✅ **Flow Actions** - Visual process automation

#### Dashboards (仪表盘)
- ✅ **Sales Dashboard** - Pipeline and revenue metrics
- ✅ **Service Dashboard** - Support case analytics
- ✅ **Executive Dashboard** - High-level overview

#### Reports (报表)
- ✅ **Tabular Reports** - Simple lists
- ✅ **Summary Reports** - Grouped data
- ✅ **Matrix Reports** - Cross-tabulation
- ✅ **Charts** - Bar, line, pie, donut, funnel

## 📂 Structure

```
examples/crm/
├── src/
│ ├── domains/
│ │ └── crm/
│ │ ├── account.object.ts # Account object with all field types
│ │ ├── contact.object.ts # Contact with master-detail
│ │ ├── opportunity.object.ts # Opportunity with workflow
│ │ ├── lead.object.ts # Lead with conversion logic
│ │ ├── case.object.ts # Case with SLA tracking
│ │ └── task.object.ts # Task with polymorphic relations
│ └── ui/
│ ├── actions.ts # Custom actions
│ ├── dashboards.ts # Dashboard definitions
│ └── reports.ts # Report definitions
├── objectstack.config.ts # App configuration
└── README.md # This file
```

## 🚀 Key Highlights

### 1. Account Object
Demonstrates:
- Autonumber fields (`account_number`)
- Formula fields (`full_address`)
- Select with custom colors
- Kanban view by type
- Validation rules (positive revenue, unique name)
- Workflow automation (update last activity)

### 2. Contact Object
Demonstrates:
- Master-detail relationship to Account
- Formula field (`full_name`)
- Email and phone field formats
- Avatar field
- Multiple list views (grid, kanban, calendar)
- Tabbed form layout

### 3. Opportunity Object
Demonstrates:
- Complex workflow with stage-based automation
- State machine validation for stage progression
- Multiple visualizations (grid, kanban, gantt)
- Probability and forecast calculations
- History tracking for audit trail
- Reference filters (contact filtered by account)

### 4. Lead Object
Demonstrates:
- Lead conversion process
- Boolean flags (is_converted)
- Readonly fields for conversion tracking
- Kanban view by status
- Lead source tracking

### 5. Case Object
Demonstrates:
- SLA tracking and violations
- Customer satisfaction ratings
- Escalation workflow
- Priority-based automation
- Resolution time calculation
- Multiple status transitions

### 6. Task Object
Demonstrates:
- Polymorphic relationships (related_to multiple objects)
- Recurring task support
- Time tracking (estimated vs actual)
- Progress percentage
- Calendar visualization
- Overdue detection

### 7. UI Components

**Actions:**
- Convert Lead (Flow action)
- Clone Opportunity (Script action)
- Send Email (Modal action)
- Mass Update (Bulk action with parameters)

**Dashboards:**
- Metric widgets (KPIs)
- Chart widgets (bar, line, pie, funnel)
- Table widgets (top lists)
- Grid layout system

**Reports:**
- Summary reports with grouping
- Matrix reports (2D grouping)
- Embedded charts
- Filter criteria
- Aggregations (sum, avg, count)

## 💡 Usage

This package is part of the `examples` workspace. To build it and verify types:

```bash
# Build the example
pnpm build

# Run type checking
pnpm typecheck
```

## 📖 Learning Resources

Each object file contains detailed comments explaining:
- Field configuration options
- View setup patterns
- Validation rule syntax
- Workflow automation examples

Study the code to understand:
1. How to define object schemas with Zod
2. How to create relationships between objects
3. How to set up validation and workflow rules
4. How to configure different view types
5. How to create actions, dashboards, and reports

## 🎓 Protocol Coverage

This example demonstrates:

| Protocol Area | Coverage | Examples |
|--------------|----------|----------|
| **Data Protocol** | 100% | All field types, validations, workflows |
| **UI Protocol** | 100% | All view types, actions, dashboards, reports |
| **System Protocol** | 80% | App manifest, menus, settings |

## 🔗 References

- [ObjectStack Documentation](https://objectstack.dev)
- [Protocol Specification](../../packages/spec/README.md)
- [Field Types Reference](../../packages/spec/src/data/field.zod.ts)
- [Object Schema Reference](../../packages/spec/src/data/object.zod.ts)

## 📝 License

MIT
91 changes: 81 additions & 10 deletions examples/crm/objectstack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,96 @@ import { App } from '@objectstack/spec';
import { Account } from './src/domains/crm/account.object';
import { Contact } from './src/domains/crm/contact.object';
import { Opportunity } from './src/domains/crm/opportunity.object';
import { Lead } from './src/domains/crm/lead.object';
import { Case } from './src/domains/crm/case.object';
import { Task } from './src/domains/crm/task.object';

import { CrmActions } from './src/ui/actions';
import { CrmDashboards } from './src/ui/dashboards';
import { CrmReports } from './src/ui/reports';

export default App.create({
name: 'crm_example',
label: 'CRM App',
description: 'A simple CRM example demonstrating ObjectStack Protocol',
version: '1.0.0',
description: 'Comprehensive CRM example demonstrating all ObjectStack Protocol features',
version: '2.0.0',

// All objects in the app
objects: [
Account,
Contact,
Opportunity
Opportunity,
Lead,
Case,
Task
],

// Navigation menu structure
menus: [
{
label: 'Sales',
items: [
{ type: 'object', object: 'account' },
{ type: 'object', object: 'contact' },
{ type: 'object', object: 'opportunity' }
]
label: 'Sales',
items: [
{ type: 'object', object: 'lead', label: 'Leads' },
{ type: 'object', object: 'account', label: 'Accounts' },
{ type: 'object', object: 'contact', label: 'Contacts' },
{ type: 'object', object: 'opportunity', label: 'Opportunities' },
{ type: 'divider' },
{ type: 'dashboard', dashboard: 'sales_dashboard', label: 'Sales Dashboard' },
{ type: 'report', report: 'opportunities_by_stage', label: 'Pipeline Report' },
]
},
{
label: 'Service',
items: [
{ type: 'object', object: 'case', label: 'Cases' },
{ type: 'divider' },
{ type: 'dashboard', dashboard: 'service_dashboard', label: 'Service Dashboard' },
{ type: 'report', report: 'cases_by_status_priority', label: 'Case Report' },
]
},
{
label: 'Activities',
items: [
{ type: 'object', object: 'task', label: 'Tasks' },
]
},
{
label: 'Analytics',
items: [
{ type: 'dashboard', dashboard: 'executive_dashboard', label: 'Executive Dashboard' },
{ type: 'dashboard', dashboard: 'sales_dashboard', label: 'Sales Dashboard' },
{ type: 'dashboard', dashboard: 'service_dashboard', label: 'Service Dashboard' },
{ type: 'divider' },
{ type: 'report', report: 'opportunities_by_stage', label: 'Opportunities by Stage' },
{ type: 'report', report: 'won_opportunities_by_owner', label: 'Won Opportunities' },
{ type: 'report', report: 'accounts_by_industry_type', label: 'Accounts Matrix' },
{ type: 'report', report: 'cases_by_status_priority', label: 'Cases by Status' },
{ type: 'report', report: 'sla_performance', label: 'SLA Performance' },
{ type: 'report', report: 'leads_by_source', label: 'Leads by Source' },
]
}
],

// Actions available in the app
actions: Object.values(CrmActions),

// Dashboards
dashboards: Object.values(CrmDashboards),

// Reports
reports: Object.values(CrmReports),

// App-level settings
settings: {
theme: {
primaryColor: '#4169E1',
logo: '/assets/crm-logo.png',
},
features: {
enableGlobalSearch: true,
enableNotifications: true,
enableMobileApp: true,
enableOfflineMode: true,
}
]
}
});
Loading