Express MVC service that fronts @mixtapelabs/engine and exposes REST endpoints for the Next.js frontend.
src/
ββ config/ # env + prisma config
ββ clients/ # metadata/analysis/http/stub clients
ββ controllers/ # HTTP controllers (e.g., SessionController)
ββ middleware/ # cross-cutting middleware (Cerberus/JWT auth)
ββ repositories/ # Prisma persistence helpers
ββ routes/ # Express routers
ββ services/ # Orchestration between engine + repo
ββ server.ts # Bootstrap entrypoint
- Node.js β₯ 18
- Access to the private
@mixtapelabs/enginepackage (localfile:../engineor GitHub Packages) - PostgreSQL database (
DATABASE_URL="postgresql://user:password@localhost:5432/mixtapelabs_api"). - Cerberus IAM tenant (base URL + OAuth2 client credentials) or a fallback
JWT_SECRETfor local testing.
npm install
npx prisma generate| Variable | Description |
|---|---|
PORT |
HTTP port (default 4001) |
DATABASE_URL |
PostgreSQL connection string (e.g., postgresql://user:pass@localhost:5432/mixtapelabs_api) |
CORS_ORIGIN |
Allowed origins for CORS (e.g., https://app.example.com or comma-separated list). If not set, reflects the request origin (allows all origins with credentials) |
CERBERUS_BASE_URL |
Cerberus IAM host (e.g., https://cerberus.example.com) |
CERBERUS_CLIENT_ID |
OAuth2 client ID used for token introspection |
CERBERUS_CLIENT_SECRET |
OAuth2 client secret used for token introspection |
JWT_SECRET |
Optional local fallback; enables Bearer JWT auth when Cerberus is unavailable |
METADATA_SERVICE_URL / ANALYSIS_SERVICE_URL |
External services when not using stubs |
METADATA_SERVICE_API_KEY / ANALYSIS_SERVICE_API_KEY |
Shared secrets passed via x-api-key for the respective microservices |
FEEDBACK_SERVICE_URL / FEEDBACK_SERVICE_API_KEY |
Required when FEEDBACK_MODE=service |
FEEDBACK_MODE |
openai, stub, or service |
OPENAI_API_KEY |
Required when FEEDBACK_MODE=openai |
USE_STUB_CLIENTS |
Force stub clients even if service URLs provided |
npm run dev # ts-node-dev hot reload
npm run lint # eslint
npm run typecheck # tsc --noEmit
npm test # vitest + supertest
npm run build # tsup -> dist/
npm start # node dist/server.js
npm run format # prettier src/ and test/
npm run ci # lint + typecheck + test + build
npm run docs:dev # (from repo root) run VitePress docsprisma/schema.prismadefines a simpleSessionmodel storing engine state JSON.- Run migrations as needed (
npx prisma migrate dev --name init).
Proxy to Cerberus IAM /v1/auth/login. Confirms credentials/MFA and returns user + organisation info (no tokens).
Unified token helper that proxies Cerberus /oauth2/token.
- Authorization Code (PKCE): provide
grantType: "authorization_code"along withcode,redirectUri, andcodeVerifier. - Client Credentials: supply
grantType: "client_credentials"and an optionalscopeto mint machine-to-machine tokens (no end-user interaction). The API fillsclientId/clientSecretfrom env unless you override them in the payload.
Response mirrors Cerberus (access_token, refresh_token, etc.).
Requires Authorization: Bearer <token>. Uses Cerberus token introspection, returns the verified user payload.
Creates a new audio analysis session. Requires authentication.
Important: The uploadUrl must point to a publicly accessible audio file hosted on cloud storage (S3, CDN, etc.). The API does not handle file uploads directly - users must upload their files separately and provide the URL.
Body:
The API will:
- Extract metadata (duration, format, sample rate) via metadata service
- Perform audio analysis (loudness, dynamics, spectrum, stereo) via analysis service
- Generate AI feedback via feedback service (OpenAI GPT-4)
- Store complete results in database
Response: EngineState from @mixtapelabs/engine with all analysis results. Include Authorization: Bearer <token> or authenticate via httpOnly cookie.
- API key middleware protects endpoints when
API_KEYis set. - Prisma client handles DB writes; sanitize tokens via environment variables.
- CI/CD should run
npm run ciandnpx prisma migrate deploybeforenpm start.
Build the API service for Railway deployment:
# Build with npm token for private @mixtapelabs/engine package
docker build --build-arg NPM_TOKEN=$NPM_TOKEN -t mixtapelabs-api .
docker run -p 8080:8080 --env-file .env mixtapelabs-apiThe Dockerfile handles:
- GitHub Packages Authentication: Requires
NPM_TOKENbuild arg to install private@mixtapelabs/enginepackage - Prisma Client Generation: Runs
npx prisma generateduring build - Database Migrations: Runs
npm run db:deployon container start - TypeScript Compilation: Builds to
dist/directory
::: tip Railway Deployment When deploying to Railway as a standalone repository:
- Ensure
Dockerfileexists in repo root (Railway auto-detects it) - Set
NPM_TOKENenvironment variable in Railway with your GitHub Personal Access Token (withread:packagesscope) - Add database reference:
DATABASE_URL=${{Postgres.DATABASE_URL}} - Configure service references for internal networking:
METADATA_SERVICE_URL=https://metadata.railway.internalANALYSIS_SERVICE_URL=https://analysis.railway.internal
- Generate and set API keys for service authentication
The Dockerfile ensures Prisma Client is generated before runtime, preventing @prisma/client did not initialize errors.
:::
- Read
CONTRIBUTING.md,CODE_OF_CONDUCT.md, andSECURITY.mdbefore submitting changes. - Use the provided GitHub issue templates (bug/feature) and PR template to streamline reviews.
- Default CODEOWNERS:
@mixtapelabs/maintainers.
{ "sessionId": "mix-42", "uploadUrl": "https://cdn.example.com/mix.wav", // Must be publicly accessible HTTPS URL "userContext": { "daw": "Ableton Live", "genre": "House", "experienceLevel": "intermediate" } }