Primitives.org.ai

Business

Business-as-Code—traditional processes and structures manifested as code

Express business processes, organizational structures, and operations as code. Teams of AI agents and humans work together with full auditability, version control, and continuous improvement.

What is Business-as-Code?

Every business has processes: hiring, procurement, customer onboarding, expense approval, performance reviews. Traditionally, these exist as informal knowledge, scattered documents, or rigid enterprise software.

Business-as-Code makes these processes:

  • Explicit: Every step, decision, and rule is defined in code
  • Versionable: Changes are tracked, reviewed, and deployed like software
  • Composable: Processes combine into larger organizational structures
  • Executable: AI and humans execute processes through the same runtime
import { business, team, process, role } from 'business-as-code'

const startupCo = business({
  name: 'startup-co',

  structure: {
    departments: [engineering, product, operations],
    hierarchy: 'flat',
    decisionMaking: 'distributed',
  },

  teams: [
    team({
      name: 'engineering',
      roles: [
        role('engineer', { type: 'human', count: '5-10' }),
        role('code-reviewer', { type: 'agent', count: 2 }),
        role('devops', { type: 'hybrid', ratio: '1:1' }),
      ],
    }),
  ],

  processes: [
    hiringProcess,
    onboardingProcess,
    deploymentProcess,
    incidentResponseProcess,
  ],

  policies: [
    expensePolicy,
    remoteWorkPolicy,
    securityPolicy,
  ],
})

Defining Teams

Teams mix human and AI roles:

const supportTeam = team({
  name: 'customer-support',

  roles: [
    role('support-agent', {
      type: 'agent',
      count: 10,
      capabilities: [answerQuestions, createTickets, escalate],
      availability: '24/7',
    }),

    role('support-specialist', {
      type: 'human',
      count: 3,
      handles: ['escalations', 'complex-issues', 'vip-customers'],
      availability: 'business-hours',
    }),

    role('support-manager', {
      type: 'human',
      count: 1,
      responsibilities: ['team-performance', 'process-improvement', 'hiring'],
    }),
  ],

  workflows: {
    incoming: ticketTriageWorkflow,
    escalation: escalationWorkflow,
    resolution: resolutionWorkflow,
  },

  metrics: {
    track: ['response-time', 'resolution-rate', 'satisfaction'],
    targets: {
      responseTime: '< 5 minutes',
      resolutionRate: '> 90%',
      satisfaction: '> 4.5',
    },
  },
})

Business Processes

Define processes as executable workflows:

const hiringProcess = process({
  name: 'hiring',

  stages: [
    stage('sourcing', {
      owner: 'recruiter-agent',
      tasks: [
        task('post-job', postJobToBoards),
        task('source-candidates', sourceCandidates),
        task('initial-screen', screenResumes),
      ],
      output: 'qualified-candidates',
    }),

    stage('interviewing', {
      owner: 'hiring-manager',
      tasks: [
        task('schedule-interviews', scheduleInterviews),
        task('conduct-interviews', conductInterviews),
        task('collect-feedback', collectFeedback),
      ],
      output: 'interview-feedback',
    }),

    stage('decision', {
      owner: 'hiring-committee',
      tasks: [
        task('review-candidates', reviewCandidates),
        task('make-decision', makeHiringDecision),
        task('generate-offer', generateOffer),
      ],
      output: 'offer-decision',
    }),

    stage('closing', {
      owner: 'recruiter-agent',
      tasks: [
        task('extend-offer', extendOffer),
        task('negotiate', handleNegotiation),
        task('complete-hire', completeHire),
      ],
      output: 'hired-employee',
    }),
  ],

  sla: {
    totalDuration: '< 30 days',
    stageTimeouts: {
      sourcing: '7 days',
      interviewing: '14 days',
      decision: '3 days',
      closing: '7 days',
    },
  },
})

Policies and Rules

Encode business rules as executable policies:

const expensePolicy = policy({
  name: 'expense-approval',

  rules: [
    rule('auto-approve-small', {
      when: 'amount <= 100',
      then: 'auto-approve',
    }),

    rule('manager-approval', {
      when: 'amount > 100 AND amount <= 1000',
      then: 'require-approval',
      from: 'direct-manager',
    }),

    rule('director-approval', {
      when: 'amount > 1000 AND amount <= 10000',
      then: 'require-approval',
      from: 'department-director',
    }),

    rule('cfo-approval', {
      when: 'amount > 10000',
      then: 'require-approval',
      from: 'cfo',
    }),

    rule('category-restrictions', {
      when: 'category = travel',
      then: 'require-receipt',
      validate: 'receipt-matches-amount',
    }),
  ],

  exceptions: {
    allowedBy: ['cfo', 'ceo'],
    requiresJustification: true,
    logged: true,
  },
})

Organizational Structure

Define how teams relate to each other:

const orgStructure = organization({
  name: 'acme-corp',

  departments: [
    department({
      name: 'engineering',
      head: 'vp-engineering',
      teams: [platformTeam, productTeam, infraTeam],
      budget: 'quarterly-allocation',
    }),

    department({
      name: 'product',
      head: 'vp-product',
      teams: [productManagement, design, research],
    }),

    department({
      name: 'operations',
      head: 'coo',
      teams: [supportTeam, financeTeam, hrTeam],
    }),
  ],

  crossFunctional: [
    squad({
      name: 'growth',
      members: ['product', 'engineering', 'marketing'],
      mission: 'Increase user acquisition and retention',
    }),
  ],

  governance: {
    decisions: {
      strategic: { level: 'executive', quorum: 'majority' },
      tactical: { level: 'department', owner: 'head' },
      operational: { level: 'team', owner: 'lead' },
    },
  },
})

Composing Micro-Businesses

Build larger organizations from smaller units:

// A micro-business is a self-contained unit
const contentFactory = microBusiness({
  name: 'content-factory',

  services: [
    blogWritingService,
    socialMediaService,
    videoScriptService,
  ],

  team: contentTeam,

  economics: {
    costStructure: 'per-piece',
    pricing: 'market-rate',
    margin: '40%',
  },
})

// Compose into larger business
const mediaCompany = business({
  name: 'media-company',

  units: [
    contentFactory,
    distributionUnit,
    analyticsUnit,
  ],

  integration: {
    workflow: contentToDistributionWorkflow,
    dataFlow: 'analytics-feeds-content',
  },
})

Audit and Compliance

Every action is logged and auditable:

const auditedBusiness = business({
  name: 'regulated-co',

  compliance: {
    frameworks: ['SOC2', 'GDPR', 'HIPAA'],

    audit: {
      logAll: ['decisions', 'approvals', 'data-access'],
      retention: '7 years',
      immutable: true,
    },

    controls: [
      control('access-review', { frequency: 'quarterly' }),
      control('separation-of-duties', { enforce: true }),
      control('data-encryption', { atRest: true, inTransit: true }),
    ],
  },
})

// Query audit log
const auditLog = await auditedBusiness.audit.query({
  action: 'expense-approved',
  amount: { gt: 10000 },
  period: 'last-quarter',
})

Continuous Improvement

Businesses evolve and improve:

const evolvingBusiness = business({
  name: 'learning-org',

  improvement: {
    // Track metrics
    metrics: {
      operational: ['cycle-time', 'error-rate', 'throughput'],
      financial: ['revenue', 'margin', 'cac', 'ltv'],
      people: ['satisfaction', 'retention', 'productivity'],
    },

    // Review cadence
    reviews: {
      weekly: 'team-retrospectives',
      monthly: 'process-reviews',
      quarterly: 'strategic-reviews',
    },

    // Experiment with changes
    experiments: {
      enabled: true,
      scope: ['processes', 'policies', 'team-structure'],
      governance: 'opt-in-with-rollback',
    },
  },
})
Was this page helpful?

On this page