FastAPI backend for the Marcus Cleaning platform. It provides:
- Role-based auth for
customer,cleaner, andadmin - Booking lifecycle with pricing + payment transaction creation
- Place autocomplete/details/reverse-geocode integration
- Document upload intents (local or S3 storage backend)
- Payment providers (
flutterwave,stripe,test) with webhook handling - Permission-template system for cleaner/customer route access
- Celery queue integration and APScheduler heartbeat monitoring
- Python + FastAPI
- MongoDB (primary data store)
- Redis (rate limiting, Celery broker/backend, cache usage)
- Celery worker + Flower (optional monitoring)
- Jinja2 templates for web payment preview pages
api/ # FastAPI routes (v1 + web pages)
core/ # settings, queue, payments, storage, scheduler, errors
repositories/ # database access
schemas/ # Pydantic models
security/ # auth, principal resolution, permission checks
services/ # business logic
templates/ static/ # web payment template assets
tests/ # pytest test suite
docs/ # focused feature docs
- Python 3.11+
- MongoDB running
- Redis running
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtOn Windows PowerShell:
.venv\Scripts\Activate.ps1cp .env.example .envThen update .env (see required variables below).
# Development server
fastapi dev main.py
# Basic Production server
fastapi run main.pyOpen:
- Swagger UI:
http://localhost:7860/docs - ReDoc:
http://localhost:7860/redoc - Health:
http://localhost:7860/health
Run Celery worker:
CELERY_CUSTOM_WORKER_POOL=celery_aio_pool.pool:AsyncIOPool celery -A celery_worker worker -l info --pool=custom --concurrency=5Run Flower:
celery -A celery_worker.celery_app flower --port=5555Start API + worker + Mongo + Redis + Flower:
docker compose up --buildServices:
- API:
http://localhost:7860 - Flower:
http://localhost:5555
The app validates required environment variables at startup in core/settings.py.
SECRET_KEYSESSION_SECRET_KEYGOOGLE_MAPS_API_KEYGOOGLE_CLIENT_IDGOOGLE_CLIENT_SECRETSUCCESS_PAGE_URLERROR_PAGE_URLEMAIL_USERNAMEEMAIL_PASSWORDEMAIL_HOSTEMAIL_PORTCELERY_BROKER_URLCELERY_RESULT_BACKEND
DB_TYPEsupportsmongodborsqlite, but current repository services are implemented around async Mongo usage.- Recommended and used in
.env.example:DB_TYPE=mongodbMONGO_URLDB_NAME
STORAGE_BACKEND=localors3- For
local:STORAGE_LOCAL_ROOT(defaultuploads) - For
s3:S3_BUCKET_NAMErequired (+ optionalS3_REGION,S3_ENDPOINT_URL)
PAYMENT_DEFAULT_PROVIDER=flutterwave|stripe|test- For
flutterwave:FLUTTERWAVE_SECRET_KEY,FLW_WEBHOOK_SECRET_HASH - For
stripe:STRIPE_SECRET_KEY,STRIPE_WEBHOOK_SECRET - For
test:TEST_PAYMENT_BASE_URL(optionalTEST_PAYMENT_WEBHOOK_SECRET_HASH)- Set base URL to this API host, e.g.
http://localhost:7860, so checkout links resolve to/web/payments/link/{reference}
- Set base URL to this API host, e.g.
ROLE_RATE_LIMITS(e.g.anonymous:20/minute,cleaner:80/minute,customer:80/minute,admin:140/minute)BOOKING_ALLOW_ACCEPT_ON_PENDING_PAYMENT(true/false)CORS_ORIGINS(comma-separated)ENV(development/production)DEBUG_INCLUDE_ERROR_DETAILSSUPER_ADMIN_EMAIL,SUPER_ADMIN_PASSWORD(needed for super-admin bootstrap/login flow)
Mounted routers in main.py:
/v1/admins- admin auth/profile
- admin language preference endpoints (
GET|PATCH /v1/admins/profile/language) - permission templates + rollout
- permission catalog (
GET /v1/admins/permissions/catalog) - user picker autocomplete (
GET /v1/admins/users/autocomplete) for cross-role search (customer + cleaner) by email/name/id - customer places lookup for concierge (
GET /v1/admins/customers/{customer_id}/places) returningPlaceOut[] - customer place creation for concierge/support (
POST /v1/admins/customers/{customer_id}/places) withlabel,place_id, optionalisDefault; admin attribution is token-derived in backend - concierge create-booking flow uses booking payload shape (
BookingBase) and derives actor admin from token context - concierge cleaner selection enforces cleaner profile flag
allow_admin_selection=true - booking and concierge lifecycle statuses are system-owned and transition through backend state-machine rules
/v1/customers- signup/login/refresh/account
- preferred language endpoints (
GET|PATCH /v1/customers/me/language) - Google OAuth routes
- saved-address create/update now take
place_idinput and server-resolveplacedetails - contract auth aliases (
/sign-in,/sign-up,/password-reset/request)
/v1/cleaners- signup/login/refresh/account
- preferred language endpoints (
GET|PATCH /v1/cleaners/me/language) - Google OAuth routes
/v1/bookings- create/list/get (customer identity for create is token-derived, not request-body self-id)
- cleaner accept/complete
- customer acknowledge completion
- customer mark-paid aliases (
POST|PATCH /v1/bookings/{booking_id}/payments/mark-paid) - customer booking rating submit (
POST /v1/bookings/{booking_id}/ratings)
/v1/places- allowed countries
- autocomplete/details/reverse geocode
- saved search history
/v1/reviews- list/get/create/update/delete
/v1/documents- upload intent, complete upload, fetch/delete metadata
- local upload/read helper routes (hidden from OpenAPI)
/v1/payments- webhook receiver
- fetch by id/reference
- refund
- payment-method CRUD under
/v1/payments/methods/*
/v1/profile- profile aliases for customer profile, addresses, and payment-method CRUD
/v1/settings- notification/security/privacy patches
- session controls (
revoke-others,revoke-all,logout, and targetedDELETE /v1/settings/security/sessions/{session_id}) - account lifecycle endpoints (
POST /v1/settings/account/deactivate,POST /v1/settings/account/delete,DELETE /v1/settings/account)
/web/paymentsGET /web/payments/templateGET /web/payments/link/{reference}
- Auth uses Bearer tokens resolved to an
AuthPrincipal. - Role checks are enforced per endpoint (
customer,cleaner,admin). - Role-based session policy is enforced during token verification:
AUTH_SESSION_MAX_AGE_ADMIN_SECONDSAUTH_SESSION_MAX_AGE_CLEANER_SECONDSAUTH_SESSION_MAX_AGE_CUSTOMER_SECONDSAUTH_SESSION_IDLE_TIMEOUT_ADMIN_SECONDSAUTH_SESSION_IDLE_TIMEOUT_CLEANER_SECONDSAUTH_SESSION_IDLE_TIMEOUT_CUSTOMER_SECONDS
- Non-admin accounts also require:
accountStatus == ACTIVE- matching route permission key in
permissionList
- Admin super account bypass is supported via static ID/email logic.
- Global rate limiting is applied per role and exposes headers:
X-RateLimit-LimitX-RateLimit-RemainingX-RateLimit-ResetRetry-After(on 429)
Most endpoints return a standard shape:
{
"success": true,
"message": "Some message",
"data": {},
"requestId": "..."
}Localization behavior:
- Supported response languages are
enandfr. Accept-Languageis validated to supported values only (en/frfamily).- For authenticated routes, account
preferredLanguagetakes precedence. - If no profile language is set, default language is
en. - Auth token responses include top-level
language.
Validation and error responses keep the same envelope with success: false.
GET /health reports:
- MongoDB status + latency
- Redis status + latency
- APScheduler heartbeat freshness
Run tests with:
pytestTest files are in tests/ (payments, bookings, permissions, places, queue, settings validation, etc.).
Mandatory documentation for contributors/agents:
DOCS_INDEX.md(documentation map and update matrix)agents.md(working contract and non-negotiable instructions)design.md(architecture and migration direction)AUTH_STRATEGY.md(role-based auth source-of-truth)MIGRATION_LOG.md(implemented/planned migration entries)CONTRIBUTING_AGENT_RULES.md(workflow and done criteria)ENDPOINT_SUMMARIES.md(feature-level API behavior summaries)
Change policy:
- Always update
readme.mdandENDPOINT_SUMMARIES.mdwhen behavior or endpoint contracts change. - Update migration and auth docs whenever role auth flow or source-of-truth changes.
Current auth split:
- Admin auth: Auth0-backed.
- Cleaner and customer auth: local backend auth.
This split is intentional for current delivery velocity and lower bug-fix turnaround on user-facing auth paths. See AUTH_STRATEGY.md and design.md for detailed rationale and migration posture.
DOCS_INDEX.mdagents.mddesign.mdAUTH_STRATEGY.mdMIGRATION_LOG.mdCONTRIBUTING_AGENT_RULES.mdADMIN_CONCIERGE_BOOKING_FRONTEND_FLOW.mddocs/ADMIN_ENDPOINTS_AND_PERMISSION_GROUPS_FRONTEND_GUIDE.mddocs/ADMIN_CONCIERGE_BOOKING_FRONTEND_FLOW.mddocs/auth0_tenant_baseline.mddocs/runbooks/auth_incident_response.mddocs/runbooks/auth0_outage_and_key_rotation.mddocs/runbooks/compliance_export_validation.mddocs/release_auth_cutover_gate.mddocs/drills/auth_drill_report_template.md