JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 140
  • Score
    100M100P100Q87049F
  • License MIT

Define, launch, experiment, iterate, and grow your business entirely in code

Package Exports

  • business-as-code
  • business-as-code/loaders
  • business-as-code/schema

Readme

business-as-code

npm version License: MIT

Define, launch, experiment, iterate, and grow your business entirely in code

Overview

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.

business-as-code (portable schema layer)
       ↓
   ┌───┴───┐
   ↓       ↓
Startups.Studio    Platform.do
(AI startups)      (Enterprise)

This is the schema definition layer - it defines what your business entities look like. It works alongside runtime packages like agents.do, workflows.do, and humans.do which handle the actual business operations.

Installation

npm install business-as-code
# or
pnpm add business-as-code

Quick Start

Use the Default Business Schema

The package includes a comprehensive default schema with 40+ business entities across 9 domains:

import { defaultBusinessSchema, getAllNouns } from 'business-as-code'

// Get all nouns from the default business schema
const nouns = getAllNouns(defaultBusinessSchema)
console.log(`${nouns.length} nouns loaded`)

// Access specific noun schemas directly
import { Customers, Products, Invoices, Projects, Teams } from 'business-as-code'

Define Custom Business in MDX

MDX provides the most expressive way to define business entities with JSX-like syntax:

import { loadFromMDX, mergeSchemas, defaultBusinessSchema } from 'business-as-code'

const mdx = `
<Business name="My SaaS">
  <Noun name="Tenant" group="Admin">
    <Name text required />
    <Subdomain text unique />
    <Plan status="free|pro|enterprise" />
    <Owner user />
  </Noun>

  <Noun name="Feature" group="Product">
    <Name text required />
    <Description rich />
    <Tier status="free|pro|enterprise" />
    <Enabled boolean />
  </Noun>
</Business>
`

const customSchema = await loadFromMDX(mdx)
const fullSchema = mergeSchemas(defaultBusinessSchema, customSchema)

Define Custom Business in YAML

YAML is ideal for configuration files and version control:

import { loadFromYAML } from 'business-as-code'

const yaml = `
name: My SaaS
version: 1.0.0

domains:
  admin:
    - name: Tenant
      titleField: name
      fields:
        name: text required
        subdomain: text unique
        plan: status:free|pro|enterprise
        owner: ref:users

  product:
    - name: Feature
      titleField: name
      fields:
        name: text required
        description: rich
        tier: status:free|pro|enterprise
        enabled: boolean
`

const schema = loadFromYAML(yaml)

Define Custom Business in JSON

JSON works well for programmatic generation and API responses:

import { loadFromJSON } from 'business-as-code'

const json = {
  name: "My SaaS",
  version: "1.0.0",
  domains: {
    admin: [{
      name: "Tenant",
      titleField: "name",
      fields: {
        name: "text required",
        subdomain: "text unique",
        plan: "status:free|pro|enterprise"
      }
    }]
  }
}

const schema = loadFromJSON(JSON.stringify(json))

Domains

The default business schema includes these domains:

Domain Nouns Description
Admin Users, Orgs, ServiceAccounts System administration
Business Businesses, Goals, Metrics, Teams, Processes Core business entities
Product Products, Services, Offers, Prices, Features Product catalog
Success Customers, Contacts, Subscriptions Customer success
Sales Deals, Quotes, Proposals Sales pipeline
Marketing Leads, Brands, Domains, Competitors Marketing & branding
Work Projects, Tasks, Issues, Workflows, Roles, Agents Work management
Financial Invoices, Payments, Refunds, ChartOfAccounts, JournalEntries Accounting
Communications Channels, Messages, Sequences, Templates, Posts Messaging

Field Types

Primitive Types

Type Description Example
text Single-line text name: text
rich Rich text / markdown description: rich
number Numeric value count: number
boolean True/false checkbox isActive: boolean
date Date picker createdAt: date

Semantic Types (with validation)

Type Description Example
email Email address email: email
url Valid URL website: url
phone Phone number phone: phone
slug URL-safe slug slug: slug

Business Types

Type Description Example
money Currency amount price: money
score 0-100 value health: score
status:a|b|c Select options status: status:active|inactive

Relationship Types

Type Description Example
ref:collection Reference to another noun customer: ref:customers
user Reference to users owner: user

Modifiers

Modifier Description Example
required Field must have value name: text required
unique Value must be unique slug: text unique

API Reference

Schema Functions

import {
  defaultBusinessSchema,  // The complete default schema
  getAllNouns,           // Get all nouns as flat array
  getDomainNouns,        // Get nouns for a specific domain
  getDomains,            // Get list of all domain names
  findNounBySlug,        // Find a noun by its slug
  mergeSchemas,          // Merge two schemas together
  validateSchema,        // Validate a schema structure
  createMinimalSchema,   // Create empty schema scaffold
} from 'business-as-code'

Loaders

import {
  load,           // Auto-detect format and load
  loadFromMDX,    // Load from MDX source
  loadFromYAML,   // Load from YAML source
  loadFromJSON,   // Load from JSON source
  loadNoun,       // Load a single noun definition
  loadNouns,      // Load multiple noun definitions
} from 'business-as-code'

Serializers

import {
  serialize,      // Serialize schema to YAML or JSON
  toYAML,         // Serialize to YAML string
  toJSON,         // Serialize to JSON string
  serializeNoun,  // Serialize single noun
  nounToYAML,     // Noun to YAML
  nounToJSON,     // Noun to JSON
} from 'business-as-code'

Types

import type {
  BusinessSchema,    // Complete business schema
  BusinessDomain,    // Domain name type
  NounSchema,        // Individual noun definition
  FieldSchema,       // Field definition
  FieldType,         // Field type union
  LoaderOptions,     // Options for loaders
  LoadResult,        // Result from load operations
} from 'business-as-code'

Integration

business-as-code provides the schema layer that integrates with the broader .do ecosystem:

License

MIT