Sudapedia Instance
Sudapedia AI Chatbot — Instance (Development) This is the development instance of the Sudapedia AI Chatbot. The main production project remains untouched at its live domain. All te...
Technical Architecture & Engineering Overview
Detailed system design and core implementation
"The core architecture follows a micro‑service style where the FastAPI application acts as the sole API gateway, routing requests to the Gemini LLM for natural language understanding and to MySQL for structured data retrieval. The API is stateless, with JWT‑style bearer tokens issued on POST /auth/login and validated on each protected route. Conversation state is maintained client‑side via a session_id stored in sessionStorage, and the backend returns a thread_id that the client re‑sends to keep the context consistent across requests.
Data ingestion is handled by the extract_all.py script, which parses PDFs into structured JSON and populates the two MySQL databases (DB1 for product metadata and DB2 for SudaHub data). The Gemini client is lazily instantiated to avoid cold‑start latency on Cloud Run, and a retry wrapper with exponential backoff ensures resilience against transient LLM failures.
Security guardrails include CORS permissive for development but can be tightened in production, Bearer token authentication, and environment‑based configuration to keep API keys and database credentials out of source control. All chat logs are persisted in the chatbot_chat_logs table, enabling auditability and future analytics.
The build topology is straightforward: a Dockerfile builds a lightweight image, a Procfile ensures Cloud Run listens on 0.0.0.0:$PORT, and the requirements.txt pins dependencies such as fastapi, uvicorn, google-generativeai, and mysql-connector-python. Continuous deployment can be achieved via Cloud Build triggers that push to Cloud Run on each commit to the main branch.
Overall, the system demonstrates a clean separation of concerns: the API layer, the LLM layer, the data layer, and the frontend UI, all orchestrated through simple REST endpoints and a minimal configuration footprint."
System Diagrams & Flow Visualizations
Interactive Mermaid architecture & execution flows
Core System Features
Key capabilities & architectural features
Real‑time conversational AI powered by Gemini.
Real‑time conversational AI powered by Gemini.
Bearer‑token authentication for secure access.
Bearer‑token authentication for secure access.
Session thread persistence across requests.n
Session thread persistence across requests.n
PDF ingestion pipeline to populate product metadata.
PDF ingestion pipeline to populate product metadata.
Dual‑database support (DB1 for metadata, DB2 for SudaHub).
Dual‑database support (DB1 for metadata, DB2 for SudaHub).
Chat logs stored for audit and analytics.
Chat logs stored for audit and analytics.
Dockerized application for consistent deployment.
Dockerized application for consistent deployment.
Cloud Run integration with automatic scaling.
Cloud Run integration with automatic scaling.
CORS support for mobile and web clients.
CORS support for mobile and web clients.
Comprehensive API documentation and Flutter guide.
Comprehensive API documentation and Flutter guide.
Retry logic for LLM calls to improve reliability.
Retry logic for LLM calls to improve reliability.
Thread‑aware chat UI with retry and error handling.
Thread‑aware chat UI with retry and error handling.
Environment‑based secret management.
Environment‑based secret management.
Endpoints for session history retrieval and deletion.
Endpoints for session history retrieval and deletion.
Lightweight frontend chat UI in plain HTML/JS.
Lightweight frontend chat UI in plain HTML/JS.
Engineering Challenges & Solutions
Problem statements & resolution strategies
Balancing cold‑start latency with Gemini client initialization.
Balancing cold‑start latency with Gemini client initialization.
Ensuring thread continuity across stateless API calls.
Ensuring thread continuity across stateless API calls.
Managing secrets securely in Cloud Run without exposing them.
Managing secrets securely in Cloud Run without exposing them.
Implementing robust retry logic without causing excessive API usage.
Implementing robust retry logic without causing excessive API usage.
Designing a simple yet extensible PDF ingestion pipeline.
Designing a simple yet extensible PDF ingestion pipeline.
Handling large SQL queries generated by Gemini without blocking the event loop.
Handling large SQL queries generated by Gemini without blocking the event loop.
Maintaining consistent CORS policies across development and production.
Maintaining consistent CORS policies across development and production.
API Reference & Endpoints
REST API surface & route documentation
| METHOD | ENDPOINT PATH | DESCRIPTION | COPY |
|---|---|---|---|
| GET | / | Endpoint defined in inspect_employee_chat_pairs.py | |
| POST | /auth/login | Endpoint defined in inspect_employee_chat_pairs.py | |
| GET | /auth/me | Endpoint defined in inspect_employee_chat_pairs.py | |
| POST | /auth/logout | Endpoint defined in inspect_employee_chat_pairs.py | |
| POST | /chat | Endpoint defined in inspect_employee_chat_pairs.py | |
| GET | /session/{employee_id} | Endpoint defined in inspect_employee_chat_pairs.py | |
| DELETE | /session/{employee_id} | Endpoint defined in inspect_employee_chat_pairs.py | |
| DELETE | /chat/{chat_id} | Endpoint defined in inspect_employee_chat_pairs.py | |
| GET | /health | Endpoint defined in main.py | |
| GET | /session/me/current-thread | Endpoint defined in main.py |
Key Code Modules & Architecture
Core file entrypoints and service responsibilities
DocsModule component managing Docs source logic
playwright-testing/testsModule component managing tests source logic
playwright-testing/utilsModule component managing utils source logic
User Journey Pipeline
- 1User Access & Preset Selection: User opens client interface and configures request parameters or task workflow presets.
- 2Client Payload Dispatch: Front-end components (React) serialize input objects and send HTTP/WebSocket requests to `/`.
- 3Middleware & Validation Check: API Gateway evaluates CORS headers, authorization tokens, and input validation schemas.
- 4Service & Inference Execution: Service controllers dispatch request frames to model inference engine (Local Engine) or storage layer.
- 5Response Delivery & State Synchronization: Serialized output payload is returned to the client and rendered in the visual workspace.
Execution Code Flow
- 1Client or caller initiates request to application entrypoint
- 2Backend router validates request parameters and applies middleware
- 3Application serializes JSON/audio/data response back to client
System FAQ & Technical Specifications
Frequently asked questions and core architecture details
Q: What technologies are used in Sudapedia Instance?
Sudapedia Instance is engineered using modern full-stack frameworks.
Q: What core engineering problem does Sudapedia Instance solve?
Sudapedia AI Chatbot — Instance (Development) This is the development instance of the Sudapedia AI Chatbot. The main production project remains untouched at its live domain. All te...
Q: How is 'Balancing cold‑start latency with Gemini client initialization.' resolved in Sudapedia Instance?
Resolved through specialized system architecture and resilient state handling.
Related Systems & Case Studies
Explore similar technical architectures and projects