How kalluru498/vertex_ai_chatbot works
Project type and purpose
• This is a full-stack web application (“AI Chat Assistant”) with:
• A single-page application (SPA) frontend built with TypeScript/React (Vite).
• A Python/Flask backend exposing HTTP endpoints.
• Integration with Google Cloud Vertex AI (PaLM/Gemini) for AI chat.
• Containerization via Docker and deployment on Google Cloud Run.
File structure
• Top-level config files:
• Dockerfile, .env.example, requirements.txt, package.json, tsconfig.json
• config.py loads environment variables.
• Backend code:
• app.py: Flask app, HTTP routes for chat.
• ai_service.py: wrapper around Google Vertex AI calls.
• templates/index.html: Flask serves initial HTML (or fallback).
• key.json: GCP service account key.
• Frontend code:
• src/ (Vite/React) – App.tsx, main.tsx, index.css.
• static/css, static/js/chat.js – supplemental styles and vanilla-JS chat logic.
• Build & tooling:
• vite.config.ts, tailwind.config.js, postcss.config.js, eslint.config.js
• Deployment:
• Dockerfile to build container.
• Cloud Run commands in README for pushing to GCR and deploying.
README for additional insights
• Describes clean chat UI, theme support, typing animations.
• Describes using Flask + Google Vertex AI SDK.
• Outlines local dev steps and GCP deployment to Cloud Run.
Main components and their interactions
a. Components
1. Browser SPA (React/Vite)
2. Static assets (CSS, JS)
3. Flask backend (app.py + ai_service.py)
4. Google Cloud Vertex AI service
5. Docker container / Cloud Run host
6. GCP IAM / Service-account for authentication
b. Relationships / data flows
1. User opens SPA in browser → initial HTML/CSS/JS served either by Flask or a static host.
2. SPA renders chat UI, user types message.
3. Frontend sends HTTP POST /chat to Flask (fetch or axios).
4. Flask endpoint receives payload, calls ai_service.py.
5. ai_service.py authenticates (key.json + GOOGLE_APPLICATION_CREDENTIALS) → sends request to Vertex AI API.
6. Vertex AI returns AI response.
7. Flask wraps result → sends JSON back to frontend.
8. Frontend renders AI reply in chat UI.
c. Architectural patterns / design principles
• 3-tier architecture (Client – Server – External AI Service).
• Separation of concerns: ai_service.py isolates AI calls; config.py handles env vars; templates + static for view layer.
• Infrastructure as Code: Dockerfile defines runtime; Cloud Run for serverless deployment.
d. Key technologies / frameworks
• Frontend: React, Vite, TypeScript, Tailwind CSS
• Backend: Flask, Python 3.7+, gunicorn (implicitly via Cloud Run)
• AI SDK: google-cloud-aiplatform
• Deployment: Docker, Google Cloud Run, GCR