DeployCode Deployment
Deploy as Businesses
Create complete autonomous businesses from MDX Functions & Components
Deploy MDX as Complete Businesses
Documentation Status: This documentation describes the planned API design for the .do platform. Code examples represent the intended interface and may not reflect the current implementation state. See roadmap for implementation status.
Combine all deployment primitives to create complete, autonomous Business-as-Code that operates end-to-end with minimal human intervention.
Overview
Deploy MDX as businesses to create:
- E-commerce Stores - Complete online retail operations
- SaaS Platforms - Full software-as-a-service businesses
- Service Marketplaces - Multi-vendor platforms
- Digital Agencies - Automated service delivery businesses
graph TB
A[Business-as-Code] --> B[Services]
A --> C[Agents]
A --> D[Workflows]
A --> E[Website]
A --> F[APIs]
B --> G[Service Delivery]
C --> H[Customer Support]
D --> I[Fulfillment]
E --> J[Marketing]
F --> K[Integration]
G --> L[Revenue]
H --> M[Customer Satisfaction]
I --> L
J --> N[Customer Acquisition]
K --> O[Partner Ecosystem]
Complete Business Example
---
title: AI Content Agency
description: Autonomous content creation and marketing agency
---
// ============================================================================
// SERVICES - What the business offers
// ============================================================================
export async function createBlogPost(params: {
topic: string
keywords: string[]
length: number
tone: 'professional' | 'casual' | 'technical'
}) {
const content = await $.ai.generateText({
prompt: `Write a ${params.tone} blog post about: ${params.topic}`,
context: { keywords: params.keywords, length: params.length }
})
const images = await $.ai.generateImages({
prompts: extractImageNeeds(content),
style: 'professional'
})
const optimized = await $.ai.optimize(content, {
for: 'seo',
keywords: params.keywords
})
return { content: optimized, images }
}
export async function manageSocialMedia(params: {
platforms: string[]
schedule: 'daily' | 'weekly'
contentPillars: string[]
}) {
const posts = await $.ai.generate.socialPosts({
platforms: params.platforms,
topics: params.contentPillars,
count: params.schedule === 'daily' ? 7 : 3
})
const scheduled = await $.social.schedule.posts(posts)
return scheduled
}
// ============================================================================
// AGENTS - Autonomous workers
// ============================================================================
const contentCreatorAgent = $.agent({
name: 'Content Creator',
role: 'Generate high-quality content',
capabilities: { createBlogPost }
})
const socialMediaAgent = $.agent({
name: 'Social Media Manager',
role: 'Manage social media presence',
capabilities: { manageSocialMedia }
})
const customerSupportAgent = $.agent({
name: 'Customer Support',
role: 'Handle customer inquiries',
capabilities: {
async handleInquiry(inquiry: Inquiry) {
const response = await $.ai.generateText({
prompt: 'Provide helpful customer support',
context: inquiry
})
await $.email.send.message({
to: inquiry.email,
subject: `Re: ${inquiry.subject}`,
body: response
})
}
}
})
// ============================================================================
// WORKFLOWS - Business processes
// ============================================================================
const clientOnboardingWorkflow = $.workflow('client-onboarding', async (clientId: string) => {
// Step 1: Welcome email
await $.step('send-welcome', () =>
$.email.send.message({
to: client.email,
template: 'client_welcome'
})
)
// Step 2: Schedule kickoff call
const meeting = await $.step('schedule-kickoff', () =>
$.calendar.schedule({
type: 'kickoff_call',
duration: 60,
attendees: [client.email, '[email protected]']
})
)
// Step 3: Create project
await $.step('create-project', () =>
$.db.projects.create({
clientId,
status: 'active',
services: client.selectedServices
})
)
// Step 4: Assign team
await $.step('assign-team', () =>
assignAgentsToProject(clientId)
)
})
const contentDeliveryWorkflow = $.workflow('content-delivery', async (orderId: string) => {
const order = await $.db.orders.findById(orderId)
// Generate content
const content = await $.step('generate', () =>
contentCreatorAgent.execute({
topic: order.topic,
keywords: order.keywords,
length: order.wordCount
})
)
// Quality review
const reviewed = await $.step('review', () =>
$.human.request({
type: 'content*review',
content,
timeout: 24 * 60 \_ 60 \* 1000
})
)
if (!reviewed.approved) {
// Revise
const revised = await $.step('revise', () =>
reviseContent(content, reviewed.feedback)
)
}
// Deliver to client
await $.step('deliver', () =>
$.email.send.message({
to: order.client.email,
subject: 'Your content is ready!',
attachments: [content.file]
})
)
// Update order status
await $.step('complete', () =>
$.db.orders.update(orderId, { status: 'completed' })
)
})
// ============================================================================
// WEBSITE - Client-facing interface
// ============================================================================
export function HomePage() {
return (
<div className="homepage">
<Hero
title="AI-Powered Content Agency"
subtitle="Quality content at scale, delivered by AI"
cta={{
primary: { text: 'Get Started', href: '/signup' },
secondary: { text: 'View Pricing', href: '/pricing' }
}}
/>
<Services>
<ServiceCard
title="Blog Content"
description="SEO-optimized blog posts that drive traffic"
price="$99/post"
features={[
'1500-2000 words',
'SEO optimized',
'Custom images',
'24-hour delivery'
]}
/>
<ServiceCard
title="Social Media"
description="Consistent social media presence"
price="$299/month"
features={[
'Daily posts',
'All major platforms',
'Content calendar',
'Analytics'
]}
/>
</Services>
<Testimonials />
<CTASection />
</div>
)
}
export function DashboardPage() {
const user = $.auth.useUser()
const orders = $.data.use(() => $.db.orders.find({ clientId: user.id }))
return (
<Dashboard>
<Sidebar>
<Navigation />
</Sidebar>
<MainContent>
<h1>Your Projects</h1>
<OrdersList orders={orders.data} />
<NewOrderButton />
</MainContent>
</Dashboard>
) }
// ============================================================================
// APIs - Programmatic access
// ============================================================================
export const api = {
'/api/orders': {
POST: async (req) => {
const order = await $.db.orders.create(req.body)
await contentDeliveryWorkflow.start(order.id)
return { order }
},
GET: async (req) => {
const orders = await $.db.orders.find({
where: { clientId: req.user.id },
})
return { orders }
},
},
'/api/content/generate': {
POST: async (req) => {
const content = await createBlogPost(req.body)
return { content }
},
},
}
// ============================================================================
// BUSINESS CONFIGURATION
// ============================================================================
export default $.business({
name: 'AI Content Agency',
description: 'Autonomous content creation and marketing agency',
// Services offered
services: {
'blog-content': {
name: 'Blog Content',
pricing: { amount: 99, unit: 'post' },
capabilities: { createBlogPost }
},
'social-media': {
name: 'Social Media Management',
pricing: { amount: 299, interval: 'month' },
capabilities: { manageSocialMedia }
}
},
// Autonomous agents
agents: [
contentCreatorAgent,
socialMediaAgent,
customerSupportAgent
],
// Business processes
workflows: {
'client-onboarding': clientOnboardingWorkflow,
'content-delivery': contentDeliveryWorkflow
},
// Website
website: {
domain: 'aicontentag Agency.do',
pages: {
'/': HomePage,
'/dashboard': DashboardPage,
'/pricing': PricingPage
}
},
// API
api: {
domain: 'api.aicontentagency.do',
endpoints: api
},
// Business operations
operations: {
// Automatic billing
billing: {
provider: 'stripe',
mode: 'automatic'
},
// Customer management
crm: {
enabled: true,
automate: ['onboarding', 'follow-ups', 'renewals']
},
// Analytics
analytics: {
track: ['orders', 'revenue', 'satisfaction', 'delivery-time']
},
// Support
support: {
channels: ['email', 'chat'],
agent: customerSupportAgent,
escalation: {
to: '[email protected]',
when: 'agent_uncertain'
}
}
}
})Business Components
E-Commerce Store
export default $.business({
name: 'AI Merch Store',
type: 'ecommerce',
// Product catalog
catalog: {
async getProducts() {
return await $.db.products.find({ available: true })
},
async getProduct(id) {
return await $.db.products.findById(id)
}
},
// Shopping cart
cart: {
engine: 'builtin',
persistence: 'database'
},
// Checkout
checkout: {
providers: ['stripe', 'paypal'],
flow: 'one-page'
},
// Order fulfillment
fulfillment: {
workflow: orderFulfillmentWorkflow,
shipping: {
providers: ['shippo', 'easypost'],
rules: 'automatic'
}
},
// Customer service
support: {
agent: supportAgent,
channels: ['email', 'chat', 'phone']
}
})SaaS Platform
export default $.business({
name: 'AI Analytics Platform',
type: 'saas',
// Subscription plans
pricing: {
plans: [
{
id: 'starter',
name: 'Starter',
price: 29,
interval: 'month',
features: ['10k events', 'Basic reports', 'Email support']
},
{
id: 'pro',
name: 'Professional',
price: 99,
interval: 'month',
features: ['100k events', 'Advanced analytics', 'Priority support', 'API access']
}
]
},
// Core platform
platform: {
app: AnalyticsDashboard,
api: analyticsAPI,
domains: {
app: 'app.analytics.do',
api: 'api.analytics.do',
docs: 'docs.analytics.do'
}
},
// User management
users: {
auth: ['email', 'google', 'github'],
onboarding: onboardingWorkflow,
roles: ['admin', 'member', 'viewer']
},
// Billing
billing: {
provider: 'stripe',
automatic: true,
invoices: true
}
})Business Automation
Automated Marketing
// Automatic email campaigns
$.on('user.signed_up', async (event) => {
await marketingWorkflow.start({
userId: event.user.id,
campaign: 'welcome_series'
})
})
// Lead nurturing
$.schedule.every('1d', async () => {
const leads = await $.db.leads.find({ status: 'warm' })
for (const lead of leads) {
await leadNurturingAgent.execute({ lead })
}
})
// Abandoned cart recovery
$.on('cart.abandoned', async (event) => {
// Wait 1 hour
await $.wait(60 _ 60 _ 1000)
// Send recovery email
await $.email.send.message({
to: event.user.email,
template: 'cart_recovery',
data: { cart: event.cart }
})
})Revenue Operations
// Automatic invoicing
$.on('subscription.renewed', async (event) => {
await $.invoice.create.and.send({
customer: event.customerId,
amount: event.amount,
items: event.items
})
})
// Usage-based billing
$.schedule.every('1month', async () => {
const customers = await $.db.customers.find({ plan: 'usage_based' })
for (const customer of customers) {
const usage = await calculateUsage(customer.id)
await $.invoice.create.and.send({
customer: customer.id,
amount: usage.total,
breakdown: usage.items
})
}
})
// Dunning management
$.on('payment.failed', async (event) => {
await paymentRetryWorkflow.start(event.paymentId)
})Customer Success
// Onboarding automation
const onboardingWorkflow = $.workflow('onboarding', async (userId: string) => {
// Day 1: Welcome
await $.step('welcome', () =>
$.email.send.template('welcome', { userId })
)
await $.wait(24 _ 60 _ 60 \* 1000) // Wait 1 day
// Day 2: Setup guide
await $.step('setup-guide', () =>
$.email.send.template('setup_guide', { userId })
)
await $.wait(2 _ 24 _ 60 _ 60 _ 1000) // Wait 2 days
// Day 4: Check progress
const progress = await $.step('check-progress', () =>
checkUserProgress(userId)
)
if (progress < 50) {
// Send help offer
await $.step('offer-help', () =>
$.email.send.template('need_help', { userId })
)
}
})
// Churn prevention
$.schedule.every('1d', async () => {
const atRiskUsers = await identifyAtRiskUsers()
for (const user of atRiskUsers) {
await retentionAgent.execute({ userId: user.id })
}
})Business Metrics
Revenue Tracking
const metrics = await $.business.metrics.get('ai-content-agency', {
period: 'last_month',
})
console.log({
mrr: metrics.mrr, // Monthly Recurring Revenue
arr: metrics.arr, // Annual Recurring Revenue
newRevenue: metrics.newRevenue,
churnedRevenue: metrics.churnedRevenue,
netRevenue: metrics.netRevenue,
ltv: metrics.customerLTV, // Customer Lifetime Value
cac: metrics.customerCAC, // Customer Acquisition Cost
})Operations Dashboard
export function BusinessDashboard() {
const metrics = $.business.metrics.use()
return (
<Dashboard>
<MetricCard
title="Monthly Revenue"
value={`$${metrics.mrr.toLocaleString()}`}
change={metrics.mrrGrowth}
/>
<MetricCard
title="Active Customers"
value={metrics.activeCustomers}
change={metrics.customerGrowth}
/>
<MetricCard
title="Order Completion Rate"
value={`${metrics.completionRate}%`}
change={metrics.completionRateChange}
/>
<MetricCard
title="Customer Satisfaction"
value={metrics.nps}
change={metrics.npsChange}
/>
<RevenueChart data={metrics.revenueHistory} />
<CustomersChart data={metrics.customerHistory} />
<OrdersChart data={metrics.orderHistory} />
</Dashboard>
)
}Deployment Configuration
// do.config.ts
export default {
businesses: [
{
name: 'ai-content-agency',
source: './business/agency.mdx',
deployment: {
// Domains
domains: {
website: 'aicontentagency.do',
app: 'app.aicontentagency.do',
api: 'api.aicontentagency.do',
},
// Infrastructure
infrastructure: {
database: 'postgres',
storage: 'r2',
email: 'resend',
payments: 'stripe',
},
// Scaling
scaling: {
agents: { min: 1, max: 10 },
workflows: { concurrency: 100 },
api: { instances: 'auto' },
},
// Monitoring
monitoring: {
uptime: true,
performance: true,
errors: true,
business: true,
},
},
environment: {
DATABASE_URL: process.env.DATABASE_URL,
STRIPE_SECRET: process.env.STRIPE_SECRET,
EMAIL_API_KEY: process.env.EMAIL_API_KEY,
AI_API_KEY: process.env.AI_API_KEY,
},
},
],
}Best Practices
Start Simple, Scale Up
// Start with MVP
export default $.business({
name: 'MVP Store',
services: { 'product-a': productAService },
website: { '/': HomePage }
})
// Add features as you grow
export default $.business({
name: 'Growing Store',
services: {
'product-a': productAService,
'product-b': productBService, // New product
'consulting': consultingService // New service line
},
website: {
'/': HomePage,
'/dashboard': Dashboard, // Added dashboard
'/blog': BlogPage // Added blog
},
agents: [supportAgent, salesAgent], // Added agents
workflows: {
onboarding: onboardingWorkflow, // Added automation
fulfillment: fulfillmentWorkflow
}
})Monitor Everything
// Set up comprehensive monitoring
export default $.business({
name: 'my-business',
monitoring: {
uptime: {
enabled: true,
notify: '[email protected]',
},
performance: {
enabled: true,
thresholds: {
api: 1000, // 1s
website: 3000, // 3s
},
},
business: {
enabled: true,
alerts: [
{ metric: 'churn_rate', threshold: 0.05, notify: '[email protected]' },
{ metric: 'completion_rate', threshold: 0.95, notify: '[email protected]' },
],
},
},
})