How avyakta-dev/ai-therapist works
What this project is (type + purpose)
This is a 2-tier full-stack web application:
• Frontend (SPA): React + TypeScript + Vite + Tailwind + shadcn/ui. It renders the “AI Therapist” chat UI and calls the backend over HTTP.
• Backend (API service): FastAPI (Python) exposing endpoints (incl. /health) and acting as a proxy/orchestrator to an external LLM provider (Novita AI API, OpenAI-compatible).
• External dependency: Novita AI API for chat completions.
• Deployment: Split deployment: Render for backend, Vercel for frontend. render.yaml captures backend IaC.
• SPA → API calls → FastAPI → External LLM API
• Cross-origin, env var configuration (VITE_API_BASE_URL, NOVITA_API_KEY)
• Clear runtime boundaries: browser vs Vercel vs Render vs Novita
Top-level
• backend/: the FastAPI service.
• frontend/: the React/Vite SPA.
• render.yaml: backend deployment definition (Render).
Backend (key files)
• backend/api.py: likely the FastAPI app entrypoint (Render start command: uvicorn api:app ... confirms this).
• backend/chatbot.py: likely encapsulates the LLM prompt/logic and the Novita/OpenAI-compatible client calls.
• backend/main.py: potentially local runner / alternate entrypoint / composition.
• backend/.env.example: documents required env (NOVITA_API_KEY).
Frontend (key files)
• frontend/src/pages/Chat.tsx, frontend/src/components/ChatInterface.tsx, frontend/src/components/AITherapist.tsx: the “chat feature” UI and likely the API-calling component.
• frontend/.env.example: documents VITE_API_BASE_URL to locate the backend.
• frontend/vercel.json: deployment hints (routing, rewrites, etc.).
• frontend/src/components/ui/*: shadcn/ui component library wrappers—mostly UI, not a separate architectural service.
Vercel-hosted React SPA (Vite build)
• Key feature module: “Chat UI” (Chat page + ChatInterface + AITherapist)
Render-hosted FastAPI service
• FastAPI routes (in api.py) including /health and “chat” endpoint(s)
• Chat orchestration module (chatbot.py) that prepares messages/prompts and calls Novita
Novita AI API (OpenAI-compatible)
• Receives prompts/chat history and returns model responses
Environment Variables
• Frontend: VITE_API_BASE_URL (public config)
• Backend: NOVITA_API_KEY (secret)
Health/ops flow
• Render Health Check → FastAPI /health: liveness monitoring.
• “HTTPS (JSON)”
• “Chat messages / conversation context”
• “API key auth (server-side only)”
• “CORS (browser → API)”
Architectural patterns to highlight (specific to this repo)
1. Backend-for-Frontend (BFF) / Proxy pattern: FastAPI mediates LLM calls so the API key stays server-side.
2. Stateless API (likely): No visible database; each request probably carries enough context (or the frontend carries chat history). If backend stores conversation in-memory, call that out as “ephemeral”.
Split deployment architecture
• Vercel: static SPA hosting + edge routing
• Render: containerized Python web service
External Providers (Novita)
Components inside the lane they run in. This alone prevents common inaccuracies (e.g., drawing React as “running on Vercel” vs “running in the browser”).
Decompose each tier into “as many components as possible” (without inventing things)
For this repo, a good level of decomposition is:
Browser
• Chat Page (src/pages/Chat.tsx)
• Chat components (ChatInterface.tsx, AITherapist.tsx)
• API client layer (where fetch/axios lives—locate in components or a lib file)
FastAPI service
• api.py (routes + app)
• chatbot.py (LLM integration / prompt building / API client)
• “Config” (env vars, settings)
External
• Novita AI API endpoint
• Browser ↔ SPA (Vercel) ↔ FastAPI (Render) ↔ Novita API
• Env vars + health check
• FastAPI app (api.py) → Chat module (chatbot.py) → Novita client
• Request/response DTOs conceptually (“chat request”, “chat response”)