business-as-code 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,228 +7,255 @@
7
7
 
8
8
  ## Overview
9
9
 
10
- `business-as-code` enables organizations to represent their businesses and processes in code for human-AI collaboration. Unlike `ai-business` which focuses on AI-only businesses, this package provides interfaces for integrating human roles, AI agents, and defining collaboration points between them.
10
+ `business-as-code` provides a schema-first approach to defining business entities. Write your business model in MDX, YAML, or JSON, and use it across different platforms.
11
+
12
+ ```
13
+ business-as-code (portable schema layer)
14
+
15
+ ┌───┴───┐
16
+ ↓ ↓
17
+ Startups.Studio Platform.do
18
+ (AI startups) (Enterprise)
19
+ ```
20
+
21
+ This is the **schema definition layer** - it defines what your business entities look like. It works alongside runtime packages like [agents.do](https://agents.do), [workflows.do](https://workflows.do), and [humans.do](https://humans.do) which handle the actual business operations.
11
22
 
12
23
  ## Installation
13
24
 
14
25
  ```bash
15
26
  npm install business-as-code
16
27
  # or
17
- yarn add business-as-code
18
- # or
19
28
  pnpm add business-as-code
20
29
  ```
21
30
 
22
- ## Usage
31
+ ## Quick Start
23
32
 
24
- ### Creating a Business with Human-AI Collaboration
33
+ ### Use the Default Business Schema
25
34
 
26
- ```typescript
27
- import { Business } from 'business-as-code'
28
- import { Human } from 'humans.do'
29
- import { Agent } from 'agents.do'
30
- import { Workflow } from 'workflows.do'
31
-
32
- // Create human roles
33
- class CEO extends Human {}
34
- class CTO extends Human {}
35
- class MarketingManager extends Human {}
36
-
37
- // Create AI agents
38
- class DataAnalyst extends Agent {}
39
- class CustomerSupportAgent extends Agent {}
40
-
41
- // Create business processes
42
- class CustomerOnboarding extends Workflow {}
43
- class ProductDevelopment extends Workflow {}
44
-
45
- // Define your business
46
- const myCompany = Business({
47
- name: 'Acme Corporation',
48
- url: 'https://acme.com',
49
- vision: 'To revolutionize industry X with innovative solutions',
50
- goals: [
51
- {
52
- objective: 'Increase market share by 20%',
53
- keyResults: ['Launch 3 new products', 'Expand to 2 new geographical markets', 'Increase customer retention by 15%'],
54
- },
55
- ],
56
- // Human roles
57
- roles: {
58
- ceo: CEO,
59
- cto: CTO,
60
- marketingManager: MarketingManager,
61
- },
62
- // AI agents
63
- agents: {
64
- dataAnalyst: DataAnalyst,
65
- customerSupport: CustomerSupportAgent,
66
- },
67
- // Organizational structure
68
- departments: {
69
- engineering: {
70
- name: 'Engineering Department',
71
- lead: CTO,
72
- members: [DataAnalyst],
73
- },
74
- marketing: {
75
- name: 'Marketing Department',
76
- lead: MarketingManager,
77
- members: [],
78
- },
79
- },
80
- // Business processes
81
- processes: {
82
- customerOnboarding: CustomerOnboarding,
83
- productDevelopment: ProductDevelopment,
84
- },
85
- })
86
-
87
- // Event handling
88
- myCompany.on('new_customer', (data) => {
89
- // Trigger customer onboarding workflow
90
- console.log(`New customer: ${data.name}`)
91
- })
92
-
93
- // Scheduled operations
94
- myCompany.every('day', () => {
95
- // Daily operations
96
- console.log('Performing daily operations')
97
- })
98
-
99
- // Task assignment
100
- myCompany.assign('Analyze quarterly sales data', myCompany.agents.dataAnalyst)
101
- myCompany.assign('Review marketing strategy', myCompany.roles.marketingManager)
102
-
103
- // Track business metrics
104
- myCompany.track('customer_satisfaction', 4.8)
105
- myCompany.track('monthly_revenue', 125000)
106
- ```
35
+ The package includes a comprehensive default schema with 40+ business entities across 9 domains:
107
36
 
108
- ## Differences from `ai-business`
37
+ ```typescript
38
+ import { defaultBusinessSchema, getAllNouns } from 'business-as-code'
109
39
 
110
- While `ai-business` focuses on AI-driven business functions, `business-as-code` is designed specifically for representing existing organizations with both human employees and AI agents:
40
+ // Get all nouns from the default business schema
41
+ const nouns = getAllNouns(defaultBusinessSchema)
42
+ console.log(`${nouns.length} nouns loaded`)
111
43
 
112
- | Feature | business-as-code | ai-business |
113
- | -------------------- | ---------------------------------- | ------------------------------ |
114
- | Primary focus | Human-AI collaboration | AI-driven business functions |
115
- | Organizational model | Comprehensive (roles, departments) | Limited (focused on functions) |
116
- | Human roles | Explicit role definitions | Not specifically modeled |
117
- | Decision approval | Built-in approval workflows | Automated decision making |
118
- | Task assignment | Supports both humans and AI | Primarily AI-focused |
119
- | Integration | Designed for existing org systems | Standalone AI capabilities |
44
+ // Access specific noun schemas directly
45
+ import { Customers, Products, Invoices, Projects, Teams } from 'business-as-code'
46
+ ```
120
47
 
121
- ## Key Design Considerations
48
+ ### Define Custom Business in MDX
122
49
 
123
- ### 1. Organizational hierarchy
50
+ MDX provides the most expressive way to define business entities with JSX-like syntax:
124
51
 
125
52
  ```typescript
126
- // Define departments with reporting lines
127
- const company = Business({
128
- departments: {
129
- engineering: {
130
- name: 'Engineering',
131
- lead: CTO,
132
- members: [SeniorEngineer, JuniorEngineer, AICodeReviewer],
133
- },
134
- },
135
- })
53
+ import { loadFromMDX, mergeSchemas, defaultBusinessSchema } from 'business-as-code'
54
+
55
+ const mdx = `
56
+ <Business name="My SaaS">
57
+ <Noun name="Tenant" group="Admin">
58
+ <Name text required />
59
+ <Subdomain text unique />
60
+ <Plan status="free|pro|enterprise" />
61
+ <Owner user />
62
+ </Noun>
63
+
64
+ <Noun name="Feature" group="Product">
65
+ <Name text required />
66
+ <Description rich />
67
+ <Tier status="free|pro|enterprise" />
68
+ <Enabled boolean />
69
+ </Noun>
70
+ </Business>
71
+ `
72
+
73
+ const customSchema = await loadFromMDX(mdx)
74
+ const fullSchema = mergeSchemas(defaultBusinessSchema, customSchema)
136
75
  ```
137
76
 
138
- ### 2. Human-AI collaboration points
77
+ ### Define Custom Business in YAML
78
+
79
+ YAML is ideal for configuration files and version control:
139
80
 
140
81
  ```typescript
141
- // AI can suggest changes that require human approval
142
- company.on('content_suggestion', (suggestion, approver) => {
143
- // Request approval from human
144
- approver.requestApproval(suggestion)
145
- })
82
+ import { loadFromYAML } from 'business-as-code'
83
+
84
+ const yaml = `
85
+ name: My SaaS
86
+ version: 1.0.0
87
+
88
+ domains:
89
+ admin:
90
+ - name: Tenant
91
+ titleField: name
92
+ fields:
93
+ name: text required
94
+ subdomain: text unique
95
+ plan: status:free|pro|enterprise
96
+ owner: ref:users
97
+
98
+ product:
99
+ - name: Feature
100
+ titleField: name
101
+ fields:
102
+ name: text required
103
+ description: rich
104
+ tier: status:free|pro|enterprise
105
+ enabled: boolean
106
+ `
107
+
108
+ const schema = loadFromYAML(yaml)
146
109
  ```
147
110
 
148
- ### 3. Task assignment
111
+ ### Define Custom Business in JSON
112
+
113
+ JSON works well for programmatic generation and API responses:
149
114
 
150
115
  ```typescript
151
- // Assign tasks based on nature and complexity
152
- function assignTask(task) {
153
- if (task.requiresCreativity) {
154
- company.assign(task, company.roles.humanCreative)
155
- } else if (task.isRepetitive) {
156
- company.assign(task, company.agents.automationAgent)
116
+ import { loadFromJSON } from 'business-as-code'
117
+
118
+ const json = {
119
+ name: "My SaaS",
120
+ version: "1.0.0",
121
+ domains: {
122
+ admin: [{
123
+ name: "Tenant",
124
+ titleField: "name",
125
+ fields: {
126
+ name: "text required",
127
+ subdomain: "text unique",
128
+ plan: "status:free|pro|enterprise"
129
+ }
130
+ }]
157
131
  }
158
132
  }
133
+
134
+ const schema = loadFromJSON(JSON.stringify(json))
159
135
  ```
160
136
 
161
- ### 4. Event handling differences
137
+ ## Domains
138
+
139
+ The default business schema includes these domains:
140
+
141
+ | Domain | Nouns | Description |
142
+ |--------|-------|-------------|
143
+ | **Admin** | Users, Orgs, ServiceAccounts | System administration |
144
+ | **Business** | Businesses, Goals, Metrics, Teams, Processes | Core business entities |
145
+ | **Product** | Products, Services, Offers, Prices, Features | Product catalog |
146
+ | **Success** | Customers, Contacts, Subscriptions | Customer success |
147
+ | **Sales** | Deals, Quotes, Proposals | Sales pipeline |
148
+ | **Marketing** | Leads, Brands, Domains, Competitors | Marketing & branding |
149
+ | **Work** | Projects, Tasks, Issues, Workflows, Roles, Agents | Work management |
150
+ | **Financial** | Invoices, Payments, Refunds, ChartOfAccounts, JournalEntries | Accounting |
151
+ | **Communications** | Channels, Messages, Sequences, Templates, Posts | Messaging |
152
+
153
+ ## Field Types
154
+
155
+ ### Primitive Types
156
+ | Type | Description | Example |
157
+ |------|-------------|---------|
158
+ | `text` | Single-line text | `name: text` |
159
+ | `rich` | Rich text / markdown | `description: rich` |
160
+ | `number` | Numeric value | `count: number` |
161
+ | `boolean` | True/false checkbox | `isActive: boolean` |
162
+ | `date` | Date picker | `createdAt: date` |
163
+
164
+ ### Semantic Types (with validation)
165
+ | Type | Description | Example |
166
+ |------|-------------|---------|
167
+ | `email` | Email address | `email: email` |
168
+ | `url` | Valid URL | `website: url` |
169
+ | `phone` | Phone number | `phone: phone` |
170
+ | `slug` | URL-safe slug | `slug: slug` |
171
+
172
+ ### Business Types
173
+ | Type | Description | Example |
174
+ |------|-------------|---------|
175
+ | `money` | Currency amount | `price: money` |
176
+ | `score` | 0-100 value | `health: score` |
177
+ | `status:a\|b\|c` | Select options | `status: status:active\|inactive` |
178
+
179
+ ### Relationship Types
180
+ | Type | Description | Example |
181
+ |------|-------------|---------|
182
+ | `ref:collection` | Reference to another noun | `customer: ref:customers` |
183
+ | `user` | Reference to users | `owner: user` |
184
+
185
+ ### Modifiers
186
+ | Modifier | Description | Example |
187
+ |----------|-------------|---------|
188
+ | `required` | Field must have value | `name: text required` |
189
+ | `unique` | Value must be unique | `slug: text unique` |
162
190
 
163
- ```typescript
164
- // Human events may require notifications
165
- company.on('urgent_issue', (issue) => {
166
- if (issue.assignee instanceof Human) {
167
- sendNotification(issue.assignee)
168
- } else {
169
- // AI can handle immediately
170
- issue.assignee.handle(issue)
171
- }
172
- })
173
- ```
191
+ ## API Reference
174
192
 
175
- ### 5. Permission workflows
193
+ ### Schema Functions
176
194
 
177
195
  ```typescript
178
- // AI can draft but needs human approval for publishing
179
- company.agents.contentWriter.setPermission('content.publish', 'suggest')
180
- company.roles.contentManager.setPermission('content.publish', 'approve')
196
+ import {
197
+ defaultBusinessSchema, // The complete default schema
198
+ getAllNouns, // Get all nouns as flat array
199
+ getDomainNouns, // Get nouns for a specific domain
200
+ getDomains, // Get list of all domain names
201
+ findNounBySlug, // Find a noun by its slug
202
+ mergeSchemas, // Merge two schemas together
203
+ validateSchema, // Validate a schema structure
204
+ createMinimalSchema, // Create empty schema scaffold
205
+ } from 'business-as-code'
181
206
  ```
182
207
 
183
- ### 6. System integration
208
+ ### Loaders
184
209
 
185
210
  ```typescript
186
- // Connect with existing organizational systems
187
- company.integrate('crm', {
188
- endpoint: 'https://crm.company.com/api',
189
- handlers: {
190
- // Map events between systems
191
- 'crm:new_customer': (data) => company.trigger('new_customer', data),
192
- },
193
- })
211
+ import {
212
+ load, // Auto-detect format and load
213
+ loadFromMDX, // Load from MDX source
214
+ loadFromYAML, // Load from YAML source
215
+ loadFromJSON, // Load from JSON source
216
+ loadNoun, // Load a single noun definition
217
+ loadNouns, // Load multiple noun definitions
218
+ } from 'business-as-code'
194
219
  ```
195
220
 
196
- ### 7. Role guidelines
221
+ ### Serializers
197
222
 
198
223
  ```typescript
199
- // Define when to use humans vs AI
200
- const roleGuidelines = {
201
- customer_complaints: {
202
- simple: company.agents.customerSupport,
203
- complex: company.roles.customerSuccessManager,
204
- criteria: (complaint) => (complaint.sentiment < -0.8 ? 'complex' : 'simple'),
205
- },
206
- }
224
+ import {
225
+ serialize, // Serialize schema to YAML or JSON
226
+ toYAML, // Serialize to YAML string
227
+ toJSON, // Serialize to JSON string
228
+ serializeNoun, // Serialize single noun
229
+ nounToYAML, // Noun to YAML
230
+ nounToJSON, // Noun to JSON
231
+ } from 'business-as-code'
207
232
  ```
208
233
 
209
- ## API Reference
210
-
211
- ### Functions
212
-
213
- - `Business(config)` - Creates a new business representation
214
-
215
234
  ### Types
216
235
 
217
- - `BusinessConfig` - Configuration for creating a business
218
- - `BusinessInstance` - Instance returned by the Business function
219
- - `PermissionLevel` - Enum for permission levels (VIEW, SUGGEST, EXECUTE, APPROVE, ADMIN)
220
- - `Task` - Interface for task assignments
221
- - `BusinessEvent` - Interface for business events
236
+ ```typescript
237
+ import type {
238
+ BusinessSchema, // Complete business schema
239
+ BusinessDomain, // Domain name type
240
+ NounSchema, // Individual noun definition
241
+ FieldSchema, // Field definition
242
+ FieldType, // Field type union
243
+ LoaderOptions, // Options for loaders
244
+ LoadResult, // Result from load operations
245
+ } from 'business-as-code'
246
+ ```
247
+
248
+ ## Integration
222
249
 
223
- ### Business Instance Methods
250
+ `business-as-code` provides the schema layer that integrates with the broader .do ecosystem:
224
251
 
225
- - `on(event, handler)` - Register event handler
226
- - `every(schedule, operation)` - Register scheduled operation
227
- - `assign(task, to)` - Assign a task to a human or AI
228
- - `track(metric, value)` - Track business metrics
252
+ - **[db.sb](https://db.sb)** - Database runtime that executes these schemas
253
+ - **[Startups.Studio](https://startups.studio)** - AI-operated autonomous startups
254
+ - **[Platform.do](https://platform.do)** - Enterprise business platform
255
+ - **[agents.do](https://agents.do)** - AI agents for business operations
256
+ - **[workflows.do](https://workflows.do)** - Business process automation
257
+ - **[humans.do](https://humans.do)** - Human role definitions
229
258
 
230
- ## Dependencies
259
+ ## License
231
260
 
232
- - [agents.do](https://github.com/drivly/agents.do) - Agent framework for AI operations
233
- - [humans.do](https://github.com/drivly/humans.do) - Human role definitions and interactions
234
- - [workflows.do](https://github.com/drivly/workflows.do) - Workflow definitions for business processes
261
+ MIT
@@ -0,0 +1,4 @@
1
+ export { a as BusinessDomain, b as BusinessExtension, B as BusinessSchema, F as FieldShorthand, c as LoadResult, L as LoaderOptions, N as NounShorthand } from './types-CJ9eGS_C.js';
2
+ export { Agents, Brands, Businesses, Channels, ChartOfAccounts, Competitors, Contacts, Customers, Deals, Domains, Features, Goals, Invoices, Issues, JournalEntries, Leads, Messages, Metrics, Offers, Orgs, Payments, Posts, Prices, Processes, Products, Projects, Proposals, Quotes, Refunds, Roles, Sequences, ServiceAccounts, Services, Subscriptions, Tasks, Teams, Templates, Users, Workflows, adminNouns, businessNouns, communicationsNouns, createMinimalSchema, defaultBusinessSchema, financialNouns, findNounBySlug, getAllNouns, getDomainNouns, getDomains, marketingNouns, mergeSchemas, productNouns, salesNouns, successNouns, validateSchema, workNouns } from './schema/index.js';
3
+ export { load, loadFromJSON, loadFromMDX, loadFromYAML, loadNoun, loadNounFromJSON, loadNounFromMDX, loadNounFromYAML, loadNouns, loadNounsFromJSON, loadNounsFromMDX, loadNounsFromYAML, nounToJSON, nounToYAML, serialize, serializeNoun, toJSON, toYAML } from './loaders/index.js';
4
+ export { FieldSchema, FieldType, NounSchema } from 'db.sb';