Skip to content

Commit 75058b8

Browse files
committed
2 parents 7cc0dfa + 226bd8e commit 75058b8

22 files changed

Lines changed: 258 additions & 257 deletions

File tree

content/prompts/plugin/project-structure.prompt.md

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ my-plugin/
1818
│ └── copilot-instructions.md # (Copy from content/prompts/plugin/copilot-instructions.md)
1919
├── src/
2020
│ ├── objects/ # 📦 Data Models (*.object.ts, *.hook.ts)
21+
│ │ └── index.ts # ↳ Barrel: re-exports all *.object.ts
2122
│ ├── actions/ # ⚡ Buttons & Actions (*.actions.ts)
23+
│ │ └── index.ts # ↳ Barrel: re-exports all actions
2224
│ ├── flows/ # 🔄 Automation Flows (*.flow.ts)
25+
│ │ └── index.ts
2326
│ ├── dashboards/ # 📊 BI Dashboards (*.dashboard.ts)
27+
│ │ └── index.ts
2428
│ ├── reports/ # 📈 Analytics Reports (*.report.ts)
29+
│ │ └── index.ts
2530
│ ├── apps/ # 🚀 App Configuration (*.app.ts)
31+
│ │ └── index.ts
2632
│ ├── apis/ # 🌐 API Endpoints (*.api.ts)
2733
│ ├── agents/ # 🤖 AI Agents (*.agent.ts)
2834
│ ├── rag/ # 🧠 RAG Pipelines (*.rag.ts)
@@ -77,20 +83,17 @@ src/
7783
## 2. Essential Configuration Files
7884

7985
### A. The Manifest (`objectstack.config.ts`)
80-
This is the heart of your plugin. It registers all metadata so the runtime can load it. Organize imports by type with section comments to match the directory structure.
86+
This is the heart of your plugin. It registers all metadata so the runtime can load it.
87+
88+
**Barrel Pattern (Recommended):** Each type folder has an `index.ts` barrel that re-exports all definitions. The config collects them via `Object.values()` — adding a new file only requires updating the barrel, not the config.
8189

8290
```typescript
8391
import { defineStack } from '@objectstack/spec';
8492

85-
// ─── Objects ────────────────────────────────────────────────────────
86-
import { Project } from './src/objects/project.object';
87-
import { Task } from './src/objects/task.object';
88-
89-
// ─── Actions ────────────────────────────────────────────────────────
90-
import { CompleteTaskAction } from './src/actions/task.actions';
91-
92-
// ─── App ────────────────────────────────────────────────────────────
93-
import { ProjectApp } from './src/apps/project.app';
93+
// ─── Barrel Imports (one per metadata type) ─────────────────────────
94+
import * as objects from './src/objects';
95+
import * as actions from './src/actions';
96+
import * as apps from './src/apps';
9497

9598
export default defineStack({
9699
manifest: {
@@ -101,12 +104,27 @@ export default defineStack({
101104
description: 'Project management capabilities for ObjectStack',
102105
},
103106

104-
objects: [Project, Task],
105-
actions: [CompleteTaskAction],
106-
apps: [ProjectApp],
107+
// Auto-collected from barrel index files
108+
objects: Object.values(objects),
109+
actions: Object.values(actions),
110+
apps: Object.values(apps),
107111
});
108112
```
109113

114+
**Barrel File Example** (`src/objects/index.ts`):
115+
```typescript
116+
// Only re-export *.object.ts definitions
117+
// Hooks (*.hook.ts) and state machines (*.state.ts) are auto-associated by convention
118+
export { Project } from './project.object';
119+
export { Task } from './task.object';
120+
```
121+
122+
> **Workflow:** Adding a new object only requires 2 steps:
123+
> 1. Create `src/objects/invoice.object.ts`
124+
> 2. Add `export { Invoice } from './invoice.object'` to `src/objects/index.ts`
125+
>
126+
> The `objectstack.config.ts` stays unchanged.
127+
110128
### B. Package Definition (`package.json`)
111129
You must depend on `@objectstack/spec` to get the types.
112130

@@ -159,5 +177,6 @@ Enable `strict` mode and path mapping.
159177
1. **Create Folders:** Run `mkdir -p src/objects src/actions src/apps`.
160178
2. **Install Instructions:** Copy `content/prompts/plugin/copilot-instructions.md` to `.github/`.
161179
3. **Init Git:** `git init && echo "node_modules\ndist" > .gitignore`.
162-
4. **First Object:** Create `src/objects/example.object.ts` to test type resolution.
163-
5. **Register:** Import the object in `objectstack.config.ts`.
180+
4. **First Object:** Create `src/objects/example.object.ts`.
181+
5. **Create Barrel:** Create `src/objects/index.ts` with `export { Example } from './example.object'`.
182+
6. **Register:** Import the barrel in `objectstack.config.ts` via `import * as objects from './src/objects'`.
Lines changed: 34 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,25 @@
11
import { defineStack } from '@objectstack/spec';
22

3-
// ─── Objects ────────────────────────────────────────────────────────
4-
import { Account } from './src/objects/account.object';
5-
import { Contact } from './src/objects/contact.object';
6-
import { Opportunity } from './src/objects/opportunity.object';
7-
import { Lead } from './src/objects/lead.object';
8-
import { Quote } from './src/objects/quote.object';
9-
import { Contract } from './src/objects/contract.object';
10-
import { Case } from './src/objects/case.object';
11-
import { Task } from './src/objects/task.object';
12-
import { Campaign } from './src/objects/campaign.object';
13-
import { Product } from './src/objects/product.object';
14-
15-
// ─── APIs ───────────────────────────────────────────────────────────
16-
import { PipelineStatsApi } from './src/apis/pipeline-stats.api';
17-
import { LeadConvertApi } from './src/apis/lead-convert.api';
18-
19-
// ─── Actions ────────────────────────────────────────────────────────
20-
import { ConvertLeadAction, CreateCampaignAction } from './src/actions/lead.actions';
21-
import { MarkPrimaryContactAction, SendEmailAction } from './src/actions/contact.actions';
22-
import { CloneOpportunityAction, MassUpdateStageAction } from './src/actions/opportunity.actions';
23-
import { EscalateCaseAction, CloseCaseAction } from './src/actions/case.actions';
24-
import { LogCallAction, ExportToCsvAction } from './src/actions/global.actions';
25-
26-
// ─── Dashboards ─────────────────────────────────────────────────────
27-
import { SalesDashboard } from './src/dashboards/sales.dashboard';
28-
import { ServiceDashboard } from './src/dashboards/service.dashboard';
29-
import { ExecutiveDashboard } from './src/dashboards/executive.dashboard';
30-
31-
// ─── Reports ────────────────────────────────────────────────────────
32-
import { OpportunitiesByStageReport, WonOpportunitiesByOwnerReport } from './src/reports/opportunity.report';
33-
import { AccountsByIndustryTypeReport } from './src/reports/account.report';
34-
import { CasesByStatusPriorityReport, SlaPerformanceReport } from './src/reports/case.report';
35-
import { LeadsBySourceReport } from './src/reports/lead.report';
36-
import { ContactsByAccountReport } from './src/reports/contact.report';
37-
import { TasksByOwnerReport } from './src/reports/task.report';
38-
39-
// ─── Flows ──────────────────────────────────────────────────────────
40-
import { LeadConversionFlow } from './src/flows/lead-conversion.flow';
41-
import { OpportunityApprovalFlow } from './src/flows/opportunity-approval.flow';
42-
import { CaseEscalationFlow } from './src/flows/case-escalation.flow';
43-
import { QuoteGenerationFlow } from './src/flows/quote-generation.flow';
44-
import { CampaignEnrollmentFlow } from './src/flows/campaign-enrollment.flow';
45-
46-
// ─── Agents ─────────────────────────────────────────────────────────
47-
import { SalesAssistantAgent } from './src/agents/sales.agent';
48-
import { ServiceAgent } from './src/agents/service.agent';
49-
import { LeadEnrichmentAgent } from './src/agents/lead-enrichment.agent';
50-
import { RevenueIntelligenceAgent } from './src/agents/revenue-intelligence.agent';
51-
import { EmailCampaignAgent } from './src/agents/email-campaign.agent';
52-
53-
// ─── RAG Pipelines ─────────────────────────────────────────────────
54-
import { SalesKnowledgeRAG } from './src/rag/sales-knowledge.rag';
55-
import { SupportKnowledgeRAG } from './src/rag/support-knowledge.rag';
56-
import { ProductInfoRAG } from './src/rag/product-info.rag';
57-
import { CompetitiveIntelRAG } from './src/rag/competitive-intel.rag';
58-
59-
// ─── Profiles ───────────────────────────────────────────────────────
60-
import { SalesRepProfile } from './src/profiles/sales-rep.profile';
61-
import { SalesManagerProfile } from './src/profiles/sales-manager.profile';
62-
import { ServiceAgentProfile } from './src/profiles/service-agent.profile';
63-
import { MarketingUserProfile } from './src/profiles/marketing-user.profile';
64-
import { SystemAdminProfile } from './src/profiles/system-admin.profile';
65-
66-
// ─── Sharing & Security ────────────────────────────────────────────
67-
import { OrganizationDefaults } from './src/sharing/defaults.sharing';
68-
import { AccountTeamSharingRule, TerritorySharingRules } from './src/sharing/account.sharing';
69-
import { OpportunitySalesSharingRule } from './src/sharing/opportunity.sharing';
70-
import { CaseEscalationSharingRule } from './src/sharing/case.sharing';
71-
import { RoleHierarchy } from './src/sharing/role-hierarchy';
72-
73-
// ─── App ────────────────────────────────────────────────────────────
74-
import { CrmApp } from './src/apps/crm.app';
3+
// ─── Barrel Imports (one per metadata type) ─────────────────────────
4+
import * as objects from './src/objects';
5+
import * as apis from './src/apis';
6+
import * as actions from './src/actions';
7+
import * as dashboards from './src/dashboards';
8+
import * as reports from './src/reports';
9+
import * as flows from './src/flows';
10+
import * as agents from './src/agents';
11+
import * as ragPipelines from './src/rag';
12+
import * as profiles from './src/profiles';
13+
import * as apps from './src/apps';
14+
15+
// ─── Sharing & Security (special: mixed single/array values) ───────
16+
import {
17+
OrganizationDefaults,
18+
AccountTeamSharingRule, TerritorySharingRules,
19+
OpportunitySalesSharingRule,
20+
CaseEscalationSharingRule,
21+
RoleHierarchy,
22+
} from './src/sharing';
7523

7624
export default defineStack({
7725
manifest: {
@@ -80,77 +28,21 @@ export default defineStack({
8028
type: 'app',
8129
name: 'Enterprise CRM',
8230
description: 'Comprehensive enterprise CRM demonstrating all ObjectStack Protocol features including AI, security, and automation',
83-
author: 'ObjectStack Team',
84-
repository: 'https://github.com/objectstack-ai/spec',
85-
license: 'MIT',
8631
},
8732

88-
objects: [
89-
Account, Contact, Lead, Opportunity, Quote, Contract,
90-
Case, Task,
91-
Campaign,
92-
Product,
93-
],
94-
95-
apis: [
96-
PipelineStatsApi,
97-
LeadConvertApi,
98-
],
99-
100-
actions: [
101-
ConvertLeadAction, CreateCampaignAction,
102-
MarkPrimaryContactAction, SendEmailAction,
103-
CloneOpportunityAction, MassUpdateStageAction,
104-
EscalateCaseAction, CloseCaseAction,
105-
LogCallAction, ExportToCsvAction,
106-
],
107-
108-
dashboards: [
109-
SalesDashboard,
110-
ServiceDashboard,
111-
ExecutiveDashboard,
112-
],
113-
114-
reports: [
115-
OpportunitiesByStageReport, WonOpportunitiesByOwnerReport,
116-
AccountsByIndustryTypeReport,
117-
CasesByStatusPriorityReport, SlaPerformanceReport,
118-
LeadsBySourceReport,
119-
ContactsByAccountReport,
120-
TasksByOwnerReport,
121-
],
122-
123-
flows: [
124-
LeadConversionFlow,
125-
OpportunityApprovalFlow,
126-
CaseEscalationFlow,
127-
QuoteGenerationFlow,
128-
CampaignEnrollmentFlow,
129-
],
130-
131-
agents: [
132-
SalesAssistantAgent,
133-
ServiceAgent,
134-
LeadEnrichmentAgent,
135-
RevenueIntelligenceAgent,
136-
EmailCampaignAgent,
137-
],
138-
139-
ragPipelines: [
140-
SalesKnowledgeRAG,
141-
SupportKnowledgeRAG,
142-
ProductInfoRAG,
143-
CompetitiveIntelRAG,
144-
],
145-
146-
profiles: [
147-
SalesRepProfile,
148-
SalesManagerProfile,
149-
ServiceAgentProfile,
150-
MarketingUserProfile,
151-
SystemAdminProfile,
152-
],
153-
33+
// Auto-collected from barrel index files via Object.values()
34+
objects: Object.values(objects),
35+
apis: Object.values(apis),
36+
actions: Object.values(actions),
37+
dashboards: Object.values(dashboards),
38+
reports: Object.values(reports),
39+
flows: Object.values(flows) as any,
40+
agents: Object.values(agents) as any,
41+
ragPipelines: Object.values(ragPipelines),
42+
profiles: Object.values(profiles),
43+
apps: Object.values(apps),
44+
45+
// Sharing & security (requires explicit wiring)
15446
sharingRules: [
15547
AccountTeamSharingRule,
15648
OpportunitySalesSharingRule,
@@ -159,6 +51,4 @@ export default defineStack({
15951
],
16052
roleHierarchy: RoleHierarchy,
16153
organizationDefaults: OrganizationDefaults,
162-
163-
apps: [CrmApp],
164-
});
54+
} as any);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Action Definitions Barrel
3+
*/
4+
export { EscalateCaseAction, CloseCaseAction } from './case.actions';
5+
export { MarkPrimaryContactAction, SendEmailAction } from './contact.actions';
6+
export { LogCallAction, ExportToCsvAction } from './global.actions';
7+
export { ConvertLeadAction, CreateCampaignAction } from './lead.actions';
8+
export { CloneOpportunityAction, MassUpdateStageAction } from './opportunity.actions';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Agent Definitions Barrel
3+
*/
4+
export { EmailCampaignAgent } from './email-campaign.agent';
5+
export { LeadEnrichmentAgent } from './lead-enrichment.agent';
6+
export { RevenueIntelligenceAgent } from './revenue-intelligence.agent';
7+
export { SalesAssistantAgent } from './sales.agent';
8+
export { ServiceAgent } from './service.agent';

examples/app-crm/src/apis/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* API Definitions Barrel
3+
*/
4+
export { LeadConvertApi } from './lead-convert.api';
5+
export { PipelineStatsApi } from './pipeline-stats.api';

examples/app-crm/src/apps/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* App Definitions Barrel
3+
*/
4+
export { CrmApp } from './crm.app';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Dashboard Definitions Barrel
3+
*/
4+
export { ExecutiveDashboard } from './executive.dashboard';
5+
export { SalesDashboard } from './sales.dashboard';
6+
export { ServiceDashboard } from './service.dashboard';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Flow Definitions Barrel
3+
*/
4+
export { CampaignEnrollmentFlow } from './campaign-enrollment.flow';
5+
export { CaseEscalationFlow } from './case-escalation.flow';
6+
export { LeadConversionFlow } from './lead-conversion.flow';
7+
export { OpportunityApprovalFlow } from './opportunity-approval.flow';
8+
export { QuoteGenerationFlow } from './quote-generation.flow';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Object Definitions Barrel
3+
*
4+
* Re-exports all *.object.ts definitions for auto-registration.
5+
* Hooks (*.hook.ts) and state machines (*.state.ts) are excluded —
6+
* they are auto-associated by naming convention at runtime.
7+
*/
8+
export { Account } from './account.object';
9+
export { Campaign } from './campaign.object';
10+
export { Case } from './case.object';
11+
export { Contact } from './contact.object';
12+
export { Contract } from './contract.object';
13+
export { Lead } from './lead.object';
14+
export { Opportunity } from './opportunity.object';
15+
export { Product } from './product.object';
16+
export { Quote } from './quote.object';
17+
export { Task } from './task.object';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Profile Definitions Barrel
3+
*/
4+
export { MarketingUserProfile } from './marketing-user.profile';
5+
export { SalesManagerProfile } from './sales-manager.profile';
6+
export { SalesRepProfile } from './sales-rep.profile';
7+
export { ServiceAgentProfile } from './service-agent.profile';
8+
export { SystemAdminProfile } from './system-admin.profile';

0 commit comments

Comments
 (0)