Skip to content

NafeesMadni/Stratum-Backend

Repository files navigation

🚀 FastAPI Project

This is a FastAPI project setup using uv, a blazing fast Python package manager.

Follow the steps below to get started.


📦 Requirements

  • Python 3.12 (uv handles virtual environments automatically)
  • uv installed
curl -LsSf https://astral.sh/uv/install.sh | sh

⚙️ Environment Variables

Create a .env file in the project root with the following values:

# Spotify API Keys
SPOTIFY_CLIENT_ID=
SPOTIFY_CLIENT_SECRET=

# Google YT API key
YOUTUBE_API_KEY=

# Supabase API keys
SUPABASE_API_KEY=
SUPABASE_URL=
BUCKET_NAME=

# Atlas MONGODB Connection String
MONGODB_URL=

# Replicate API Key
REPLICATE_API_TOKEN=

# API Key
GROQ_API_KEY=

# Logging
LOG_LEVEL=INFO   # Options: NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL

⚠️ Make sure not to commit .env to version control.


How to get your MongoDB connection string

1. Create an Account on MongoDB Atlas

2. Create a Cluster

  • Once logged in, you'll be redirected to the MongoDB Atlas Dashboard.
  • Click on "Create Cluster".
  • Select the Free Plan (M0) as your cluster type.
  • Follow the steps for creating a cluster (choose cloud provider and region).
  • Click on "Create Cluster".

3. Create Database Users

  • After the cluster is created, you will be taken to a "Connect to _cluster_name" popup.

  • Under "Create Database User", you need to create a user with a username and password:

    • Choose a Username (e.g., myUser).
    • Choose a Password (e.g., myPassword123).
    • Click on the "Create Database User" button.

4. Connect to Your Cluster

  • After creating your database user, go to the next step in the popup.

  • Choose "Drivers" as the connection method.

  • Select Python as your driver.

  • In the next step, select the version of Python you’re using.

  • MongoDB will now show you the connection string. It will look something like this:

    mongodb+srv://<username>:<password>@cluster0.mongodb.net/test?retryWrites=true&w=majority
    

🎵 Audio Processing Setup

Saves processed stems file to Supabase Storage.

Before running:

  1. Go to your Supabase project dashboard

  2. Navigate to Storage → Buckets

  3. Create a new bucket with the name:

    Media-Files
    
  4. Enable ✅ “Public bucket”

  5. Inside this bucket, create a directory:

    audio_stems
    

Now, Splitter AI will save all audio files under:

Media-Files/audio_stems/

🏷️ API Versioning & Pricing

The API supports two versions for stem extraction, each with different processing methods and costs:

API Version Processing Method Cost Notes
v1 Local Processing Free Uses the local logic with HTDemucs model. Requires sufficient local resources.
v2 Replicate ~$0.039 / run Uses cloud-based processing via Replicate. Ideal for scalable deployments without local GPU.

💡 Tip: Use v2 if you want to offload processing power, or stick to v1 for free local testing.


⚙️ Local Setup Instructions

  1. Clone the repository

    git clone https://github.com/NafeesMadni/Stratum-Backend.git
    cd Stratum-Backend
  2. Install dependencies

    uv sync
  3. Activate the virtual environment (optional if you run via uv run)

    source .venv/bin/activate   # Linux / MacOS
    .venv\Scripts\activate      # Windows

▶️ Running the App (Local)

uv run main.py

⚡ Running Celery Worker (Local)

celery -A app.core.celery_app worker --loglevel=info

🧪 Running Tests

Run all tests:

pytest

Run Audio Processing API tests:

pytest tests/test_audio_api_workflow.py

🐳 Running with Docker & Docker Compose

1. Build & Start Services

docker-compose up --build

Services started:

  • Redis (broker & backend for Celery)
  • Web (FastAPI app)http://localhost:8000
  • Celery Worker (background task processor)

2. Stop Services

docker-compose down

Remove volumes (e.g., Redis data):

docker-compose down -v

3. Logs

docker-compose logs -f        # all services
docker-compose logs -f web    # only FastAPI
docker-compose logs -f celery-worker

About

Stratum is a high-performance, asynchronous backend service designed to process Spotify tracks for advanced audio analysis. It serves as a bridge between streaming platforms and AI-driven audio processing, enabling users to retrieve rich metadata, transcribe lyrics, and split songs into individual instrument stems (vocals, drums, bass, etc.)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors