Payment to Chat Flow
End-to-end trace of purchasing a book: Stripe PaymentIntent, webhook, purchases upsert, library grant, and session creation.
End-to-End Flow: Payment to Library to Chat
This flow traces the dependency chain from purchasing a book to being able to chat with its characters.
Dependency Chain
Purchase (Stripe PaymentIntent)
→ Webhook (Stripe → Frontend)
→ purchases row (Supabase, upsert on user_id,book_id)
→ user_library row (Supabase, upsert on user_id,book_id)
→ chat session creation allowed
→ message streaming (Frontend → Backend → LLM)Every link gates the next. Without a successful Stripe charge, there is no purchase row. Without a purchase row, there is no library entry. Without a library entry, the session creation endpoint rejects the request. Without a session, chat messages cannot be sent.
Payments: The Stripe webhook is idempotent via upsert conflict on user_id,book_id, so duplicate webhook deliveries do not create duplicate library entries. Stripe retries failed webhooks up to three times before giving up. If all retries fail, an admin can manually insert the purchases and user_library rows using the Stripe dashboard session ID.
Chat Message Flow
End-to-end trace of a single chat message: browser to SSE stream, including caching, locking, rewrite, hybrid retrieval, rerank, and persist.
Error Propagation
Component failure matrix and error event flows: how each service failure degrades the user experience and chat-specific error codes.