|
1 | | -# ObjectStack CRM Example |
2 | | - |
3 | | -这是一个全面的 CRM (客户关系管理) 示例,展示了 ObjectStack 协议的所有核心功能。 |
4 | | -This is a comprehensive CRM (Customer Relationship Management) example that demonstrates all core features of the ObjectStack Protocol. |
5 | | - |
6 | | -## 🎯 Features Demonstrated |
7 | | - |
8 | | -### Data Protocol (数据协议) |
9 | | - |
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 |
| 1 | +# ObjectStack Enterprise CRM Application |
| 2 | + |
| 3 | +[English](#english) | [中文](#中文) |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## English |
| 8 | + |
| 9 | +### 🎯 Overview |
| 10 | + |
| 11 | +**Enterprise CRM** is a comprehensive, production-ready Customer Relationship Management system built on the ObjectStack Protocol. It demonstrates all 128+ protocol modules across 15 categories, showcasing enterprise-grade architecture following Salesforce and ServiceNow best practices. |
| 12 | + |
| 13 | +### ✨ Key Features |
| 14 | + |
| 15 | +#### 📊 **Complete Data Model** |
| 16 | +- **10 Core Objects** organized by domain (Sales, Service, Marketing, Products) |
| 17 | +- **50+ Field Types** including advanced types (Location, Color, Address) |
| 18 | +- **Comprehensive Relationships** with lookups and master-detail |
| 19 | +- **Smart Validations** with script-based rules and formulas |
| 20 | + |
| 21 | +#### 🔒 **Enterprise Security** |
| 22 | +- **5 User Profiles** (Admin, Sales Manager, Sales Rep, Service Agent, Marketing User) |
| 23 | +- **Role Hierarchy** with 10 roles |
| 24 | +- **Sharing Rules** (criteria-based, owner-based, territory-based) |
| 25 | +- **Field-Level Security** for sensitive data |
| 26 | +- **Organization-Wide Defaults** for baseline access control |
| 27 | + |
| 28 | +#### 🤖 **AI-Powered Automation** |
| 29 | +- **5 AI Agents** (Sales Assistant, Service Agent, Lead Enrichment, Revenue Intelligence, Email Campaign) |
| 30 | +- **4 RAG Pipelines** for knowledge retrieval |
| 31 | +- **Natural Language Queries** for intuitive data access |
| 32 | +- **Predictive Analytics** (lead scoring, revenue forecasting) |
| 33 | + |
| 34 | +#### ⚡ **Business Process Automation** |
| 35 | +- **5 Automated Flows** (Lead Conversion, Opportunity Approval, Case Escalation, Quote Generation, Campaign Enrollment) |
| 36 | +- **Workflow Rules** for field updates and notifications |
| 37 | +- **Approval Processes** for large deals and contracts |
| 38 | +- **Scheduled Jobs** for batch processing |
| 39 | + |
| 40 | +#### 📈 **Analytics & Reporting** |
| 41 | +- **3 Interactive Dashboards** (Sales, Service, Executive) |
| 42 | +- **8 Pre-built Reports** (opportunities, accounts, cases, leads, tasks) |
| 43 | +- **Real-time Metrics** with KPIs and trends |
| 44 | +- **Custom Charts** (funnel, bar, line, pie, table) |
| 45 | + |
| 46 | +### 📁 Architecture |
68 | 47 |
|
69 | 48 | ``` |
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 |
| 49 | +src/ |
| 50 | +├── domains/ # Domain-Driven Design |
| 51 | +│ ├── sales/ # Account, Contact, Lead, Opportunity, Quote, Contract |
| 52 | +│ ├── service/ # Case, Task |
| 53 | +│ ├── marketing/ # Campaign |
| 54 | +│ └── products/ # Product |
| 55 | +├── ui/ # User Interface |
| 56 | +│ ├── dashboards.ts # 3 dashboards |
| 57 | +│ ├── reports.ts # 8 reports |
| 58 | +│ └── actions.ts # Custom actions |
| 59 | +├── security/ # Security Model |
| 60 | +│ ├── profiles.ts # 5 profiles |
| 61 | +│ └── sharing-rules.ts # Sharing and OWD |
| 62 | +├── automation/ # Business Logic |
| 63 | +│ └── flows.ts # 5 flows |
| 64 | +├── ai/ # AI & Machine Learning |
| 65 | +│ ├── agents.ts # 5 AI agents |
| 66 | +│ └── rag-pipelines.ts # 4 RAG pipelines |
| 67 | +└── server/ # Custom APIs |
| 68 | + └── apis.ts # REST endpoints |
86 | 69 | ``` |
87 | 70 |
|
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 |
165 | | - |
166 | | -This package is part of the `examples` workspace. To build it and verify types: |
| 71 | +### 📚 Documentation |
| 72 | + |
| 73 | +Comprehensive guides covering all aspects: |
| 74 | + |
| 75 | +1. **[Data Modeling](./docs/01-data-modeling.md)** - Objects, fields, relationships, validations |
| 76 | +2. **[Business Logic](./docs/02-business-logic.md)** - Workflows, triggers, formulas |
| 77 | +3. **[Security](./docs/05-security.md)** - Profiles, roles, sharing, permissions |
| 78 | +4. **[AI Capabilities](./docs/08-ai-capabilities.md)** - Agents, RAG, NLQ, ML |
| 79 | + |
| 80 | +### 🚀 Quick Start |
167 | 81 |
|
168 | 82 | ```bash |
169 | | -# From monorepo root |
| 83 | +# Install dependencies |
170 | 84 | pnpm install |
171 | 85 |
|
172 | | -# Build the spec package first |
173 | | -pnpm --filter @objectstack/spec build |
174 | | - |
175 | | -# Build this example |
| 86 | +# Build the application |
176 | 87 | pnpm --filter @example/app-crm build |
177 | 88 |
|
178 | | -# Run type checking |
179 | | -pnpm --filter @example/app-crm typecheck |
| 89 | +# Run development server |
| 90 | +pnpm --filter @example/app-crm dev |
180 | 91 | ``` |
181 | 92 |
|
182 | | -## 📖 Learning Resources |
| 93 | +### 📦 What's Included |
| 94 | + |
| 95 | +| Category | Count | Examples | |
| 96 | +|----------|-------|----------| |
| 97 | +| **Objects** | 10 | Account, Opportunity, Case, Product | |
| 98 | +| **Fields** | 100+ | AutoNumber, Formula, Lookup, Address | |
| 99 | +| **Profiles** | 5 | Admin, Sales Manager, Sales Rep | |
| 100 | +| **Sharing Rules** | 5+ | Criteria-based, Territory-based | |
| 101 | +| **AI Agents** | 5 | Sales Assistant, Service Agent | |
| 102 | +| **RAG Pipelines** | 4 | Sales Knowledge, Support KB | |
| 103 | +| **Flows** | 5 | Lead Conversion, Approval | |
| 104 | +| **Dashboards** | 3 | Sales, Service, Executive | |
| 105 | +| **Reports** | 8 | Opportunities, Cases, Leads | |
| 106 | + |
| 107 | +--- |
| 108 | + |
| 109 | +## 中文 |
| 110 | + |
| 111 | +### 🎯 概述 |
| 112 | + |
| 113 | +**企业级CRM** 是基于 ObjectStack 协议构建的综合性、生产就绪的客户关系管理系统。它展示了15个类别中的128+协议模块,遵循 Salesforce 和 ServiceNow 的企业级架构最佳实践。 |
183 | 114 |
|
184 | | -**For Beginners:** |
185 | | -1. Start with [Todo Example](../todo/) for basics |
186 | | -2. Review [Basic Protocol Examples](../basic/) to understand individual protocols |
187 | | -3. Then explore this CRM example for comprehensive implementation |
| 115 | +### ✨ 核心特性 |
188 | 116 |
|
189 | | -**Protocol References in Basic Examples:** |
190 | | -- [Stack Definition](../basic/stack-definition-example.ts) - How to use `defineStack()` |
191 | | -- [Capabilities](../basic/capabilities-example.ts) - Runtime capabilities configuration |
192 | | -- [Auth & Permissions](../basic/auth-permission-example.ts) - RBAC and RLS patterns |
193 | | -- [Automation](../basic/automation-example.ts) - Workflows and approvals |
194 | | -- [AI & RAG](../basic/ai-rag-example.ts) - AI integration patterns |
| 117 | +#### 📊 **完整数据模型** |
| 118 | +- **10个核心对象** 按领域组织(销售、服务、营销、产品) |
| 119 | +- **50+字段类型** 包括高级类型(位置、颜色、地址) |
| 120 | +- **全面的关系** 查找和主从关系 |
| 121 | +- **智能验证** 基于脚本的规则和公式 |
195 | 122 |
|
196 | | -**In This Example:** |
197 | | -Each object file contains detailed comments explaining: |
198 | | -- Field configuration options |
199 | | -- View setup patterns |
200 | | -- Validation rule syntax |
201 | | -- Workflow automation examples |
| 123 | +#### 🔒 **企业级安全** |
| 124 | +- **5种用户配置文件** (管理员、销售经理、销售代表、服务代表、营销用户) |
| 125 | +- **角色层次结构** 包含10个角色 |
| 126 | +- **共享规则** (基于条件、基于所有者、基于区域) |
| 127 | +- **字段级安全** 保护敏感数据 |
| 128 | +- **组织范围默认值** 基线访问控制 |
202 | 129 |
|
203 | | -Study the code to understand: |
204 | | -1. How to define object schemas with Zod |
205 | | -2. How to create relationships between objects |
206 | | -3. How to set up validation and workflow rules |
207 | | -4. How to configure different view types |
208 | | -5. How to create actions, dashboards, and reports |
| 130 | +#### 🤖 **AI驱动自动化** |
| 131 | +- **5个AI代理** (销售助手、服务代理、线索丰富、收入智能、邮件营销) |
| 132 | +- **4个RAG管道** 用于知识检索 |
| 133 | +- **自然语言查询** 直观的数据访问 |
| 134 | +- **预测分析** (线索评分、收入预测) |
209 | 135 |
|
210 | | -## 🎓 Protocol Coverage |
| 136 | +#### ⚡ **业务流程自动化** |
| 137 | +- **5个自动化流程** (线索转换、商机审批、案例升级、报价生成、营销注册) |
| 138 | +- **工作流规则** 字段更新和通知 |
| 139 | +- **审批流程** 大型交易和合同 |
| 140 | +- **定时任务** 批处理 |
211 | 141 |
|
212 | | -This example demonstrates: |
| 142 | +#### 📈 **分析与报表** |
| 143 | +- **3个交互式仪表板** (销售、服务、高管) |
| 144 | +- **8个预制报表** (商机、客户、案例、线索、任务) |
| 145 | +- **实时指标** KPI和趋势 |
| 146 | +- **自定义图表** (漏斗、柱状、折线、饼图、表格) |
213 | 147 |
|
214 | | -| Protocol Area | Coverage | Examples | |
215 | | -|--------------|----------|----------| |
216 | | -| **Data Protocol** | 100% | All field types, validations, workflows | |
217 | | -| **UI Protocol** | 100% | All view types, actions, dashboards, reports | |
218 | | -| **System Protocol** | 80% | App manifest, menus, settings | |
| 148 | +### 📚 文档 |
219 | 149 |
|
220 | | -## 🔗 References |
| 150 | +1. **[数据建模](./docs/01-data-modeling.md)** - 对象、字段、关系、验证 |
| 151 | +2. **[业务逻辑](./docs/02-business-logic.md)** - 工作流、触发器、公式 |
| 152 | +3. **[安全模型](./docs/05-security.md)** - 配置文件、角色、共享、权限 |
| 153 | +4. **[AI能力](./docs/08-ai-capabilities.md)** - 代理、RAG、NLQ、机器学习 |
221 | 154 |
|
222 | | -- [ObjectStack Documentation](https://objectstack.dev) |
223 | | -- [Protocol Specification](../../packages/spec/README.md) |
224 | | -- [Field Types Reference](../../packages/spec/src/data/field.zod.ts) |
225 | | -- [Object Schema Reference](../../packages/spec/src/data/object.zod.ts) |
| 155 | +### 🚀 快速开始 |
| 156 | + |
| 157 | +```bash |
| 158 | +# 安装依赖 |
| 159 | +pnpm install |
| 160 | + |
| 161 | +# 构建应用 |
| 162 | +pnpm --filter @example/app-crm build |
| 163 | + |
| 164 | +# 运行开发服务器 |
| 165 | +pnpm --filter @example/app-crm dev |
| 166 | +``` |
226 | 167 |
|
227 | | -## 📝 License |
| 168 | +--- |
228 | 169 |
|
229 | | -MIT |
| 170 | +**构建全球最顶级的企业管理软件平台** 🚀 |
0 commit comments