S
API Service2026CompletedFeatured Project

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...

RoleSole Developer
Classificationhigh
Client / ContextOpen Source Project
Development TimelineCompleted

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

Architectural Visualizer · System Architecture

Core System Features

Key capabilities & architectural features

FEATURE 01

Real‑time conversational AI powered by Gemini.

Real‑time conversational AI powered by Gemini.

FEATURE 02

Bearer‑token authentication for secure access.

Bearer‑token authentication for secure access.

FEATURE 03

Session thread persistence across requests.n

Session thread persistence across requests.n

FEATURE 04

PDF ingestion pipeline to populate product metadata.

PDF ingestion pipeline to populate product metadata.

FEATURE 05

Dual‑database support (DB1 for metadata, DB2 for SudaHub).

Dual‑database support (DB1 for metadata, DB2 for SudaHub).

FEATURE 06

Chat logs stored for audit and analytics.

Chat logs stored for audit and analytics.

FEATURE 07

Dockerized application for consistent deployment.

Dockerized application for consistent deployment.

FEATURE 08

Cloud Run integration with automatic scaling.

Cloud Run integration with automatic scaling.

FEATURE 09

CORS support for mobile and web clients.

CORS support for mobile and web clients.

FEATURE 010

Comprehensive API documentation and Flutter guide.

Comprehensive API documentation and Flutter guide.

FEATURE 011

Retry logic for LLM calls to improve reliability.

Retry logic for LLM calls to improve reliability.

FEATURE 012

Thread‑aware chat UI with retry and error handling.

Thread‑aware chat UI with retry and error handling.

FEATURE 013

Environment‑based secret management.

Environment‑based secret management.

FEATURE 014

Endpoints for session history retrieval and deletion.

Endpoints for session history retrieval and deletion.

FEATURE 015

Lightweight frontend chat UI in plain HTML/JS.

Lightweight frontend chat UI in plain HTML/JS.

Engineering Challenges & Solutions

Problem statements & resolution strategies

Challenge #1

Balancing cold‑start latency with Gemini client initialization.

Balancing cold‑start latency with Gemini client initialization.

Challenge #2

Ensuring thread continuity across stateless API calls.

Ensuring thread continuity across stateless API calls.

Challenge #3

Managing secrets securely in Cloud Run without exposing them.

Managing secrets securely in Cloud Run without exposing them.

Challenge #4

Implementing robust retry logic without causing excessive API usage.

Implementing robust retry logic without causing excessive API usage.

Challenge #5

Designing a simple yet extensible PDF ingestion pipeline.

Designing a simple yet extensible PDF ingestion pipeline.

Challenge #6

Handling large SQL queries generated by Gemini without blocking the event loop.

Handling large SQL queries generated by Gemini without blocking the event loop.

Challenge #7

Maintaining consistent CORS policies across development and production.

Maintaining consistent CORS policies across development and production.

API Reference & Endpoints

REST API surface & route documentation

METHODENDPOINT PATHDESCRIPTIONCOPY
GET/Endpoint defined in inspect_employee_chat_pairs.py
POST/auth/loginEndpoint defined in inspect_employee_chat_pairs.py
GET/auth/meEndpoint defined in inspect_employee_chat_pairs.py
POST/auth/logoutEndpoint defined in inspect_employee_chat_pairs.py
POST/chatEndpoint 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/healthEndpoint defined in main.py
GET/session/me/current-threadEndpoint defined in main.py

Key Code Modules & Architecture

Core file entrypoints and service responsibilities

DocsMODULE 01
Docs

Module component managing Docs source logic

TestsMODULE 02
playwright-testing/tests

Module component managing tests source logic

UtilsMODULE 03
playwright-testing/utils

Module component managing utils source logic

User Journey Pipeline

  1. 1User Access & Preset Selection: User opens client interface and configures request parameters or task workflow presets.
  2. 2Client Payload Dispatch: Front-end components (React) serialize input objects and send HTTP/WebSocket requests to `/`.
  3. 3Middleware & Validation Check: API Gateway evaluates CORS headers, authorization tokens, and input validation schemas.
  4. 4Service & Inference Execution: Service controllers dispatch request frames to model inference engine (Local Engine) or storage layer.
  5. 5Response Delivery & State Synchronization: Serialized output payload is returned to the client and rendered in the visual workspace.

Execution Code Flow

  1. 1Client or caller initiates request to application entrypoint
  2. 2Backend router validates request parameters and applies middleware
  3. 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

View All Systems