02 — AI Music Platform

Beatflow

AI-powered music generation ecosystem. Combines a Python AI inference engine (Modal) with a Node.js processing backend to turn user prompts into full tracks with auto-generated lyrics and cover art.

Next.js Modal (Python) Express (Node.js) Upstash Redis Neon Postgres FFmpeg Cloudflare R2
The challenge

From text prompt
to finished track.

Problem

Building a high-quality AI music generator requires multiple distinct services. You need heavy GPU compute to run synthesis models, LLMs to generate creative lyrics, and image models to generate cover art. Running all this synchronously on a single server leads to massive timeouts and crashes.

Furthermore, the raw `.wav` output from AI models is enormous. Serving uncompressed audio to thousands of frontend users directly from a GPU worker creates unbearable latency and bandwidth costs.

Solution

Beatflow implements a highly decoupled microservices architecture. A Python backend deployed on Modal orchestrates the heavy AI models (ACEStepPipeline, Qwen2, and SDXL-Turbo) using serverless GPUs.

Simultaneously, a dedicated Node.js/Express backend handles all post-processing via FFmpeg. It watches an Upstash Redis queue, pulls the raw AI audio, compresses it to MP3, generates 30-second watermarked previews, and offloads the final assets to Cloudflare R2 for zero-egress CDN delivery.

3,000+ unique visitors
1,500+ songs generated
3 model pipeline
System design

Architecture diagram

A multi-tier architecture decoupling the Next.js frontend, Python GPU inference engine, and Node.js audio processing worker via Upstash Redis.

Next.js Frontend Zustand · Better Auth
Upstash Redis async job queue
Neon Postgres user & track metadata
Modal Python API GPU task orchestration
Qwen2-7B lyrics & metadata
ACEStepPipeline music synthesis
SDXL-Turbo cover art generation
Express.js Worker Node.js backend
FFmpeg Pipeline WAV to MP3 · watermarks
Cloudflare R2 zero-egress CDN storage
Interface

Screenshots

Landing Page
High-conversion entry point showcasing the AI music generation capabilities, audio samples, and feature breakdowns.
Creation Dashboard
Main prompt interface allowing users to auto-generate lyrics via Qwen2-7B or provide their own, with real-time job status polling.
User Track Library
Neon Postgres-backed library showing track history, metadata tags, custom cover art, and options to download or share.
Engineering

Technical deep-dive

01
Multi-Model Orchestration
Generating a track requires a chain of models. I built a Python backend on Modal that receives a single prompt and orchestrates the flow: it queries `Qwen2-7B-Instruct` to write lyrics and metadata, feeds that into `ACEStepPipeline` to synthesize the raw audio tensor, and concurrently triggers `sdxl-turbo` to generate thematic cover art.
lyrics = await qwen2_model.generate(prompt)
audio = ace_pipeline.process(lyrics)
cover = sdxl_turbo.generate(prompt)
02
Dedicated Node.js Audio Worker
Audio processing is highly CPU-bound and shouldn't block the Python API. I decoupled this by building a separate Node.js/Express worker. It receives webhook payloads containing raw `.wav` paths, spins up FFmpeg to convert the files into web-optimized 192kbps `.mp3` files, and generates 30-second watermarked snippets for public sharing.
ffmpeg(rawPath)
.audioBitrate('192k')
.save(mp3Path) // Offloaded to Node.js
03
Upstash Redis Queuing
AI synthesis can take over 60 seconds, which will timeout standard HTTP requests. Beatflow's Next.js frontend pushes requests directly into an Upstash Redis queue. The UI utilizes `Zustand` to manage the local application state and continuously polls the queue status, providing the user with real-time updates (e.g., "Writing lyrics...", "Synthesizing audio...") without dropping the connection.
await redis.lpush('tasks', JSON.stringify(job));
// Worker pulls with BLPOP beatflow:queue
04
Zero-Egress Delivery with R2
Storing and streaming thousands of audio files on standard cloud providers results in massive egress fees. Beatflow bypasses this by uploading all processed audio and cover art directly to Cloudflare R2. The application generates short-lived signed URLs for clients, allowing them to stream music straight from Cloudflare's edge CDN with sub-80ms latency.
const url = await getSignedUrl(s3Client, command, {
expiresIn: 3600
});
Previous SketchWiz AI Canvas · WebSockets Next ViralRot AI Video · GPU Pipelines