-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathopenapi.yaml
More file actions
1621 lines (1529 loc) · 58.6 KB
/
Copy pathopenapi.yaml
File metadata and controls
1621 lines (1529 loc) · 58.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
openapi: 3.0.3
info:
title: Moodify API
version: "1.1.0"
description: |
_Emotion-driven music recommendation API — Django backend + Modal inference service._
Single source of truth for **both** HTTP surfaces that make up Moodify in
production:
* The **Django backend** at `https://moodify-emotion-music-app-backend.vercel.app`
(also exposed locally on `http://127.0.0.1:8000`). Owns user accounts,
JWTs, mood / listening / saved-recommendation history, and proxies the
cheap text-emotion + recommendation calls.
* The **Modal inference service** at
`https://hoangsonww--moodify-inference-inferenceservice-web.modal.run`.
Owns the ML models (text, speech, face) plus the Deezer-backed
recommender. Web + mobile clients call Modal directly for speech and
facial uploads to avoid round-tripping multi-megabyte bodies through
Vercel.
Both services share the same `JWT_SIGNING_KEY` — one access token,
one identity, two backends. The Django service additionally accepts a
shared `MODAL_SERVICE_TOKEN` so its server-side calls bypass per-user
rate limits.
## Authentication
| Header | Used by |
|---|---|
| `Authorization: Bearer <access JWT>` | End-user calls to Django + Modal |
| `Authorization: Bearer <service token>` | Server-to-server (`/api/metrics/`, Modal `/metrics`) |
Access tokens live 7 days, refresh tokens 14 days. Tokens come from
`POST /users/login/` (Django) and are accepted as-is by Modal.
## Rate limiting
* Django: DRF `AnonRateThrottle` 60/min, `UserRateThrottle` 240/min.
* Modal: per-user sliding window — 45/min general (text + recs), 15/min
media (speech + facial). Service-token callers bypass both.
## Conventions
* Success bodies are either a typed payload or `{"message": "..."}`.
* Error bodies are always `{"error": "<human readable>"}` matching the
4xx / 5xx status.
* Timestamps are ISO 8601 UTC; IDs are Mongo ObjectIds (24-hex).
contact:
name: Son Nguyen
email: hoangson091104@gmail.com
url: https://moodify-app.vercel.app/
license:
name: MIT
url: https://opensource.org/licenses/MIT
termsOfService: https://moodify-app.vercel.app/terms-of-service
x-logo:
url: https://raw.githubusercontent.com/hoangsonww/Moodify-Emotion-Music-App/master/frontend/web/public/logo512.png
altText: Moodify
externalDocs:
description: Source code + READMEs
url: https://github.com/hoangsonww/Moodify-Emotion-Music-App
servers:
- url: https://moodify-emotion-music-app-backend.vercel.app
description: Django backend — production (Vercel)
- url: http://127.0.0.1:8000
description: Django backend — local
- url: https://hoangsonww--moodify-inference-inferenceservice-web.modal.run
description: Modal inference service — production
- url: http://127.0.0.1:8001
description: Modal inference service — local (FastAPI dev runner)
tags:
- name: Authentication
description: |
Create accounts, sign in, refresh tokens, validate a session. All
authenticated endpoints expect `Authorization: Bearer <access>`.
- name: Passkeys
description: |
WebAuthn / FIDO2 passwordless sign-in. Users enroll many passkeys
(phone, laptop, hardware key) and manage them in-app. Each ceremony is
two calls — `begin` issues a single-use challenge + opaque `flowId`,
`complete` returns the signed credential. A verified login assertion
mints the same `(access, refresh)` pair as `/users/login/`.
- name: Password Reset
description: |
Two-step API-driven reset (verify identity → set new password). No
email magic link in this build.
- name: Profile
description: |
Read, update, and delete the signed-in user's profile. Deleting the
profile cascades to mood / listening / saved-recommendation history.
- name: Mood History
description: |
Append-only log of detected moods. Powers the recurring-mood blend
in the personalised recommender.
- name: Listening History
description: |
Tracks the user has opened. Used to dim already-heard tracks and
bias the recommender against duplicates.
- name: Saved Recommendations
description: |
Pinned tracks. Two URL shapes (split + combined multi-method) exist
for backwards compatibility; they're equivalent.
- name: Emotion Inference
description: |
Text → emotion. Django proxies this to Modal; the Modal endpoint is
also reachable directly with the same JWT.
- name: Music Recommendations
description: |
Mood-matched Deezer tracks with optional history blend.
- name: Media Inference (Modal only)
description: |
Speech + facial emotion. Multipart uploads (≤12 MB). Browsers / mobile
clients call Modal directly with the user's own JWT.
- name: System
description: |
Liveness + SRE metrics. Metrics endpoints require the shared service
token, not end-user JWTs.
security:
- bearerAuth: []
paths:
# ===========================================================================
# Django — Authentication
# ===========================================================================
/users/register/:
post:
tags: [Authentication]
summary: Register a new account
description: |
Creates a `User` document + empty `UserProfile`. Username and email
are unique; password is stored as a PBKDF2 hash.
security: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/RegisterBody'
responses:
'201':
$ref: '#/components/responses/Created'
'400':
$ref: '#/components/responses/BadRequest'
'409':
description: Username already taken.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
example: { error: "Username already taken." }
/users/login/:
post:
tags: [Authentication]
summary: Sign in (issue access + refresh tokens)
description: |
Verifies the password against the PBKDF2 hash and returns a fresh
`(access, refresh)` pair. The same signing key is shared with
Modal, so this access token works against both services.
security: []
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/LoginBody' }
responses:
'200':
description: Authenticated.
content:
application/json:
schema: { $ref: '#/components/schemas/TokenPair' }
'401':
$ref: '#/components/responses/Unauthorized'
/users/token/refresh/:
post:
tags: [Authentication]
summary: Refresh an expired access token
description: |
Trade a valid refresh token for a new `(access, refresh)` pair.
Rotation is intentional — overwrite both stored tokens with the
new pair.
security: []
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/RefreshBody' }
responses:
'200':
description: Refreshed.
content:
application/json:
schema: { $ref: '#/components/schemas/TokenPair' }
'401':
$ref: '#/components/responses/Unauthorized'
/users/validate_token/:
get:
tags: [Authentication]
summary: Validate an access token
description: Cheap probe — 200 only if the bearer token decodes to a real, active user.
responses:
'200':
description: Token is valid.
content:
application/json:
schema:
type: object
properties:
message: { type: string, example: "Token is valid." }
username: { type: string, example: "moodify_user" }
'401':
$ref: '#/components/responses/Unauthorized'
# ===========================================================================
# Django — Passkeys (WebAuthn / FIDO2)
# ===========================================================================
/users/passkeys/register/begin/:
post:
tags: [Passkeys]
summary: Begin passkey registration
description: |
Step 1 of enrolling a passkey for the signed-in user. Returns the
`PublicKeyCredentialCreationOptions` to pass to
`navigator.credentials.create()`, plus an opaque `flowId`. The user's
existing passkeys are listed in `excludeCredentials` so the same
authenticator can't be enrolled twice.
responses:
'200':
description: Creation options + flowId.
content:
application/json:
schema: { $ref: '#/components/schemas/PasskeyBeginResponse' }
'401': { $ref: '#/components/responses/Unauthorized' }
/users/passkeys/register/complete/:
post:
tags: [Passkeys]
summary: Complete passkey registration
description: |
Step 2 of enrolling a passkey. Verifies the attestation against the
challenge from step 1 and stores the credential's public key. An
optional `name` labels the passkey in the management UI.
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/PasskeyRegisterCompleteBody' }
responses:
'201':
description: Passkey registered.
content:
application/json:
schema: { $ref: '#/components/schemas/PasskeyMutationResponse' }
'400':
description: Verification failed or the registration session expired.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
example: { error: "Could not verify the passkey." }
'401': { $ref: '#/components/responses/Unauthorized' }
'409':
description: Authenticator already registered.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
example: { error: "This passkey is already registered." }
/users/passkeys/login/begin/:
post:
tags: [Passkeys]
summary: Begin passkey login
description: |
Step 1 of signing in with a passkey. Returns
`PublicKeyCredentialRequestOptions` for `navigator.credentials.get()`
plus a `flowId`. Pass a `username` to scope the prompt to one account,
or omit it for a usernameless (discoverable-credential) prompt. The
response is identical whether or not the username exists — it never
discloses account existence.
security: []
requestBody:
required: false
content:
application/json:
schema: { $ref: '#/components/schemas/PasskeyLoginBeginBody' }
responses:
'200':
description: Request options + flowId.
content:
application/json:
schema: { $ref: '#/components/schemas/PasskeyBeginResponse' }
/users/passkeys/login/complete/:
post:
tags: [Passkeys]
summary: Complete passkey login
description: |
Step 2 of signing in with a passkey. Verifies the assertion against the
stored public key and challenge, advances the signature counter (a
non-increasing counter — a possible cloned authenticator — is
rejected), then returns the same `(access, refresh)` JWT pair as
`/users/login/`.
security: []
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/PasskeyLoginCompleteBody' }
responses:
'200':
description: Authenticated — returns access + refresh JWTs plus the username.
content:
application/json:
schema: { $ref: '#/components/schemas/PasskeyTokenPair' }
'400':
description: Malformed request or the login session expired.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
example: { error: "Login session expired. Please try again." }
'401':
description: Assertion could not be verified.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
example: { error: "Could not verify the passkey." }
/users/passkeys/:
get:
tags: [Passkeys]
summary: List the signed-in user's passkeys
description: Returns every passkey on the account, newest first. No secret material is included.
responses:
'200':
description: The user's passkeys.
content:
application/json:
schema: { $ref: '#/components/schemas/PasskeyList' }
'401': { $ref: '#/components/responses/Unauthorized' }
/users/passkeys/{passkey_id}/:
parameters:
- $ref: '#/components/parameters/PasskeyId'
patch:
tags: [Passkeys]
summary: Rename a passkey
description: Updates the friendly label of one of the caller's passkeys.
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/PasskeyRenameBody' }
responses:
'200':
description: Renamed.
content:
application/json:
schema: { $ref: '#/components/schemas/PasskeyMutationResponse' }
'400': { $ref: '#/components/responses/BadRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'404':
description: No such passkey for this user.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
example: { error: "Passkey not found." }
delete:
tags: [Passkeys]
summary: Delete a passkey
description: |
Permanently removes one of the caller's passkeys. The user can still
sign in with their password (and any remaining passkeys).
responses:
'200':
description: Deleted.
content:
application/json:
schema: { $ref: '#/components/schemas/Message' }
example: { message: "Passkey removed." }
'401': { $ref: '#/components/responses/Unauthorized' }
'404':
description: No such passkey for this user.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
example: { error: "Passkey not found." }
# ===========================================================================
# Django — Password reset
# ===========================================================================
/users/verify-username-email/:
post:
tags: [Password Reset]
summary: Step 1 — verify a username/email pair
description: |
Returns 200 if the pair matches an existing account, 404 otherwise.
Same 404 for "wrong username" and "wrong email" — does not disclose
which.
security: []
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/VerifyBody' }
responses:
'200':
description: Pair verified.
content:
application/json:
schema: { $ref: '#/components/schemas/Message' }
example: { message: "Username and email combination verified." }
'400': { $ref: '#/components/responses/BadRequest' }
'404': { $ref: '#/components/responses/NotFoundUser' }
/users/reset-password/:
post:
tags: [Password Reset]
summary: Step 2 — set a new password
description: |
Sets the account password (PBKDF2 hash). Old JWTs become unverifiable
because the signing inputs change — clients must re-login.
security: []
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/ResetBody' }
responses:
'200':
description: Password reset.
content:
application/json:
schema: { $ref: '#/components/schemas/Message' }
example: { message: "Password reset successfully." }
'400': { $ref: '#/components/responses/BadRequest' }
'404': { $ref: '#/components/responses/NotFoundUser' }
# ===========================================================================
# Django — Profile
# ===========================================================================
/users/user/profile/:
get:
tags: [Profile]
summary: Get the signed-in user's profile
description: |
Canonical "who am I" call — clients hit this on app boot to hydrate
UI state (mood history, listening history, saved recommendations).
responses:
'200':
description: Profile.
content:
application/json:
schema: { $ref: '#/components/schemas/Profile' }
'401': { $ref: '#/components/responses/Unauthorized' }
'404':
description: Profile missing.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
example: { error: "User profile not found." }
/users/user/profile/update/:
put:
tags: [Profile]
summary: Update mutable profile fields (PATCH-style)
description: |
Missing fields are left untouched. Renaming the username returns a
fresh `(access, refresh)` pair in the body so the client can swap
tokens without forcing a re-login.
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/ProfileUpdateBody' }
responses:
'200':
description: Profile updated.
content:
application/json:
schema: { $ref: '#/components/schemas/ProfileUpdateResponse' }
'400': { $ref: '#/components/responses/BadRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'404':
description: Profile missing.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
example: { error: "User profile not found." }
'409':
description: Username taken.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
example: { error: "That username is already taken." }
/users/user/profile/delete/:
delete:
tags: [Profile]
summary: Permanently delete the signed-in account
description: |
Hard-deletes `User` + `UserProfile`. Irreversible — there is no
soft-delete, recycle bin, or grace period.
responses:
'200':
description: Deleted.
content:
application/json:
schema: { $ref: '#/components/schemas/Message' }
example: { message: "Profile deleted successfully." }
'401': { $ref: '#/components/responses/Unauthorized' }
# ===========================================================================
# Django — Saved recommendations (split URLs)
# ===========================================================================
/users/recommendations/save/{user_id}/:
post:
tags: [Saved Recommendations]
summary: Append tracks to saved recommendations
parameters:
- $ref: '#/components/parameters/UserId'
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/RecommendationsBody' }
responses:
'201':
description: Saved.
content:
application/json:
schema: { $ref: '#/components/schemas/Message' }
example: { message: "Recommendations saved successfully." }
'400': { $ref: '#/components/responses/BadRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'404': { $ref: '#/components/responses/NotFoundUser' }
/users/recommendations/get/{user_id}/:
get:
tags: [Saved Recommendations]
summary: List saved recommendations
parameters:
- $ref: '#/components/parameters/UserId'
responses:
'200':
description: Saved tracks.
content:
application/json:
schema: { $ref: '#/components/schemas/RecommendationsBody' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'404': { $ref: '#/components/responses/NotFoundUser' }
/users/recommendations/delete/{user_id}/:
delete:
tags: [Saved Recommendations]
summary: Clear all saved recommendations
parameters:
- $ref: '#/components/parameters/UserId'
responses:
'200':
description: Cleared.
content:
application/json:
schema: { $ref: '#/components/schemas/Message' }
example: { message: "All recommendations deleted." }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'404': { $ref: '#/components/responses/NotFoundUser' }
# ===========================================================================
# Django — Saved recommendations (combined multi-method URL)
# ===========================================================================
/users/recommendations/{user_id}/:
parameters:
- $ref: '#/components/parameters/UserId'
get:
tags: [Saved Recommendations]
summary: List saved recommendations (combined)
responses:
'200':
description: Saved tracks.
content:
application/json:
schema: { $ref: '#/components/schemas/RecommendationsBody' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'404': { $ref: '#/components/responses/NotFoundUser' }
post:
tags: [Saved Recommendations]
summary: Append tracks (combined)
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/RecommendationsBody' }
responses:
'201':
description: Saved.
content:
application/json:
schema: { $ref: '#/components/schemas/Message' }
example: { message: "Recommendations saved successfully." }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'404': { $ref: '#/components/responses/NotFoundUser' }
delete:
tags: [Saved Recommendations]
summary: Clear all saved recommendations (combined)
responses:
'200':
description: Cleared.
content:
application/json:
schema: { $ref: '#/components/schemas/Message' }
example: { message: "All recommendations deleted." }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'404': { $ref: '#/components/responses/NotFoundUser' }
# ===========================================================================
# Django — Mood history
# ===========================================================================
/users/mood_history/{user_id}/:
parameters:
- $ref: '#/components/parameters/UserId'
get:
tags: [Mood History]
summary: List the user's mood history
responses:
'200':
description: Mood history.
content:
application/json:
schema:
type: object
properties:
mood_history:
type: array
items: { type: string }
example: ["joy", "sadness", "calm", "anger"]
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'404': { $ref: '#/components/responses/NotFoundUser' }
post:
tags: [Mood History]
summary: Append a mood to history
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/MoodEntry' }
responses:
'201':
description: Appended.
content:
application/json:
schema: { $ref: '#/components/schemas/Message' }
example: { message: "Mood history updated." }
'400': { $ref: '#/components/responses/BadRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'404': { $ref: '#/components/responses/NotFoundUser' }
delete:
tags: [Mood History]
summary: Remove the first occurrence of a mood
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/MoodEntry' }
responses:
'200':
description: Removed.
content:
application/json:
schema: { $ref: '#/components/schemas/Message' }
example: { message: "Mood deleted." }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'404':
description: Mood (or user) not found.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
example: { error: "Mood not found in history." }
# ===========================================================================
# Django — Listening history
# ===========================================================================
/users/listening_history/{user_id}/:
parameters:
- $ref: '#/components/parameters/UserId'
get:
tags: [Listening History]
summary: List the user's listening history
responses:
'200':
description: Listening history.
content:
application/json:
schema:
type: object
properties:
listening_history:
type: array
items: { $ref: '#/components/schemas/Track' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'404': { $ref: '#/components/responses/NotFoundUser' }
post:
tags: [Listening History]
summary: Append a track to listening history
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/TrackEntry' }
responses:
'201':
description: Appended.
content:
application/json:
schema: { $ref: '#/components/schemas/Message' }
example: { message: "Listening history updated." }
'400': { $ref: '#/components/responses/BadRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'404': { $ref: '#/components/responses/NotFoundUser' }
delete:
tags: [Listening History]
summary: Remove a single track from listening history
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/TrackEntry' }
responses:
'200':
description: Removed.
content:
application/json:
schema: { $ref: '#/components/schemas/Message' }
example: { message: "Track deleted." }
'401': { $ref: '#/components/responses/Unauthorized' }
'403': { $ref: '#/components/responses/Forbidden' }
'404':
description: Track (or user) not found.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
example: { error: "Track not found in history." }
# ===========================================================================
# Django — Inference proxies + system
# ===========================================================================
/api/health/:
get:
tags: [System]
summary: Liveness probe (Django)
description: Cheapest possible probe — doesn't touch Mongo or Modal.
security: []
responses:
'200':
description: Alive.
content:
application/json:
schema:
type: object
properties:
status: { type: string, example: "ok" }
/api/text_emotion/:
post:
tags: [Emotion Inference]
summary: Detect emotion from text (Django proxy)
description: |
Proxies to Modal's `/text_emotion`. No auth required — Django uses
the shared service token to call Modal on behalf of anonymous
callers. DRF `AnonRateThrottle` 60/min applies. Text is capped at
5000 chars.
security: []
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/TextEmotionRequest' }
responses:
'200':
description: Predicted emotion + recommendations.
content:
application/json:
schema: { $ref: '#/components/schemas/EmotionResponse' }
'400': { $ref: '#/components/responses/BadRequest' }
'502': { $ref: '#/components/responses/BadGateway' }
/api/music_recommendation/:
post:
tags: [Music Recommendations]
summary: Mood → Deezer recommendations (Django proxy)
description: |
Returns a list of Deezer tracks matched to the emotion. When
`history` is provided, the recommender blends in tracks for the
recurring mood via a recency-weighted affinity model + first-order
Markov transitions.
security: []
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/MusicRecommendationRequest' }
responses:
'200':
description: Mood + recommendations.
content:
application/json:
schema: { $ref: '#/components/schemas/EmotionResponse' }
'400': { $ref: '#/components/responses/BadRequest' }
'502': { $ref: '#/components/responses/BadGateway' }
/api/metrics/:
get:
tags: [System]
summary: SRE metrics — Django (admin only)
description: |
Aggregated request count, error rate, latency p50/p95/p99.
**Service token only** (`Authorization: Bearer <ADMIN_METRICS_TOKEN>`).
Falls back to `MODAL_SERVICE_TOKEN` if the dedicated admin token
isn't set.
parameters:
- in: query
name: window
schema:
type: string
enum: [5m, 15m, 1h, 6h, 24h, 7d, 30d]
default: 1h
- in: query
name: endpoint
schema: { type: string }
required: false
description: Optional endpoint filter (e.g. `/users/login/`).
responses:
'200':
description: Aggregated + live metrics.
content:
application/json:
schema: { $ref: '#/components/schemas/MetricsResponse' }
'401':
description: Missing or non-admin Authorization header.
content:
application/json:
schema: { $ref: '#/components/schemas/Error' }
example: { error: "Service-token authentication required." }
/api/feedback/:
post:
tags: [Emotion Inference]
summary: Submit mood / track feedback (RL surfaces)
description: |
Unified intake for both reinforcement-learning surfaces. The
request body's `kind` discriminator selects the payload shape.
* **`kind: "mood"`** — record an agreement or correction on a
previously detected emotion. Persisted to the `mood_feedback`
time-series collection; corrections also bump the per-user
mood-calibration map on `UserProfile.mood_calibration`. Once
a `(predicted → actual)` correction has been logged ≥ 3
times, `/api/text_emotion/` rewrites that user's predicted
label automatically.
* **`kind: "track"`** — record a 👍 / 👎 / open-in-Deezer
event for a specific track. Persisted to the `track_feedback`
time-series collection. When the optional `track` object is
supplied, the bandit posterior on
`UserProfile.taste_profile` is updated via the Thompson
Sampling update step.
Requires a user JWT (`Authorization: Bearer <access>`). Returns
**202** on success because the downstream effects (calibration
map, bandit posterior) settle out-of-band.
requestBody:
required: true
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/MoodFeedbackRequest'
- $ref: '#/components/schemas/TrackFeedbackRequest'
discriminator:
propertyName: kind
mapping:
mood: '#/components/schemas/MoodFeedbackRequest'
track: '#/components/schemas/TrackFeedbackRequest'
responses:
'202':
description: Feedback accepted.
content:
application/json:
schema: { $ref: '#/components/schemas/Message' }
example: { message: "Feedback recorded." }
'400': { $ref: '#/components/responses/BadRequest' }
'401': { $ref: '#/components/responses/Unauthorized' }
# ===========================================================================
# Modal — direct endpoints
# ===========================================================================
/health:
get:
tags: [System]
summary: Liveness + cache + rate-limit stats (Modal)
description: |
Reports model load status, per-cache hit/miss stats, and per-tier
rate-limit stats. Status flips to `degraded` if any sub-system
failed to report. Never 500s (defensive `_safe_stats` wrapper).
security: []
servers:
- url: https://hoangsonww--moodify-inference-inferenceservice-web.modal.run
responses:
'200':
description: Health snapshot.
content:
application/json:
schema: { $ref: '#/components/schemas/HealthResponse' }
/text_emotion:
post:
tags: [Emotion Inference]
summary: Detect emotion from text (Modal direct)
description: |
End-user JWT required. Falls back to a neutral emotion with
`degraded: true` instead of 500 when a model is unavailable.
servers:
- url: https://hoangsonww--moodify-inference-inferenceservice-web.modal.run
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/TextEmotionRequest' }
responses:
'200':
description: Predicted emotion + recommendations.
headers:
X-RateLimit-Limit:
schema: { type: integer }
X-RateLimit-Remaining:
schema: { type: integer }
X-RateLimit-Window:
schema: { type: integer }
content:
application/json:
schema: { $ref: '#/components/schemas/EmotionResponse' }
'401': { $ref: '#/components/responses/Unauthorized' }
'422': { $ref: '#/components/responses/Unprocessable' }
'429': { $ref: '#/components/responses/RateLimited' }
/music_recommendation:
post:
tags: [Music Recommendations]
summary: Mood → Deezer recommendations (Modal direct)
description: |
Adds an optional `genre` keyword over the Django proxy schema
(e.g. `lofi`, `hip-hop`, `jazz`). End-user JWT required.
servers:
- url: https://hoangsonww--moodify-inference-inferenceservice-web.modal.run
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/MusicRecommendationRequest' }
responses:
'200':
description: Mood + recommendations.
content:
application/json:
schema: { $ref: '#/components/schemas/EmotionResponse' }
'401': { $ref: '#/components/responses/Unauthorized' }
'422': { $ref: '#/components/responses/Unprocessable' }
'429': { $ref: '#/components/responses/RateLimited' }
/speech_emotion:
post:
tags: [Media Inference (Modal only)]
summary: Detect emotion from a voice clip
description: |
Multipart upload, ≤12 MB. Identical uploads (same sha256) within
the media-cache TTL skip the model entirely. Falls back to neutral
+ `degraded: true` on a model error.
servers:
- url: https://hoangsonww--moodify-inference-inferenceservice-web.modal.run
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object