How eightrocks/chatbot works
Project type and purpose
• This is a lightweight full-stack chatbot application.
• Frontend: Single static page (index.html) served to the user.
• Backend: FastAPI app in chatbot.py exposing HTTP endpoints.
• External systems: Supabase (PostgreSQL-based) for retrieving Reddit data, and OpenAI API for generating responses.
File structure
• Top level:
• chatbot.py – FastAPI app, route definitions, client initializations.
• index.html – simple user interface for chat.
• requirements.txt – Python dependencies (FastAPI, uvicorn, supabase, openai, python-dotenv).
• .gitignore, .cursor/ – ancillary.
Key components
a. Client (Browser)
– Loads index.html.
– Sends user messages via HTTP (fetch/XHR) to the backend.
b. FastAPI Server (chatbot.py + uvicorn)
– HTTP REST endpoint(s) (e.g., POST /chat).
– Reads environment variables (.env) for credentials.
– Orchestrates calls to Supabase and OpenAI.
c. Supabase
– Houses Reddit posts or other data.
– FastAPI uses the Supabase client library to query.
d. OpenAI API
– Receives prompts (combining user input + context) from FastAPI.
– Returns generated text.
e. (Optional) Environment/config layer
– .env for SUPABASE_URL/KEY and OPENAI_API_KEY.
Relationships and interactions (data flow)
1. User opens index.html in browser.
2. User submits a message → Browser sends HTTP POST to FastAPI (/chat).
3. FastAPI endpoint handler:
a. Reads message.
b. Queries Supabase for relevant Reddit context.
c. Constructs prompt and calls OpenAI API.
d. Receives AI response.
e. Returns JSON response to browser.
4. Browser displays the chatbot’s reply.
Architectural patterns and design principles
• Separation of concerns: UI, API layer, data store, AI service.
• Single process monolith (no microservices), but clear logical layers.
• Environment-based configuration for secrets.
Final advice
• Don’t over-fragment: only separate components that have distinct responsibilities.