This repository contains the FastAPI backend for sheydoc mobile application. It is responsible for sending push notifications, emails, and scheduled reminders when appointments are booked, canceled, or approaching. It uses Firebase Firestore for user/appointment data and Gmail SMTP for emails.
- Booking confirmations: Notify both patient and doctor via FCM and email.
- Appointment cancellations: Alerts sent to all parties.
- Automated reminders: Hourly cron job checks for appointments in the 24‑h and 1‑h windows, dispatching notifications/emails and marking reminders in Firestore.
- Health check endpoint for monitoring.
- CORS enabled to allow cross‑origin requests from your Flutter/React front end.
- Python 3.11+ (recommended)
- A Firebase project with Firestore
- Service account JSON file (
serviceAccountKey.jsonor equivalent path) - Gmail account with SMTP enabled (or any SMTP server)
-
Clone the repo and change directory:
git clone <repo-url> sheydoc_backend cd sheydoc_backend
-
Create and activate a virtual environment (Windows example):
python -m venv venv venv\Scripts\Activate.ps1 -
Install dependencies:
pip install -r requirements.txt -
Copy your Firebase service account JSON to the repo (or store it elsewhere and adjust
FIREBASE_SERVICE_ACCOUNT_PATH). -
Create a
.envfile with the following variables:FIREBASE_SERVICE_ACCOUNT_PATH=serviceAccountKey.json SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_USER=your@gmail.com SMTP_PASSWORD=app-specific-password FROM_NAME="TeleMed App"
Note: For Gmail, generate an App Password and/or enable "less secure" access.
Locally with uvicorn:
uvicorn main:app --host 0.0.0.0 --port 8000 --reloadThe API will be available at http://localhost:8000/.
| Method | Path | Description |
|---|---|---|
| GET | / |
Health check |
| POST | /booking-confirmed |
Notify on new appointment |
| POST | /appointment-canceled |
Notify on cancellation |
| GET | /check-reminders |
Trigger reminder logic (call hourly via cron) |
/booking-confirmed:
{
"appointment_id": "string",
"patient_id": "string",
"doctor_id": "string",
"appointment_datetime": "ISO string",
"duration_minutes": 30
}/appointment-canceled:
{
"appointment_id": "string",
"patient_id": "string",
"doctor_id": "string",
"canceled_by": "patient" | "doctor",
"appointment_datetime": "ISO string"
}/check-reminders has no body; run it hourly via an external scheduler (cron, Cloud Scheduler, etc.).
-
quick_test.pycontains a simple script that exercises every endpoint against a local server. Update the patient/doctor UIDs to match entries in your Firestore and run:python quick_test.py
-
You can also use
test_backend.pyfor pytest‑style unit tests.
- Users collection with documents containing at least
email,fcmToken, and optionaldisplayName/firstName. - Appointments collection with
status(confirmed),appointmentDateTime(ISO string),patientId,doctorId, andlastReminderSentfields. - Composite index on
status+appointmentDateTimefor efficient queries used by reminders.
- Ensure environment variables are set in your hosting platform.
- Schedule
/check-remindersto run every hour (e.g. Render cron job or Cloud Scheduler). - Keep the service account key secure.