An AI-powered music generation platform built on Cloudflare Workers that transforms text prompts into complete musical compositions with AI-generated artwork, lyrics, and songs.
Smol Workflow uses Cloudflare Workflows to orchestrate a complex, multi-step AI generation pipeline that creates "Smols" - unique music experiences combining:
- AI-Generated Pixel Art (via Pixellab)
- AI-Described Image Metadata (via Cloudflare AI)
- AI-Generated Lyrics (via AI Song Generator)
- AI-Generated Songs (via AI Song Generator / DiffRhythm)
- NSFW Content Detection (via Cloudflare AI)
- Stellar Blockchain Integration for minting songs as tokens
- Cloudflare Workers - Serverless compute platform
- Cloudflare Workflows - Durable execution engine for complex, multi-step processes
- Cloudflare Durable Objects - Stateful storage for workflow steps
- Hono - Lightweight web framework
- Stellar SDK - Blockchain integration
- D1 (SQLite) - Relational database for Smols, Users, Likes, Mixtapes
- KV - Key-value store for workflow state
- R2 - Object storage for images and audio files
- Pixellab - Pixel art generation
- Cloudflare AI - Image description and NSFW detection
- AI Song Generator - Lyrics and music generation
- DiffRhythm - Fallback music generation service
src/
├── index.ts # Main application entry point
├── workflow.ts # Main Smol generation workflow
├── tx-workflow.ts # Stellar blockchain transaction workflow
├── do.ts # Durable Objects for state management
├── types.ts # TypeScript type definitions
├── utils.ts # Utility functions
├── utils/
│ └── pagination.ts # Pagination helpers
├── middleware/
│ └── auth.ts # JWT authentication middleware
├── api/
│ ├── auth.ts # Authentication endpoints (login/logout)
│ ├── smols.ts # Smol CRUD operations
│ ├── likes.ts # Like/unlike functionality
│ ├── mixtapes.ts # Mixtape creation and retrieval
│ ├── mint.ts # Stellar blockchain minting
│ ├── media.ts # Audio/image serving with range requests
│ └── playlists.ts # Playlist management
└── ai/
├── pixellab.ts # Pixel art generation
├── cf.ts # Cloudflare AI integration
├── aisonggenerator.ts # Song and lyrics generation
└── nsfw.ts # NSFW content detection
ext/
└── smol-sdk/ # Stellar smart contract SDK
The main workflow (src/workflow.ts) executes the following steps:
- Validate Input - Ensure address and prompt are provided
- Save Payload - Store initial parameters in Durable Object
- Generate Image - Create pixel art based on prompt
- Describe Image - Generate metadata description
- Generate Lyrics - Create title, lyrics, and style
- Check NSFW - Validate content safety
- Generate Songs - Create 2 song variations
- Wait for Completion - Poll until songs finish processing
- Store Results - Save to D1, KV, and R2
- Complete Workflow - Clean up and optionally add to playlist
Each step is retryable with exponential backoff and has a 5-minute timeout.
POST /login- Create account or authenticate with passkeyPOST /logout- Clear authentication
GET /- List all public Smols (paginated)GET /created- List authenticated user's SmolsGET /liked- List authenticated user's liked SmolsGET /:id- Get specific Smol with workflow statusPOST /- Create new Smol (starts workflow)POST /retry/:id- Retry failed Smol generationPUT /:id- Toggle public/private visibilityPUT /:smol_id/:song_id- Swap song orderDELETE /:id- Delete Smol and associated media
GET /likes- Get authenticated user's liked Smol IDsPUT /likes/:id- Toggle like on a Smol
GET /mixtapes- List all mixtapesGET /mixtapes/:id- Get specific mixtapePOST /mixtapes- Create new mixtape (collection of Smols)
GET /song/:id.mp3- Stream song with range request supportGET /image/:id.png- Serve image with optional scaling
POST /mint/:id- Mint single Smol as Stellar tokenPOST /mint- Batch mint multiple Smols
Id TEXT PRIMARY KEY
Title TEXT NOT NULL
Song_1 TEXT NOT NULL
Song_2 TEXT NOT NULL
Created_At DATETIME DEFAULT CURRENT_TIMESTAMP
Public BOOLEAN DEFAULT 1
Instrumental BOOLEAN DEFAULT 0
Plays INTEGER DEFAULT 0
Views INTEGER DEFAULT 0
Address TEXT NOT NULL
Mint_Token TEXT DEFAULT NULL
Mint_Amm TEXT DEFAULT NULLUsername TEXT NOT NULL
Address TEXT NOT NULL
UNIQUE (Username, Address)Id TEXT NOT NULL
Address TEXT NOT NULL
UNIQUE (Id, Address)Id TEXT PRIMARY KEY
Title TEXT NOT NULL
Desc TEXT NOT NULL
Smols TEXT NOT NULL -- Comma-separated list
Address TEXT NOT NULL
Created_At DATETIME DEFAULT CURRENT_TIMESTAMP- Node.js 18+
- Wrangler CLI
- Cloudflare account
# Install dependencies
npm install
# Start local development server
npm start
# Start with remote bindings (production-like environment)
npm run start:remote
# Type check
npm run typecheck
# Deploy to Cloudflare
npm run deployRequired secrets (set via wrangler secret put):
SECRET- JWT signing secretSK- Stellar secret key for transaction signingLAUNCHTUBE_TOKEN- Authorization token for Launchtube service
Environment variables (in wrangler.jsonc):
RPC_URL- Stellar RPC endpointNETWORK_PASSPHRASE- Stellar network identifierSMOL_CONTRACT_ID- Deployed smart contract address
Workflows:
WORKFLOW- Main Smol generation workflowTX_WORKFLOW- Stellar transaction workflow
Durable Objects:
DURABLE_OBJECT(SmolDurableObject) - Workflow state storageDO_STATE(SmolState) - Additional state management
Storage:
SMOL_D1- D1 databaseSMOL_KV- KV namespaceSMOL_BUCKET- R2 bucket
AI & Services:
AI- Cloudflare AI bindingAISONGGENERATOR- Song generation service bindingLAUNCHTUBE- Stellar transaction submission service
The project includes a custom SDK (ext/smol-sdk) for interacting with Stellar smart contracts. The TxWorkflow handles:
- Single Mints - Create token and AMM for individual Smols
- Batch Mints - Efficiently mint multiple Smols in one transaction
- Auth Entry Signing - Sign Stellar transactions with stored keypair
Minted tokens are recorded in the database (Mint_Token, Mint_Amm) for future reference.
Failed workflows can be retried while preserving completed steps, saving time and API credits.
All list endpoints support cursor-based pagination via limit and cursor query parameters.
Songs support HTTP range requests for efficient streaming and seeking.
Images can be scaled on-demand via the scale query parameter using nearest-neighbor interpolation.
Content is automatically analyzed and flagged/hidden if deemed unsafe.
Workflow state is persisted in Durable Objects and auto-cleaned after completion via scheduled alarms.
Apache 2.0 - See LICENSE file for details.
Copyright 2024, Cloudflare.