openapi: 3.1.0 info: title: AI Vocal Coach API version: "1.0.0" summary: > Auth/account (E1), song upload/YouTube import/analysis queue (E2), per-aspect scores/report/piano-roll (E4) and the progress-over-time chart (E5, FR-35). A paginated /analyses history endpoint (FR-34) is not yet built. servers: - url: /api/v1 paths: /auth/register: post: operationId: registerWithEmail summary: Register with email and password tags: [auth] security: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/RegisterRequest" responses: "202": description: > Accepted. The response never reveals whether the email was already registered (spec 9.1). content: application/json: schema: $ref: "#/components/schemas/MessageResponse" "400": $ref: "#/components/responses/BadRequest" /auth/verify: post: operationId: verifyEmail summary: Confirm an email address with its 6-digit code tags: [auth] security: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/VerifyRequest" responses: "200": description: Email verified. content: application/json: schema: $ref: "#/components/schemas/MessageResponse" "400": description: Code invalid or expired. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" "429": $ref: "#/components/responses/TooManyRequests" /auth/verify/resend: post: operationId: resendVerificationCode summary: Resend the verification code (max 1/60s, 5/day) tags: [auth] security: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/ResendRequest" responses: "200": description: Sent, if the account exists and is unverified. content: application/json: schema: $ref: "#/components/schemas/MessageResponse" "429": $ref: "#/components/responses/TooManyRequests" /auth/login: post: operationId: login summary: Log in with email and password tags: [auth] security: [] requestBody: required: true content: application/json: schema: $ref: "#/components/schemas/LoginRequest" responses: "200": description: > Authenticated. Sets the refresh token as an httpOnly cookie scoped to /api/v1/auth; the response body carries only the access token. headers: Set-Cookie: schema: type: string content: application/json: schema: $ref: "#/components/schemas/SessionResponse" "401": description: Invalid credentials, or correct password but email not verified. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" "429": $ref: "#/components/responses/TooManyRequests" /auth/refresh: post: operationId: refreshSession summary: Rotate the refresh token and mint a new access token tags: [auth] security: - refreshCookie: [] responses: "200": description: New access token issued; refresh cookie rotated. content: application/json: schema: $ref: "#/components/schemas/SessionResponse" "401": description: Refresh token missing, expired, or reused (forces re-login). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" /auth/logout: post: operationId: logout summary: Log out of the current session tags: [auth] security: - refreshCookie: [] responses: "200": description: Logged out; refresh cookie cleared. content: application/json: schema: $ref: "#/components/schemas/MessageResponse" /auth/google: get: operationId: startGoogleLogin summary: Start the Google OAuth2/PKCE flow tags: [auth] security: [] responses: "302": description: Redirect to Google's consent screen. /auth/google/callback: get: operationId: googleLoginCallback summary: Google OAuth2 callback tags: [auth] security: [] parameters: - name: code in: query required: true schema: type: string - name: state in: query required: true schema: type: string responses: "302": description: > Redirect to APP_BASE_URL with the refresh cookie set. The access token is never placed in the URL; the frontend calls /auth/refresh on load to mint its first one. "400": description: OAuth state mismatch or missing PKCE cookies. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" /me: get: operationId: getProfile summary: Get the authenticated user's profile tags: [account] security: - bearerAuth: [] responses: "200": description: The caller's profile. content: application/json: schema: $ref: "#/components/schemas/User" "401": $ref: "#/components/responses/Unauthorized" delete: operationId: deleteAccount summary: Delete the authenticated user's account and all their data tags: [account] security: - bearerAuth: [] responses: "204": description: Account and every session revoked; cascades to owned data. "401": $ref: "#/components/responses/Unauthorized" /songs: post: operationId: addSong summary: Add a song by file upload or YouTube link (FR-10, FR-11) tags: [songs] security: - bearerAuth: [] requestBody: required: true content: multipart/form-data: schema: $ref: "#/components/schemas/AddSongRequest" responses: "201": description: > Song catalogued and its cold path (reference separation, transcription, pitch curve) queued immediately (spec 6.2, FR-15) -- poll GET /songs/{id} or watch prep_status for readiness. `reused: true` means an identical song (by content hash / YouTube video id) already existed, this upload was deduplicated (spec 6.6, FR-13), and no new cold path run was queued. content: application/json: schema: $ref: "#/components/schemas/Song" "400": $ref: "#/components/responses/BadRequest" "401": $ref: "#/components/responses/Unauthorized" "403": description: YouTube import is disabled (spec 11.4). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" "413": description: Audio exceeds MAX_UPLOAD_MB. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" "429": $ref: "#/components/responses/TooManyRequests" /songs/{id}: get: operationId: getSong summary: Get a song's reference preparation status (FR-14) tags: [songs] security: - bearerAuth: [] parameters: - name: id in: path required: true schema: type: string format: uuid responses: "200": description: The song. content: application/json: schema: $ref: "#/components/schemas/Song" "401": $ref: "#/components/responses/Unauthorized" "404": description: No song with this id. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" /songs/{id}/prepare: post: operationId: retrySongPrep summary: Restart a song's cold path after it failed, without re-uploading (FR-17) tags: [songs] security: - bearerAuth: [] parameters: - name: id in: path required: true schema: type: string format: uuid responses: "202": description: Re-queued onto songs:prep. Progress follows via GET /songs/{id} (FR-14). content: application/json: schema: $ref: "#/components/schemas/Song" "401": $ref: "#/components/responses/Unauthorized" "404": description: No song with this id. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" "409": description: The song's prep_status is not 'failed' (`SONG_PREP_NOT_FAILED`). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" "429": $ref: "#/components/responses/TooManyRequests" /analyses: post: operationId: enqueueAnalysis summary: Put a recording in the analysis queue (FR-22) tags: [analyses] security: - bearerAuth: [] requestBody: required: true content: multipart/form-data: schema: $ref: "#/components/schemas/EnqueueAnalysisRequest" responses: "202": description: > Queued, or waiting_for_reference if the song's cold path hasn't reached ready yet (spec 6.2, 10.3, FR-16) -- it transitions to queued automatically, no re-submission needed. Position updates follow over the WebSocket channel. content: application/json: schema: $ref: "#/components/schemas/Analysis" "400": $ref: "#/components/responses/BadRequest" "401": $ref: "#/components/responses/Unauthorized" "404": description: No song with this id. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" "409": description: The song's cold path already failed (`REFERENCE_PREP_FAILED`, FR-17). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" "413": description: Recording exceeds MAX_UPLOAD_MB. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" "429": $ref: "#/components/responses/TooManyRequests" /analyses/{id}: get: operationId: getAnalysis summary: Get an analysis's current status, scoped to its owner tags: [analyses] security: - bearerAuth: [] parameters: - name: id in: path required: true schema: type: string format: uuid responses: "200": description: The analysis. content: application/json: schema: $ref: "#/components/schemas/Analysis" "401": $ref: "#/components/responses/Unauthorized" "404": description: No analysis with this id owned by the caller. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" /analyses/{id}/cancel: post: operationId: cancelAnalysis summary: Cancel an analysis while it is queued or waiting_for_reference (FR-25) tags: [analyses] security: - bearerAuth: [] parameters: - name: id in: path required: true schema: type: string format: uuid responses: "200": description: Canceled. content: application/json: schema: $ref: "#/components/schemas/Analysis" "401": $ref: "#/components/responses/Unauthorized" "404": description: No analysis with this id owned by the caller. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" "409": description: The analysis is not queued or waiting_for_reference anymore (`ANALYSIS_NOT_QUEUED`). content: application/problem+json: schema: $ref: "#/components/schemas/Problem" /analyses/{id}/retry: post: operationId: retryAnalysis summary: Restart a failed analysis without re-uploading the recording (FR-26) tags: [analyses] security: - bearerAuth: [] parameters: - name: id in: path required: true schema: type: string format: uuid responses: "202": description: > Re-queued, or back to waiting_for_reference if the song's cold path still hasn't reached ready (spec 6.2, 10.3, FR-16) -- same duality as enqueueAnalysis. Position updates follow over the WebSocket channel. content: application/json: schema: $ref: "#/components/schemas/Analysis" "401": $ref: "#/components/responses/Unauthorized" "404": description: No analysis with this id owned by the caller. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" "409": description: > Either the analysis is not in the failed state (`ANALYSIS_NOT_FAILED`), or its song's cold path itself failed (`REFERENCE_PREP_FAILED`, FR-17) -- restart the song's prep (POST /songs/{id}/prepare) before retrying this analysis again. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" "429": $ref: "#/components/responses/TooManyRequests" /ws/analyses/{id}: get: operationId: watchAnalysisQueuePosition summary: WebSocket status channel for one analysis (spec 8.3) description: > Upgrades to a WebSocket. The client's first message must be `{"token": ""}` (never a query parameter, so it never lands in proxy logs); the server then pushes one JSON event per status change, each with a `type` field: `{"type": "queued", "position": N}` while queued; `{"type": "stage", "name": "pitch", "index": 5, "total": 10}` once the E3 worker picks the job up, one push per stage started; `{"type": "done", "analysis_id": "..."}` on success; `{"type": "failed", "error_code": "...", "message": "..."}` on failure (spec 6.8 error codes). `stage`/`done`/`failed` events are relayed from the worker over Redis Pub/Sub (ADR-0010) and are best-effort -- WebSocket is a status-only transport, the final result is always read back over REST (fallback to polling GET /analyses/{id} if the socket drops or an event is missed). tags: [analyses] security: - bearerAuth: [] parameters: - name: id in: path required: true schema: type: string format: uuid responses: "101": description: Switching Protocols to WebSocket. "401": $ref: "#/components/responses/Unauthorized" /progress: get: operationId: getProgress summary: Get the caller's overall_score points for the progress chart (FR-35) description: > Every completed analysis's overall_score, oldest first (spec 7's progress_snapshots, written by the E3 worker once stage 11 succeeds). Not cursor-paginated like a browsable list (spec 8.1): this feeds a chart in one call rather than something a user pages through, so the server caps it at a fixed size instead. tags: [progress] security: - bearerAuth: [] responses: "200": description: The caller's progress points. content: application/json: schema: type: array items: $ref: "#/components/schemas/ProgressPoint" "401": $ref: "#/components/responses/Unauthorized" /healthz: servers: - url: / get: operationId: healthz summary: Liveness probe tags: [ops] security: [] responses: "200": description: Process is up. /readyz: servers: - url: / get: operationId: readyz summary: Readiness probe (Postgres + Redis reachable) tags: [ops] security: [] responses: "200": description: Ready to serve traffic. "503": description: A dependency is unavailable. components: securitySchemes: bearerAuth: type: http scheme: bearer bearerFormat: JWT refreshCookie: type: apiKey in: cookie name: refresh_token responses: BadRequest: description: The request failed validation. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" Unauthorized: description: Missing or invalid access token. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" TooManyRequests: description: Rate limit or lockout in effect. headers: Retry-After: schema: type: integer description: Seconds until the next attempt may succeed. content: application/problem+json: schema: $ref: "#/components/schemas/Problem" schemas: RegisterRequest: type: object required: [email, password, display_name] additionalProperties: false properties: email: type: string format: email maxLength: 254 password: type: string minLength: 10 maxLength: 256 description: Rejected if under 10 characters or one of the most common passwords. display_name: type: string minLength: 1 maxLength: 100 VerifyRequest: type: object required: [email, code] additionalProperties: false properties: email: type: string format: email code: type: string pattern: "^[0-9]{6}$" ResendRequest: type: object required: [email] additionalProperties: false properties: email: type: string format: email LoginRequest: type: object required: [email, password] additionalProperties: false properties: email: type: string format: email password: type: string MessageResponse: type: object required: [message] properties: message: type: string SessionResponse: type: object required: [access_token, expires_in_seconds] properties: access_token: type: string expires_in_seconds: type: integer User: type: object required: [id, email, display_name, email_verified, created_at] properties: id: type: string format: uuid email: type: string format: email display_name: type: string email_verified: type: boolean created_at: type: string format: date-time AddSongRequest: type: object description: > multipart/form-data. source_type selects the branch: `file` is required and `artist` optional for `upload`; `youtube_url` is required for `youtube` (title then falls back to the video's own title if omitted). required: [source_type] properties: source_type: type: string enum: [upload, youtube] title: type: string maxLength: 200 description: Required for source_type=upload; optional override for youtube. artist: type: string maxLength: 200 file: type: string format: binary description: Required for source_type=upload. mp3/wav/m4a/flac/ogg/webm, checked by magic bytes. youtube_url: type: string maxLength: 2048 description: Required for source_type=youtube. Must be a youtube.com/youtu.be link. Song: type: object required: [id, source_type, title, duration_sec, prep_status, lyrics_available, reused, created_at] properties: id: type: string format: uuid source_type: type: string enum: [upload, youtube] title: type: string artist: type: string duration_sec: type: integer prep_status: type: string enum: [pending, processing, ready, failed] description: >- Cold path lifecycle (spec 6.2, 10, FR-14). `ready` means the reference vocal stem and pitch curve are cached and any queued analysis of this song can run immediately. prep_stage: type: string description: The P-stage currently running (P1-P4, spec 6.4). Absent when not processing. prep_error_code: type: string description: Set once prep_status is 'failed' (FR-17); restart via POST /songs/{id}/prepare. lyrics_available: type: boolean description: >- False when P3 (Whisper transcription) failed or timed out for this song -- optional stage, never blocks the cold path (FR-18). prepared_at: type: string format: date-time description: When prep_status last reached 'ready'. Absent until then. reused: type: boolean description: True if this submission deduplicated onto an existing song (spec 6.6, FR-13). created_at: type: string format: date-time EnqueueAnalysisRequest: type: object description: multipart/form-data. required: [song_id, recording] properties: song_id: type: string format: uuid mode: type: string enum: [clean, mixed] default: clean description: >- Which analysis mode to run (spec 2.3, FR-27). `clean` (a cappella) is recommended and scores all six aspects at the highest accuracy; `mixed` (any accompaniment) scores four, at reduced accuracy. Defaults to `clean` when omitted. allow_transposition: type: boolean description: >- Whether the user may have sung in a different key (FR-31, spec 6.8). Defaults to `false` for `clean` and `true` for `mixed` when omitted. locale: type: string enum: [en, uk] default: en description: >- Language the FR-32 feedback report is written in (ADR-0031). Fixed for this analysis at creation time; a later UI language switch never retroactively re-renders it. Defaults to `en` when omitted. recording: type: string format: binary description: >- The user's recording. mp3/wav/m4a/flac/ogg/webm (the last is what MediaRecorder produces in-browser on Chrome/Firefox, FR-20), checked by magic bytes, ≤ MAX_AUDIO_SECONDS. Analysis: type: object required: [id, song_id, status, mode, created_at, queued_at] properties: id: type: string format: uuid song_id: type: string format: uuid status: type: string enum: [queued, waiting_for_reference, processing, done, failed, canceled] description: >- waiting_for_reference means the job was created before its song's cold path reached ready; it transitions to queued automatically once the song is ready (spec 6.2, 10.3, FR-16). mode: type: string enum: [clean, mixed] description: The mode the user chose at POST /analyses (spec 2.3, FR-27). effective_mode: type: string enum: [clean, mixed] description: >- What the worker's stage A3 actually reconciled `mode` to once it saw the recording (spec 6.16) -- e.g. auto-downgraded from `mixed` to `clean` when no accompaniment was detected (FR-29). Absent until that stage completes. queue_position: type: integer description: 1-based position among currently queued jobs. Absent once no longer queued. current_stage: type: string description: Set by the worker once processing starts. current_stage_index: type: integer description: >- 1-based position of current_stage among total_stages (spec 6.2), matching the WS `stage` event (spec 8.3). Set once processing starts. total_stages: type: integer description: Total pipeline stages for this analysis (spec 6.2). current_stage_started_at: type: string format: date-time description: >- When current_stage began. Lets the client render a live elapsed timer instead of a static label that looks frozen during a multi-minute stage (Demucs/Whisper, spec 6.2). stages: type: object description: >- Every already-completed stage's real recorded duration, keyed by stage name (spec 6.1) -- a running timeline, not just the current stage. additionalProperties: $ref: "#/components/schemas/StageProgress" error_code: type: string pitch_score: type: number rhythm_score: type: number vibrato_score: type: number breath_score: type: number dynamics_score: type: number timbre_score: type: number overall_score: type: number description: Weighted sum of the six aspect scores (spec 6.4), set by stage 11. feedback_text: type: string description: Readable per-aspect report with concrete advice (FR-32). scoring_version: type: string description: Which SCORING_WEIGHTS this analysis was scored under (spec 6.4). weights_profile: type: string description: >- Which named weight profile (`clean_v1`/`mixed_v1`, spec 6.14) overall_score was computed under. Two analyses with different weights_profile must never have their overall_score compared directly without flagging that to the user (FR-49). confidence: type: string enum: [high, medium, low] description: >- Overall reliability of this analysis's scores (spec 6.15, FR-47). Absent until stage 11 (aggregate) completes. aspect_confidence: type: object description: Per-aspect confidence level, keyed by aspect name (spec 6.15). additionalProperties: type: string enum: [high, medium, low] warnings: type: array description: >- Machine-readable warning codes (spec 6.18), e.g. `ACCOMPANIMENT_IN_CLEAN_MODE`, `MODE_DOWNGRADED_TO_CLEAN`, `LITTLE_VOICE_DETECTED`, `WEAK_ALIGNMENT`, `KEY_SHIFT_OUT_OF_RANGE`, `LENGTH_MISMATCH_PARTIAL_ANALYSIS` (ADR-0030: the recording and reference were cropped to a shared overlap before aligning), `REFERENCE_START_OFFSET_DETECTED` (ADR-0032: the reference's own start was adjusted to where the recording actually begins, e.g. an instrumental intro the recording didn't include). The client localizes these to a human-readable message rather than showing the code (FR-47). items: type: string unavailable_aspects: type: object description: >- Every aspect this mode does not score, mapped to a machine-readable reason (FR-41) -- e.g. `breath`/`timbre` under `NOT_MEASURABLE_WITH_ACCOMPANIMENT` in `mixed`. An aspect listed here is never also present as a `0` in its `*_score` field: it is simply absent there. additionalProperties: type: string key_shift_semitones: type: number description: >- Applied tonality-normalization shift in semitones, if any (spec 6.8, FR-46). Absent when no shift was applied. piano_roll: $ref: "#/components/schemas/PianoRoll" created_at: type: string format: date-time queued_at: type: string format: date-time description: >- When the *current* queued/waiting_for_reference wait began. Equal to created_at for a fresh submission; reset to the retry time by POST /analyses/{id}/retry (FR-26), so a client's live wait timer never measures from a stale original submission. completed_at: type: string format: date-time StageProgress: type: object description: >- Display-only summary of one completed pipeline stage (spec 6.1) -- never the stage's own `data` (which can carry a full pitch curve for the "pitch" stage, already exposed separately as pitch_curve_json) or its error detail. required: [status, duration_ms] properties: status: type: string enum: [done, failed] duration_ms: type: integer description: Real wall-clock time the stage took. PianoRoll: type: object description: >- FR-31 overlay data: the user's pitch curve and the reference curve already resampled onto the user's own time grid, frame for frame, so the client never needs to redo the DTW alignment (spec 6.3.4/6.3.5) to draw the two curves together. required: [hop_seconds, user_hz, reference_hz, deviation_cents, off_pitch] properties: hop_seconds: type: number description: Seconds between consecutive frames; frame i's time is i * hop_seconds. user_hz: type: array items: type: number nullable: true reference_hz: type: array items: type: number nullable: true deviation_cents: type: array description: Signed cents deviation per frame, null wherever either side is unvoiced. items: type: number nullable: true off_pitch: type: array description: deviation_cents already thresholded against PIANO_ROLL_OFF_PITCH_CENTS. items: type: boolean ProgressPoint: type: object description: >- One dated overall_score sample for the FR-35/FR-49 progress chart. mode/confidence are denormalized alongside overall_score: two points with different mode were scored under different weights_profile (spec 6.14) and must be visually distinguished, never presented as directly comparable (FR-49). required: [analysis_id, overall_score, mode, created_at] properties: analysis_id: type: string format: uuid overall_score: type: number mode: type: string enum: [clean, mixed] confidence: type: string enum: [high, medium, low] created_at: type: string format: date-time Problem: type: object description: RFC 9457 application/problem+json body. required: [type, title, status, detail, code, request_id] properties: type: type: string title: type: string status: type: integer detail: type: string code: type: string description: Stable machine-readable error code; frontend localizes on this. request_id: type: string