|
1 | | -# 🚀 ObjectStack Application Development Context |
| 1 | +# 🚀 ObjectStack Enterprise Application Specification |
2 | 2 |
|
3 | | -**Role:** You are the **Product Builder** utilizing the ObjectStack Framework. |
4 | | -**Task:** Configure and assemble a full-stack Enterprise Application. |
5 | | -**Environment:** You are working in a **standalone repository**. You import standard plugins and configure the application manifest. You do NOT modify the core framework code. |
| 3 | +**Role:** You are the **Chief Product Architect** building a complex Enterprise Application (CRM, ERP, HCM). |
| 4 | +**Task:** Design and implement a full-featured metadata-driven application. |
| 5 | +**Environment:** Standalone repository. You import definitions from `@objectstack/spec`. |
6 | 6 |
|
7 | 7 | --- |
8 | 8 |
|
9 | | -## 1. The Application Manifest |
| 9 | +## 1. Architecture: Domain-Driven Design |
| 10 | + |
| 11 | +For complex apps like a CRM, do not dump files into flat folders. Organize by **Business Domain**. |
| 12 | + |
| 13 | +**Recommended Structure:** |
| 14 | +```text |
| 15 | +my-crm-app/ |
| 16 | +├── package.json |
| 17 | +├── objectstack.config.ts (App Manifest) |
| 18 | +├── src/ |
| 19 | +│ ├── domains/ |
| 20 | +│ │ ├── sales/ (Sales Cloud) |
| 21 | +│ │ │ ├── objects/ (Account, Opportunity) |
| 22 | +│ │ │ ├── triggers/ (Revenue Calculation) |
| 23 | +│ │ │ └── views/ (Funnel Reports) |
| 24 | +│ │ ├── service/ (Service Cloud) |
| 25 | +│ │ └── common/ (Shared Resources) |
| 26 | +│ ├── security/ (Profiles, Permissions) |
| 27 | +│ └── i18n/ (Translations) |
| 28 | +``` |
| 29 | + |
| 30 | +## 2. The Protocols Checklist |
| 31 | + |
| 32 | +A "Complete" application must define metadata across these 5 layers: |
| 33 | + |
| 34 | +### Layer 1: Data Model (Deep Structure) |
| 35 | +**Library:** `@objectstack/spec/data` |
| 36 | +* **Objects:** Define entities (`Account`, `Contact`). |
| 37 | +* **Fields:** Use advanced types (`master_detail`, `formula`, `rollup_summary`). |
| 38 | +* **Validation:** Define strict `validation_rules` (e.g., "Discount cannot exceed 20%"). |
| 39 | +* **Indexes:** specific database indexing for performance. |
| 40 | + |
| 41 | +### Layer 2: User Interface (The Workspace) |
| 42 | +**Library:** `@objectstack/spec/ui` |
| 43 | +* **App:** Navigation Menu groups (`Sales`, `Service`, `Settings`). |
| 44 | +* **Views:** |
| 45 | + * `Grid`: Standard tables with filters. |
| 46 | + * `Kanban`: Pipeline visualization. |
| 47 | + * `Calendar`: Event tracking. |
| 48 | +* **Layouts:** |
| 49 | + * `Tabbed`: Organize complex records (Details | Related | History). |
| 50 | + * `Wizard`: Step-by-step guidance. |
| 51 | +* **Actions:** Custom buttons (`Convert Lead`, `Submit for Approval`). |
| 52 | + |
| 53 | +### Layer 3: Analytics (Intelligence) |
| 54 | +**Library:** `@objectstack/spec/ui` (Dashboard/Report) |
| 55 | +* **Reports:** Tabular, Summary, Matrix reports. |
| 56 | +* **Dashboards:** Layouts with Charts (Donut, Bar, Metric) embedding reports. |
| 57 | + |
| 58 | +### Layer 4: Logic & Automation |
| 59 | +**Library:** `@objectstack/spec/system` & `@objectstack/spec/data` (Hooks) |
| 60 | +* **Triggers:** `beforeInsert`, `afterUpdate` hooks for data consistency. |
| 61 | +* **Jobs:** Scheduled tasks (e.g., "Nightly Sync"). |
| 62 | +* **Webhooks:** Inbound/Outbound integration. |
| 63 | + |
| 64 | +### Layer 5: Security & Globalization |
| 65 | +**Library:** `@objectstack/spec/permission` & `@objectstack/spec/system` |
| 66 | +* **Profiles:** Standard, Admin, Read-Only. |
| 67 | +* **Permission Sets:** granular capability grants (`Export Reports`, `Manage Users`). |
| 68 | +* **I18n:** `zh-CN.json`, `en-US.json` for labels and messages. |
| 69 | + |
| 70 | +--- |
10 | 71 |
|
11 | | -An "App" in ObjectStack is a bundle of config that creates a cohesive product. |
| 72 | +## 3. Implementation Patterns |
12 | 73 |
|
13 | | -**Reference:** `packages/spec/src/ui/app.zod.ts` |
| 74 | +### A. Defining a Complex Object (Account) |
| 75 | + |
| 76 | +```typescript |
| 77 | +import { ObjectSchema } from '@objectstack/spec/data'; |
| 78 | + |
| 79 | +export const AccountObject: ObjectSchema = { |
| 80 | + name: 'account', |
| 81 | + label: 'Account', |
| 82 | + enable: { |
| 83 | + audit: true, // Track Field History |
| 84 | + workflow: true, // Allow Process Builder |
| 85 | + files: true // Attachments |
| 86 | + }, |
| 87 | + fields: { |
| 88 | + name: { type: 'text', required: true, searchable: true }, |
| 89 | + |
| 90 | + // Relationship |
| 91 | + parent_id: { |
| 92 | + type: 'lookup', |
| 93 | + reference: 'account', |
| 94 | + label: 'Parent Account' |
| 95 | + }, |
| 96 | + |
| 97 | + // Status Logic |
| 98 | + rating: { |
| 99 | + type: 'select', |
| 100 | + options: ['Hot', 'Warm', 'Cold'], |
| 101 | + defaultValue: 'Warm' |
| 102 | + }, |
| 103 | + |
| 104 | + // Calculated |
| 105 | + pipeline_value: { |
| 106 | + type: 'rollup_summary', |
| 107 | + reference: 'opportunity', |
| 108 | + summaryType: 'sum', |
| 109 | + summaryField: 'amount' |
| 110 | + } |
| 111 | + } |
| 112 | +}; |
| 113 | +``` |
| 114 | + |
| 115 | +### B. Configuring the App & Navigation |
14 | 116 |
|
15 | 117 | ```typescript |
16 | | -// objectstack.config.ts |
17 | 118 | import { App } from '@objectstack/spec/ui'; |
18 | 119 |
|
19 | 120 | export default App.create({ |
20 | | - type: 'app', |
21 | | - name: 'crm', |
22 | | - |
23 | | - // Navigation & Layout |
24 | | - layout: { |
25 | | - brand: { logo: '/logo.svg', color: '#0070f3' }, |
26 | | - menu: [ |
27 | | - { id: 'sales', label: 'Sales', items: ['accounts', 'opportunities'] }, |
28 | | - { id: 'settings', label: 'Admin', items: ['users', 'roles'] } |
29 | | - ] |
| 121 | + name: 'crm_enterprise', |
| 122 | + label: 'Force CRM', |
| 123 | + branding: { |
| 124 | + logo: '/assets/logo.svg', |
| 125 | + primaryColor: '#0F172A' |
30 | 126 | }, |
31 | | - |
32 | | - // Dependencies |
33 | | - plugins: [ |
34 | | - '@objectstack/plugin-sales', |
35 | | - '@objectstack/plugin-marketing' |
| 127 | + navigation: [ |
| 128 | + // Dashboard Entry |
| 129 | + { |
| 130 | + type: 'dashboard', |
| 131 | + id: 'home', |
| 132 | + label: 'Home', |
| 133 | + dashboardName: 'sales_leaderboard' |
| 134 | + }, |
| 135 | + // Object Group |
| 136 | + { |
| 137 | + type: 'group', |
| 138 | + id: 'sales_ops', |
| 139 | + label: 'Sales Operations', |
| 140 | + children: [ |
| 141 | + { type: 'object', id: 'leads', objectName: 'lead', label: 'Leads' }, |
| 142 | + { type: 'object', id: 'deals', objectName: 'opportunity', label: 'Opportunities' } |
| 143 | + ] |
| 144 | + } |
36 | 145 | ] |
37 | 146 | }); |
38 | 147 | ``` |
39 | 148 |
|
40 | | -## 2. Declarative UI (ObjectUI) |
41 | | - |
42 | | -You do not write pages; you define **Views**. |
| 149 | +### C. Defining a Dashboard |
43 | 150 |
|
44 | | -**Reference:** `packages/spec/src/ui/view.zod.ts` |
45 | | - |
46 | | -### List View (The Grid) |
47 | | -```yaml |
48 | | -# customer.list.yml |
49 | | -name: all_customers |
50 | | -object: customer |
51 | | -type: grid |
52 | | -columns: [name, industry, revenue, owner] |
53 | | -filters: [[status, =, active]] |
54 | | -actions: [create, export, delete] |
55 | | -``` |
56 | | -
|
57 | | -### Form View (The Editor) |
58 | | -```yaml |
59 | | -# customer.form.yml |
60 | | -type: layout |
61 | | -layout: |
62 | | - - section: "Basic Info" |
63 | | - columns: 2 |
64 | | - fields: [name, website, phone, industry] |
65 | | - - section: "Financials" |
66 | | - fields: [annual_revenue, credit_rating] |
| 151 | +```typescript |
| 152 | +import { Dashboard } from '@objectstack/spec/ui'; |
| 153 | + |
| 154 | +export const SalesDashboard: Dashboard = { |
| 155 | + name: 'sales_leaderboard', |
| 156 | + layout: 'grid', // 12-column grid |
| 157 | + widgets: [ |
| 158 | + { |
| 159 | + type: 'chart', |
| 160 | + title: 'Revenue by Quarter', |
| 161 | + report: 'revenue_report_q1', // References a Report definition |
| 162 | + chartType: 'bar', |
| 163 | + w: 8, h: 4, x: 0, y: 0 |
| 164 | + }, |
| 165 | + { |
| 166 | + type: 'metric', |
| 167 | + title: 'Total Pipeline', |
| 168 | + expression: 'sum(opportunity.amount)', |
| 169 | + w: 4, h: 4, x: 8, y: 0 |
| 170 | + } |
| 171 | + ] |
| 172 | +} |
67 | 173 | ``` |
68 | 174 |
|
69 | | -## 3. Workflow & Automation |
70 | | -
|
71 | | -**Reference:** `packages/spec/src/data/flow.zod.ts` |
72 | | - |
73 | | -* **Screen Flows:** Multi-step wizards for user data entry. |
74 | | -* **Auto-Launched Flows:** Background data processing triggering on field updates. |
75 | | - |
76 | | -## 4. Key Directives for AI |
77 | | - |
78 | | -* **Config Over Code:** 90% of a standard CRUD app should be `.yml` or `.ts` configuration files, not React/Node code. |
79 | | -* **User Experience:** Focus on the *Metadata* that drives the UX (field labels, help text, empty states). |
80 | | -* **Integration:** Use Standard Actions (`smart_action`) where possible before writing custom code. |
81 | | - |
82 | 175 | --- |
83 | 176 |
|
84 | | -**Instruction:** |
85 | | -When building an app, think **Metadata-First**. Define the Object Model, then the View Layouts, and finally the Navigation structure. |
| 177 | +**Instruction for AI:** |
| 178 | +When asked to "Build a CRM" or "Build an ERP", do not just create one file. |
| 179 | +1. **Plan the Domain Model** first (List all objects and their relationships). |
| 180 | +2. **Define the App Shell** (Navigation). |
| 181 | +3. **Iterate Domain by Domain** (Sales -> Service -> Marketing). |
| 182 | +4. **Always include basic Security** (Admin Profile). |
| 183 | + |
0 commit comments