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:
chatbot.jscaptures the message, user's first name, email (to check if they are the Owner), and previous conversation history. - Live Context Gathering:
chatbot.pydetermines the current time in Fiji and deduces a likely activity (e.g., "At USP"). It also makes a synchronous request to the ESPN API (with a 3-second timeout) for recent sports scores. - Intent Routing: The engine checks the user's message against a list of ~50 keywords (e.g., "ronil", "usp", "tech stack"). If matched, it routes to Gemini; otherwise, it sends the request straight to Groq.
- Failover (L1/L2/L3): If Gemini Key 1 hits a rate limit, the system automatically tries Key 2. If both fail, it falls back to Groq.
- Extraction Engine: Upon receiving the text, client-side JS scans for specific instruction strings like
[LEARN_RONIL: ...]or[SAVE_TRIGGER: ...]. - Persistence: Detected facts are pushed to Firestore (using
setDoc/arrayUnion), then the tags are stripped from the text before it is animated onto the screen.