How tanuj0071/chatgpt-clone works
Project type and purpose
• This is a full-stack web application built with Python/Flask on the backend and a static HTML/CSS/JavaScript frontend.
• It serves as a ChatGPT-style chat interface that proxies user messages to the OpenRouter API (GPT-3.5-turbo) and returns AI-generated responses in real time.
File structure
• Top-level files:
• main.py – Flask application entry point
• package.json & package-lock.json + node_modules – Frontend build dependencies (Tailwind CSS, any JS libraries)
• tailwind.config.js + static/ – Static assets for styling (CSS) and behavior (JS)
• templates/index.html – HTML template served by Flask
• No database or persistent storage present: the app is stateless beyond the API integration.
• Key external dependency: OpenRouter API.
README for additional insights
• Confirms Flask backend, Tailwind CSS frontend, OpenRouter integration.
• No mention of additional microservices or data stores.
• Ready for deployment on Python-friendly PaaS (Heroku, Vercel, etc.).
Main components and interactions
a. Components
• Web Browser (Client)
• Static Asset Server (serving CSS/JS via Flask’s static route or CDN)
• Flask Web Server
• OpenRouter External API
b. Relationships / Data flow
1. User types a message in the chat UI (index.html + script.js).
2. script.js issues an HTTP POST to Flask endpoint (/api/chat or root).
3. Flask receives request in main.py, packages it, calls OpenRouter API over HTTPS.
4. OpenRouter responds with AI-generated text.
5. Flask forwards that response back to the browser as JSON.
6. script.js updates the DOM to display the chat reply.
c. Architectural patterns/design principles
• Single back-end service (monolithic Flask app)
• Separation of concerns: static frontend assets vs. dynamic API logic
• External API integration as a façade pattern
• Client-server interaction via RESTful HTTP calls (or AJAX/fetch)
d. Technologies and libraries
• Flask (Python) – HTTP server, routing, template rendering
• Jinja2 – template engine for index.html
• Tailwind CSS – utility-first styling
• Vanilla JavaScript (or any small JS lib) – AJAX requests and DOM updates
• OpenRouter API – external AI model service