This service powers the resort forecasting and operations backend. It is a FastAPI application that combines a loaded forecasting model, Supabase-backed operational data, chat assistance, staff planning, pricing tools, promotion management, notifications, audit logging, exports, and system health checks.
- Serves occupancy forecasts from a Hugging Face-hosted
joblibmodel. - Stores and reads operational data from Supabase.
- Applies manual overrides to forecasts.
- Produces staffing recommendations from forecasted demand.
- Exposes guest feedback, staff, schedule, pricing, promotion, and revenue endpoints.
- Provides admin/system endpoints for settings, notifications, audit logs, exports, backups, and health checks.
- Hosts a WebSocket chat assistant with retrieval-augmented generation support.
The backend is split into two main modules:
main.py- Core FastAPI application.
- Loads the forecasting model at startup.
- Defines the forecasting, feedback, staff, schedule, pricing, promotion, and dashboard endpoints.
- Mounts the chat router and the admin extensions router.
admin_extensions.py- Contains the admin/system endpoints that were split out of the main file.
- Implements settings, notification, export, audit, health, backup, and staffing override routes.
- Includes helper functions for notification creation, audit logging, CSV/PDF export generation, and seeding default records.
chat_rag.py- Provides the WebSocket chat route and retrieval helpers for the assistant.
Key Python packages:
fastapiuvicornpandasjoblibhuggingface_hubsupabasegoogle-genaiwebsocketsreportlabfor PDF exports
Required configuration:
HUGGINGFACE_TOKEN- token used to download the model artifact.HUGGINGFACE_REPO_ID- Hugging Face repository that stores the model.HUGGINGFACE_MODEL_FILE- optional model filename, defaults tomodel.joblib.RELOAD_TOKEN- token required by the reload endpoint.SUPABASE_URL- Supabase project URL.SUPABASE_SERVICE_ROLE_KEYorSUPABASE_ANON_KEY- Supabase API key.GEMINI_API_KEY- used by the chat assistant and health checks.ADMIN_EMAIL- default admin email used when one is not supplied.
Optional table overrides:
SUPABASE_EVENTS_TABLESUPABASE_HOLIDAYS_TABLESUPABASE_GUEST_FEEDBACK_TABLESUPABASE_STAFF_OVERRIDES_TABLE
- Dates are generally accepted and returned in ISO format:
YYYY-MM-DD. - JSON bodies are used for create/update operations.
- Errors are returned as FastAPI HTTP errors with structured status codes.
- Most admin/system endpoints default to the configured admin email when a
user_emailquery parameter is not provided.
GET /health- basic service health check.GET /- simple root response.POST /reload- reloads the model from Hugging Face. Requires thex-api-tokenheader matchingRELOAD_TOKEN.
POST /forecast- generate forecast results for a horizon.GET /forecast/today- one-day forecast shortcut.GET /daily_occupancy- daily occupancy time series data.GET /revenue/dashboard- revenue dashboard data used by the frontend.
Forecast responses include:
predicted_roomslower_boundupper_bounddemand_classoccupancy_percentageevents- optional
staffingrecommendations
POST /override- store a manual forecast override.
Overrides are persisted in Supabase and can optionally return staffing recommendations for the overridden prediction.
GET /feedback- list feedback records with optional sentiment/date filters.POST /feedback- dual-mode endpoint:- forecast feedback mode using
actual_rooms_sold - guest feedback mode using
date,rating, andcomment
- forecast feedback mode using
Guest feedback inserts can trigger a notification when sentiment is negative.
GET /events- list operational events.GET /ethiopian_holidays- list holiday records, optionally filtered by year.
GET /admin/staff- list active staff.POST /admin/staff- create a staff record.PUT /admin/staff/{staff_id}- update a staff record.DELETE /admin/staff/{staff_id}- deactivate/remove a staff record.
GET /admin/schedule- fetch existing schedule data.POST /admin/schedule/generate- generate a schedule.PUT /admin/schedule- persist schedule changes.POST /admin/schedule/publish- publish a schedule.
Schedule publishing creates a notification and audit entry.
GET /admin/pricing-rules- fetch pricing rules.PUT /admin/pricing-rules- update pricing rules.POST /pricing/suggest- suggest a price for a room type/date.POST /pricing/approve- approve a pricing recommendation.GET /pricing/approvals- list approved pricing records.
POST /promotions- create a promotion.PUT /promotions/{promotion_id}- update a promotion.DELETE /promotions/{promotion_id}- remove a promotion.GET /promotions- list promotions.GET /admin/promotions- admin-facing promotion listing.
WS /ws/chat- WebSocket chat endpoint mounted bychat_rag.py.
The extension router in admin_extensions.py adds the following grouped endpoints:
GET /admin/settingsPUT /admin/settingsGET /admin/staffing-ratiosPUT /admin/staffing-ratiosGET /admin/notification-preferencesPUT /admin/notification-preferencesGET /notificationsPUT /notifications/{notification_id}/readPUT /notifications/read-allDELETE /notifications/{notification_id}DELETE /notifications/clear-allGET /export/forecastGET /export/staffingGET /export/feedbackGET /export/promotionsGET /admin/audit-logGET /health/systemGET /admin/backupPOST /staff-overrideGET /staff-override
The application expects the following logical tables, though some names can be overridden through environment variables:
forecast_overridesactual_vs_predictedfeedbackeventsethiopian_holidaysstaffstaffing_rulesstaffing_ratiosstaff_schedulepricing_rulespricing_approvalspromotionsnotificationsnotification_preferencesaudit_logresort_settingsstaff_overrides
Exports are generated from live Supabase data.
- CSV responses use a generic row-to-CSV conversion.
- PDF responses are generated with
reportlabwhen available. - If
reportlabis missing, the PDF export route still returns a plain-text fallback payload.
Install dependencies:
pip install -r requirements.txtRun the API:
uvicorn main:app --reload --host 0.0.0.0 --port 8000- The model must load successfully before forecast endpoints can return data.
- Most admin write routes log an audit record and may create a notification when the action is user-visible.
- The backup endpoint is intended as a JSON snapshot download for internal admin use.