To keep the frontend and backend synced, use the following mapping:
| Feature | Frontend Call (app.js) | API Endpoint (app.py) | Logic Provider (ai_service.py) |
|---|---|---|---|
| Book Vibe | POST /api/v1/generate-note | handle_generate_note() | generate_book_note() |
Method: POST
URL: /api/v1/generate-note
Description: Generates an AI-powered "bookseller note" based on the book's vibe, mood, and metadata.
Headers:
{
"Content-Type": "application/json"
}Body:
{
"title": "The Night Circus",
"author": "Erin Morgenstern",
"mood": "mysterious, magical, slow-burn romance"
}Success (200 OK):
{
"status": "success",
"note": "A dreamlike duel unfolds in a wandering circus of shadows and light. Perfect for readers who crave atmospheric magic and quiet intensity."
}Error (400 Bad Request):
{
"status": "error",
"message": "Missing required fields: title or mood"
}- Frontend sends a POST request from app.js to /api/v1/generate-note.
- The Flask backend (app.py) receives the request via handle_generate_note().
- Input data (title, author, mood) is validated.
- The request is passed to generate_book_note() in ai_service.py.
- The AI model generates a contextual "bookseller note".
- The backend returns the generated note as a JSON response.
- Frontend displays the note in the book popup UI.