Private ChatGPT-like application with a Cloudflare for backend, Next.js frontend and Beam-self hosted LLM inference.
TheChatBot is a full-stack chat application designed for private/self-controlled deployments.
- Frontend: Next.js 16 + React 19 + Tailwind
- Backend: Cloudflare + LangChain wrapper
- LLM Inference: Beam endpoint (GPU) with model cold-start
TheChatBot/
backend/
core/
models/
routes/
services/
main.py
requirements.txt
beam_deploy/
app.py
frontend/
app/
components/
hooks/
lib/
types/
package.json
plan.md
graph TB
subgraph Frontend
UI[Next.js Chat UI]
end
subgraph Backend
API[FastAPI Routes]
LLM[BeamLLM Wrapper]
MEM[Session/Memory Services]
end
subgraph Infra
BEAM[Beam GPU Endpoint]
APPWRITE[Appwrite DB/Auth]
end
UI --> API
API --> LLM
API --> MEM
LLM --> BEAM
MEM --> APPWRITE
- Chat page with session creation
- Streaming/non-stream backend routes
- Beam model invocation with retries for cold starts
- Beam deploy script with startup model fallback logic
- Sidebar/session UI scaffolding
- Appwrite service integration with graceful fallback behavior
- Python 3.12+
- Node.js 20+
- npm 10+
- Beam CLI (
beam) - Appwrite project (cloud or self-hosted)
- Hugging Face token with model access (if required)
BEAM_ENDPOINT_URL=https://your-beam-endpoint.app.beam.cloud
BEAM_TOKEN=your_beam_token
APPWRITE_ENDPOINT=https://your-appwrite-endpoint/v1
APPWRITE_PROJECT_ID=your_project_id
APPWRITE_API_KEY=your_api_key
APPWRITE_DB_ID=chatbot_db
API_HOST=0.0.0.0
API_PORT=8000
CORS_ORIGINS=http://localhost:3000,http://127.0.0.1:3000
HF_TOKEN=your_hf_tokenNEXT_PUBLIC_API_URL=http://localhost:8000
NEXT_PUBLIC_APPWRITE_ENDPOINT=https://your-appwrite-endpoint/v1
NEXT_PUBLIC_APPWRITE_PROJECT_ID=your_project_idNotes:
- Do not commit
.envfiles. .gitignoreis configured to exclude secret env files.
cd backend
..\.venv\Scripts\python.exe -m pip install -r requirements.txtRun backend:
cd backend
..\.venv\Scripts\python.exe -m uvicorn main:app --reload --port 8000cd frontend
npm install
npm run devFrontend URL:
http://localhost:3000
Backend URL:
http://localhost:8000
Deploy the endpoint from beam_deploy:
cd beam_deploy
beam deploy app.py:generateImportant behavior in beam_deploy/app.py:
- Uses
HF_MODEL_ID(if provided) - Falls back to a valid default model candidate
- Keeps container warm (
keep_warm_seconds=300) to reduce repeated cold starts
After deploy, copy the Beam URL into backend/.env as BEAM_ENDPOINT_URL.
Two workflows are now included under .github/workflows:
ci.yml: Runs on push/PR tomain- Backend: install deps + run API smoke tests
- Frontend:
npm ci,npm run build
cd-beam.yml: Deploys Beam endpoint frombeam_deploy/- Triggers on
pushtomainwhenbeam_deploy/**changes - Can also be run manually via
workflow_dispatch
- Triggers on
Set these repository secrets before running the Beam deploy workflow:
BEAM_TOKEN(required)HF_TOKEN(optional but recommended for gated/private models)HF_MODEL_ID(optional override for model selection)
If BEAM_TOKEN is not set, the deploy job is skipped safely.
GET /- service metadataGET /health- health checkGET /info- config status overviewPOST /chat/stream- chat response endpointPOST /sessionsandGET /sessions- session handling
Cause:
- Stale/misbound Next dev process.
Fix:
- Stop existing frontend process and restart from
frontend/. - Ensure only one Next dev server is bound to port 3000.
Cause:
- Invalid or inaccessible Hugging Face model ID.
Fix:
- Set valid
HF_MODEL_IDin Beam environment. - Ensure
HF_TOKENhas access for gated/private models. - Redeploy:
beam deploy app.py:generate.
Cause:
APPWRITE_DB_IDdoes not exist or permissions mismatch.
Fix:
- Create/select the correct Appwrite database and collections.
- Verify API key scopes and project ID.
- Keep all tokens in env files only, never in source code
- Rotate any token if accidentally exposed
- Restrict CORS origins in production
- Use least-privilege Appwrite API key scopes
- Prefer separate dev/staging/prod Beam endpoints
- Add secret scanning in CI before deploy
- Phase 1: Stable chat, sessions, memory, auth
- Phase 2: File upload + RAG
- Phase 3: Web search augmentation
- Phase 4: Voice I/O and personas
- Add
.env.exampletemplates for backend and frontend with placeholder values only. - Configure Appwrite collections and indexes for sessions/messages and verify write permissions.
- Add backend tests for
chat,sessions, andmemoryroutes. - Add CI checks:
- lint + type checks
- secret scan
- basic API smoke test
- Add production deployment profiles:
- separate Beam endpoint per environment
- stricter CORS and error handling
- Implement Phase 2 (RAG): document ingestion pipeline + retrieval API.
This repository includes a LICENSE file. Update the section here with the exact license name if needed.