|
1 | 1 | # ObjectStack CRM Example |
2 | 2 |
|
3 | | -This is a reference implementation of a simple CRM schema using the ObjectStack Protocol. |
| 3 | +这是一个全面的 CRM (客户关系管理) 示例,展示了 ObjectStack 协议的所有核心功能。 |
| 4 | +This is a comprehensive CRM (Customer Relationship Management) example that demonstrates all core features of the ObjectStack Protocol. |
4 | 5 |
|
5 | | -## Structure |
| 6 | +## 🎯 Features Demonstrated |
6 | 7 |
|
7 | | -* `src/domains/crm/` - Contains the Object definitions (`Account`, `Contact`, `Opportunity`). |
8 | | -* `objectstack.config.ts` - The application manifest that bundles the objects into an app. |
| 8 | +### Data Protocol (数据协议) |
9 | 9 |
|
10 | | -## Usage |
| 10 | +#### Objects (对象) |
| 11 | +- **Account** - 客户账户 (Companies and organizations) |
| 12 | +- **Contact** - 联系人 (People associated with accounts) |
| 13 | +- **Opportunity** - 销售机会 (Sales opportunities and deals) |
| 14 | +- **Lead** - 潜在客户 (Potential customers) |
| 15 | +- **Case** - 客户支持案例 (Customer support cases) |
| 16 | +- **Task** - 任务活动 (Activities and to-do items) |
| 17 | + |
| 18 | +#### Field Types (字段类型) |
| 19 | +- ✅ **Text/String**: text, textarea, email, url, phone, password |
| 20 | +- ✅ **Rich Content**: markdown, html |
| 21 | +- ✅ **Numbers**: number, currency, percent |
| 22 | +- ✅ **Date/Time**: date, datetime, time |
| 23 | +- ✅ **Logic**: boolean |
| 24 | +- ✅ **Selection**: select, multiselect |
| 25 | +- ✅ **Relational**: lookup, master_detail |
| 26 | +- ✅ **Media**: avatar, image, file |
| 27 | +- ✅ **Calculated**: formula, summary, autonumber |
| 28 | + |
| 29 | +#### Advanced Features (高级功能) |
| 30 | +- ✅ **Validation Rules** - Script, uniqueness, state machine, format validation |
| 31 | +- ✅ **Workflow Rules** - Field updates, email alerts, automated actions |
| 32 | +- ✅ **Permissions** - Object-level and field-level security |
| 33 | +- ✅ **History Tracking** - Audit trail for field changes |
| 34 | +- ✅ **Relationships** - Lookup and master-detail relationships |
| 35 | +- ✅ **Indexes** - Database performance optimization |
| 36 | + |
| 37 | +### UI Protocol (用户界面协议) |
| 38 | + |
| 39 | +#### List Views (列表视图) |
| 40 | +- ✅ **Grid View** - Traditional table view |
| 41 | +- ✅ **Kanban View** - Card-based workflow view |
| 42 | +- ✅ **Calendar View** - Date-based visualization |
| 43 | +- ✅ **Gantt View** - Timeline/project view |
| 44 | + |
| 45 | +#### Form Views (表单视图) |
| 46 | +- ✅ **Simple Forms** - Single page layout |
| 47 | +- ✅ **Tabbed Forms** - Multi-section layout |
| 48 | +- ✅ **Dynamic Sections** - Collapsible sections |
| 49 | + |
| 50 | +#### Actions (操作) |
| 51 | +- ✅ **Script Actions** - JavaScript execution |
| 52 | +- ✅ **URL Actions** - Navigation |
| 53 | +- ✅ **Modal Actions** - Popup forms |
| 54 | +- ✅ **Flow Actions** - Visual process automation |
| 55 | + |
| 56 | +#### Dashboards (仪表盘) |
| 57 | +- ✅ **Sales Dashboard** - Pipeline and revenue metrics |
| 58 | +- ✅ **Service Dashboard** - Support case analytics |
| 59 | +- ✅ **Executive Dashboard** - High-level overview |
| 60 | + |
| 61 | +#### Reports (报表) |
| 62 | +- ✅ **Tabular Reports** - Simple lists |
| 63 | +- ✅ **Summary Reports** - Grouped data |
| 64 | +- ✅ **Matrix Reports** - Cross-tabulation |
| 65 | +- ✅ **Charts** - Bar, line, pie, donut, funnel |
| 66 | + |
| 67 | +## 📂 Structure |
| 68 | + |
| 69 | +``` |
| 70 | +examples/crm/ |
| 71 | +├── src/ |
| 72 | +│ ├── domains/ |
| 73 | +│ │ └── crm/ |
| 74 | +│ │ ├── account.object.ts # Account object with all field types |
| 75 | +│ │ ├── contact.object.ts # Contact with master-detail |
| 76 | +│ │ ├── opportunity.object.ts # Opportunity with workflow |
| 77 | +│ │ ├── lead.object.ts # Lead with conversion logic |
| 78 | +│ │ ├── case.object.ts # Case with SLA tracking |
| 79 | +│ │ └── task.object.ts # Task with polymorphic relations |
| 80 | +│ └── ui/ |
| 81 | +│ ├── actions.ts # Custom actions |
| 82 | +│ ├── dashboards.ts # Dashboard definitions |
| 83 | +│ └── reports.ts # Report definitions |
| 84 | +├── objectstack.config.ts # App configuration |
| 85 | +└── README.md # This file |
| 86 | +``` |
| 87 | + |
| 88 | +## 🚀 Key Highlights |
| 89 | + |
| 90 | +### 1. Account Object |
| 91 | +Demonstrates: |
| 92 | +- Autonumber fields (`account_number`) |
| 93 | +- Formula fields (`full_address`) |
| 94 | +- Select with custom colors |
| 95 | +- Kanban view by type |
| 96 | +- Validation rules (positive revenue, unique name) |
| 97 | +- Workflow automation (update last activity) |
| 98 | + |
| 99 | +### 2. Contact Object |
| 100 | +Demonstrates: |
| 101 | +- Master-detail relationship to Account |
| 102 | +- Formula field (`full_name`) |
| 103 | +- Email and phone field formats |
| 104 | +- Avatar field |
| 105 | +- Multiple list views (grid, kanban, calendar) |
| 106 | +- Tabbed form layout |
| 107 | + |
| 108 | +### 3. Opportunity Object |
| 109 | +Demonstrates: |
| 110 | +- Complex workflow with stage-based automation |
| 111 | +- State machine validation for stage progression |
| 112 | +- Multiple visualizations (grid, kanban, gantt) |
| 113 | +- Probability and forecast calculations |
| 114 | +- History tracking for audit trail |
| 115 | +- Reference filters (contact filtered by account) |
| 116 | + |
| 117 | +### 4. Lead Object |
| 118 | +Demonstrates: |
| 119 | +- Lead conversion process |
| 120 | +- Boolean flags (is_converted) |
| 121 | +- Readonly fields for conversion tracking |
| 122 | +- Kanban view by status |
| 123 | +- Lead source tracking |
| 124 | + |
| 125 | +### 5. Case Object |
| 126 | +Demonstrates: |
| 127 | +- SLA tracking and violations |
| 128 | +- Customer satisfaction ratings |
| 129 | +- Escalation workflow |
| 130 | +- Priority-based automation |
| 131 | +- Resolution time calculation |
| 132 | +- Multiple status transitions |
| 133 | + |
| 134 | +### 6. Task Object |
| 135 | +Demonstrates: |
| 136 | +- Polymorphic relationships (related_to multiple objects) |
| 137 | +- Recurring task support |
| 138 | +- Time tracking (estimated vs actual) |
| 139 | +- Progress percentage |
| 140 | +- Calendar visualization |
| 141 | +- Overdue detection |
| 142 | + |
| 143 | +### 7. UI Components |
| 144 | + |
| 145 | +**Actions:** |
| 146 | +- Convert Lead (Flow action) |
| 147 | +- Clone Opportunity (Script action) |
| 148 | +- Send Email (Modal action) |
| 149 | +- Mass Update (Bulk action with parameters) |
| 150 | + |
| 151 | +**Dashboards:** |
| 152 | +- Metric widgets (KPIs) |
| 153 | +- Chart widgets (bar, line, pie, funnel) |
| 154 | +- Table widgets (top lists) |
| 155 | +- Grid layout system |
| 156 | + |
| 157 | +**Reports:** |
| 158 | +- Summary reports with grouping |
| 159 | +- Matrix reports (2D grouping) |
| 160 | +- Embedded charts |
| 161 | +- Filter criteria |
| 162 | +- Aggregations (sum, avg, count) |
| 163 | + |
| 164 | +## 💡 Usage |
11 | 165 |
|
12 | 166 | This package is part of the `examples` workspace. To build it and verify types: |
13 | 167 |
|
14 | 168 | ```bash |
| 169 | +# Build the example |
15 | 170 | pnpm build |
| 171 | + |
| 172 | +# Run type checking |
| 173 | +pnpm typecheck |
16 | 174 | ``` |
| 175 | + |
| 176 | +## 📖 Learning Resources |
| 177 | + |
| 178 | +Each object file contains detailed comments explaining: |
| 179 | +- Field configuration options |
| 180 | +- View setup patterns |
| 181 | +- Validation rule syntax |
| 182 | +- Workflow automation examples |
| 183 | + |
| 184 | +Study the code to understand: |
| 185 | +1. How to define object schemas with Zod |
| 186 | +2. How to create relationships between objects |
| 187 | +3. How to set up validation and workflow rules |
| 188 | +4. How to configure different view types |
| 189 | +5. How to create actions, dashboards, and reports |
| 190 | + |
| 191 | +## 🎓 Protocol Coverage |
| 192 | + |
| 193 | +This example demonstrates: |
| 194 | + |
| 195 | +| Protocol Area | Coverage | Examples | |
| 196 | +|--------------|----------|----------| |
| 197 | +| **Data Protocol** | 100% | All field types, validations, workflows | |
| 198 | +| **UI Protocol** | 100% | All view types, actions, dashboards, reports | |
| 199 | +| **System Protocol** | 80% | App manifest, menus, settings | |
| 200 | + |
| 201 | +## 🔗 References |
| 202 | + |
| 203 | +- [ObjectStack Documentation](https://objectstack.dev) |
| 204 | +- [Protocol Specification](../../packages/spec/README.md) |
| 205 | +- [Field Types Reference](../../packages/spec/src/data/field.zod.ts) |
| 206 | +- [Object Schema Reference](../../packages/spec/src/data/object.zod.ts) |
| 207 | + |
| 208 | +## 📝 License |
| 209 | + |
| 210 | +MIT |
0 commit comments