How vinaykumarvk/create_ekg works
This is a single-service FastAPI web application that serves a secure admin console for managing an OpenAI Vector Store. Admins authenticate, then can:
• Upload local documents (validated and size-limited)
• Optionally browse/import files from a Google Drive folder via service account
• Trigger vector store orchestration (create store if missing, upload files to OpenAI Files API, re-embed/replace stale embeddings)
So the “system” is not a microservice mesh; it’s a hardened admin web app with a few critical integrations: OpenAI APIs and optional Google Drive APIs.
Core service boundary
• api/main.py: FastAPI app, routes, middleware, security headers, request lifecycle
• api/settings.py: Config (env-driven dataclasses, secrets, feature flags like Drive enablement)
• api/security.py: Auth primitives (PBKDF2 password verification, CSRF helpers)
• api/session.py: Session + flash messaging (secure cookie/session)
• api/vector_store.py: OpenAI orchestration layer (vector store creation/lookup, file ingestion, stale removal)
• api/google_drive.py: Google Drive integration (folder listing, downloading file content)
• api/templates/*: Server-rendered UI (Jinja2: login + dashboard)
• api/static/*: Front-end assets (CSS, admin JS)
• api/compat.py: compatibility helpers (likely small glue—don’t over-emphasize unless it’s central)
Infra / packaging / deployment
• Dockerfile, start.sh: container runtime entry + startup
• cloudbuild.yaml: CI/CD build pipeline (Google Cloud Build implied)
• requirements.txt, pyproject.toml: dependency and packaging metadata
What the README adds (runtime behaviors worth diagramming)
The README tells you key runtime concerns to explicitly represent:
Security perimeter
• PBKDF2 password hash verification
• CSRF protection
• Secure session cookies
• Defensive HTTP headers
Document ingestion constraints
• Reject empty uploads
• Max 100MB
• Allowed types list (PDF/TXT/MD/DOCX/CSV/JSON)
OpenAI vector store lifecycle
• Create vector store if needed
• Remove stale embeddings
• Re-ingest updated documents via OpenAI Files API
Google Drive is optional
• Service account file and (optional) impersonated user
• Browser/import from Drive folder inside dashboard
Client / UI
• Admin’s Browser
• Server-rendered pages (Jinja2 templates)
• Static assets (CSS/JS)
Application (FastAPI Service)
Split into internal modules (separating into more components is better here):
• Routing / Controllers (api/main.py)
• AuthN/AuthZ + CSRF (api/security.py)
• Session & flash (api/session.py)
• Vector Store Orchestrator (api/vector_store.py)
• Google Drive Connector (api/google_drive.py, optional)
• Configuration (api/settings.py)
External Systems
• OpenAI API
• Files API
• Vector Store API (or “Vector Store endpoint”)
• Google Drive API (optional)
Flow 1: Login
Browser → FastAPI /login
FastAPI → Security: verify PBKDF2 hash
FastAPI → Session: set secure session cookie
FastAPI → Browser: redirect to dashboard
Flow 2: Local upload → ingestion
Browser (multipart upload) → FastAPI /upload
FastAPI → Document Validation (size/type/empty)
FastAPI → Vector Store Orchestrator
Vector Store Orchestrator → OpenAI Files API (upload)
Vector Store Orchestrator → OpenAI Vector Store (attach file / re-embed / delete stale)
Result → FastAPI → Browser (dashboard status / flash message)
Flow 3: Google Drive browse/import (optional branch)
Browser → FastAPI /drive/browse (or similar)
FastAPI → Google Drive Connector → Google Drive API (list)
Browser selects file → FastAPI /drive/import
FastAPI → Google Drive Connector → Google Drive API (download)
Downloaded bytes → Document Validation → Vector Store Orchestrator → OpenAI APIs
Flow 4: Vector store bootstrap
On first use (or startup), Orchestrator:
FastAPI/Orchestrator → OpenAI Vector Store API: create/lookup store (controlled by OPENAI_VECTOR_STORE_ID)
Configuration/secrets as a first-class node
• session secret
• admin username/password hash
• OpenAI key + vector store id
• Google service account + impersonation user