Flow Document #
This document visualizes the major user journeys and internal data processes within the application. The diagrams use Mermaid.js to illustrate routing decisions, authentication states, and the multi-layered LLM failover system.
1. Main Navigation Flow #
The primary user journey for a public visitor navigating the portfolio. The persistent navigation bar (defined in base.html) and global routing (app.py) control access to different content areas.
Step-by-Step Breakdown:
- Entry Point: User hits the
/route.app.pyrenderstemplates/index.html. - Persistent UI: The navigation bar and floating chat widget (controlled by
chatbot.js) persist across views. - Exploration: The user browses static views (
/about,/project,/contact). - Chat Attempt: The user clicks the floating widget.
chatbot.jsverifiesonAuthStateChanged. If null, the UI is blocked with a login prompt.
2. Authentication Flow #
The process by which a user registers, logs in, or resets their password. All authentication is client-side, managed by Firebase Auth and implemented in login.html.
Step-by-Step Breakdown:
- UI Selection: User selects Login, Sign Up, or clicks "Forgot Password?" (controlled via DOM class toggling in
login.html). - Validation: Client-side JS validates inputs (e.g., regex matching for 8+ characters, symbols, and numbers).
- Firebase Auth: Calls the respective Firebase v10 SDK method.
- Firestore Profile: On new registration (Email or Google), a document is created in the
users/{uid}collection with the user's name and email. - State Change: Once authenticated,
onAuthStateChangedfires globally across the app (inbase.htmlandchatbot.js), unlocking protected elements.
3. AI Chatbot Data & Failover Flow #
The core technical pipeline of the application. This flow details how user messages are augmented with live context, routed to appropriate LLMs, and how system knowledge is extracted and saved.
Step-by-Step Breakdown:
- Client Payload & Bearer Token:
chatbot.jsretrieves the active user's Firebase ID token viagetIdToken()(or guest token) and packages it inside theAuthorization: Bearerheader, requesting streaming viaAccept: text/event-stream. - Server-Side Auth & Rate Limiting:
app.pyvalidates the cryptographic JWT against Google public signing keys viaverify_firebase_token()(returning401on failure) and checks the in-memory sliding window rate limiter (max 15 requests/minute per UID/IP, returning429if exceeded). - Concurrent Multi-Threaded Pre-Fetching: A
concurrent.futures.ThreadPoolExecutor(max_workers=3)fetches global knowledge facts, episodic memory summaries, and pre-warmed sports match cache simultaneously, dropping pre-fetch latency from ~750ms sequentially down to 150–200ms. - Intent Routing & Context Synthesis: An intent classifier analyzes the user's inquiry, activating conversational dialogue for exploratory queries while enforcing an immediate, structured direct-answer policy without preambles for technical questions.
- Multi-Key Round-Robin & Inverted Failover: Primary inference routes directly to the Groq multi-key pool for ultra-low TTFT (<250ms) across all user interactions with in-flight sub-50ms key failover. If all Groq keys are exhausted or rate-limited (HTTP 429), the engine seamlessly falls back to Google Gemini multi-key rotation, guaranteeing zero downtime.
- StreamTagFilter & Adaptive 60fps Typewriter: The backend
StreamTagFilterintercepts in-flight control tokens, memory directives, and redundant framing headers before stream chunks are yielded to the network. The client consumestext/event-streamSSE chunks, driving an adaptive 60fps typewriter engine (1–3 chars/frame accelerated to 6–16 chars/frame dynamically) with live markdown synthesis. - Non-Blocking Background Audit: Firestore message logging, trigger updates, and learned memory extraction execute in a background daemon thread (
_bg_executor) with 0ms latency impact on streaming.