Project origin: This repository originates from the main branch of JunCaiAgent/AIordering. This project mainly delivers feature extensions and architecture improvements on top of the original (frontend/backend separation, authentication system, admin console, recommendation enhancements, production deployment support, etc.).
refactor branch — Frontend/Backend Separation + Production Deployment Enhancements
A restaurant food-ordering agent built on LangChain 1.0 + FastAPI + LLMs. Users interact through natural language to query dishes, get smart recommendations by party size / taste / diner profile, and manage dishes & users via an admin console. This branch upgrades the first version (main branch) with four major areas: frontend/backend separation, an authentication system, a full admin backend, and production deployment support.
| Aspect | First version (main) | This version (refactor) |
|---|---|---|
| Project layout | Flat files, single FastAPI app serving everything | Frontend/backend separation: frontend/ (H5 pages) + backend/ (API service) |
| Recommendation | Text-to-SQL + basic recommendations | RAG vector retrieval (ChromaDB, 40 dish profiles) + rules engine + diversified recommendation algorithm (category balancing / dynamic weights / soft-constraint fallback — never returns an empty result) |
| Database | restaurant schema |
catering_agent schema (renamed & migrated, 27 dishes, new pic image field) |
| Authentication | No login system | User registration/login (SMS/password) + image captcha + token auth; all business APIs require login |
| Admin console | None | Full admin backend (/admin): overview stats, dish pagination & inline editing, delist/relist, user management (create users / set passwords), recommendation weight & rule config, KB rebuild, data-statistics charts |
| Dish delisting | None | is_active flag: delisted dishes are excluded from rebuilt KB and recommendations |
| Deployment | Local run only | Gunicorn production config, BT-Panel deployment, nginx reverse proxy, static-asset performance (93% image size reduction) |
- Natural-language ordering chat: dish lookup, recommendation, pairing advice (
/api/ai/chat) - Smart recommendation: quota by party size, taste fallback chain, diner/scene filters, health tags, hard constraints on allergens & dietary taboos, explicit counts ("recommend one signature dish"), context awareness ("girlfriend is on her period" → warm sweet drinks)
- Image captcha: Pillow-rendered, Arial Bold with stroke, confusable characters removed from the charset, case-insensitive
- User auth: SMS/password login, 30-day tokens, set/reset password
- Admin console: dashboard, dish pagination & inline edit, user accounts, weight/rule config, KB rebuild (with amber warning banner), statistics (sales ranking / donut chart / trends)
- Demo ordering: mock order endpoint (login required, persists to DB and feeds back sales counts)
- Backend: Python 3.11 / FastAPI / LangChain 1.0 / Uvicorn / Gunicorn
- Vector store: ChromaDB (1024-dim, embedded by qwen3.7-text-embedding)
- Databases: MySQL 8 (local) / 5.7 (server), Redis (session & rate limiting)
- LLMs: Alibaba Cloud Bailian
qwen3.7-flash(chat),qwen3.7-text-embedding(embedding — model names must be lowercase) - Frontend: vanilla H5 single-page, Font Awesome icons
├── frontend/ # H5 frontend (served by nginx / FastAPI)
│ ├── index.html # User ordering chat
│ ├── admin.html # Admin console
│ └── img/ # Dish images (27, compressed)
└── backend/ # Backend service
├── main/ # api_server / agent / tools / auth / admin / db ...
├── kb_data/ # ChromaDB knowledge base (rebuilt by build_kb.py, git-ignored)
├── config.py # Configuration (reads .env)
├── build_kb.py # Rebuild knowledge base
├── weight_calc.py # Recommendation weight calculation
├── gunicorn_conf.py # Production multi-worker config
├── requirements.txt
└── .env.example # Env template (real .env holds secrets, git-ignored)
# 1. Install dependencies (Python 3.11)
cd backend && pip install -r requirements.txt
# 2. Configure environment
cp .env.example .env # fill in DB / Bailian LLM / SMS credentials
# 3. Initialize database (schema + 27 dishes)
python main/init_db.py
# 4. Compute weights & rebuild KB
python weight_calc.py && python build_kb.py
# 5. Run
python main/api_server.py
# Open http://127.0.0.1:3000/ (user) and http://127.0.0.1:3000/admin (admin)When using the backend/catering_agent.sql snapshot from this repo, the following accounts are built in (passwords shown in plaintext):
| Role | Account | Password | Entry |
|---|---|---|---|
| Admin | admin |
test123456 |
Admin console /admin |
| Demo user | 19900001111 |
test123456 |
User login (password) |
| Demo user | 19900002222 |
test123456 |
User login (password) |
Phone numbers are anonymized, non-real numbers for demo only; in production create users via the admin console and change the admin password.
- Single-host:
gunicorn -c gunicorn_conf.py main.api_server:app - Separated + nginx reverse proxy: serve static frontend via nginx, proxy
location /api/to the backend on port 3000 (see deploy.sh / project docs) - BT-Panel: Python Project Manager + nginx site reverse proxy (on CentOS 7: install deps with
--only-binary=:all:; usepysqlite3-binaryfor ChromaDB on systems with sqlite < 3.35)
李俊颖 and project contributors (Citadel Yang)