Backend API for Apatye platform - A modular monolith built with Django 5, DRF, PostgreSQL, Redis, and Celery.
- Framework: Django 5 + Django REST Framework
- Database: PostgreSQL 16
- Cache/Message Broker: Redis 7
- Task Queue: Celery + Celery Beat
- Containerization: Docker + Docker Compose
- API Documentation: OpenAPI 3 (drf-spectacular)
- Doctor Appointments (
apps.appointments) - Appointment scheduling system - Motorcycle Delivery (
apps.delivery) - Delivery service management - Payment & Billing (
apps.billing) - Zibal integration for Business Plan subscriptions
- Docker & Docker Compose
- Make (optional, but recommended)
- Clone the repository
- Access the application
یک کلاینت React در پوشه frontend/ قرار داده شده است که با Vite پیکربندی شده و از API بکاند روی http://localhost:8000/api استفاده میکند. برای راهاندازی رابط کاربری:
cd frontend
npm install
npm run devدر حالت توسعه، پراکسی داخلی Vite تمام درخواستهای /api را به سرویس Django هدایت میکند. اسکریپتهای npm run build, npm run test و npm run lint نیز برای تولید خروجی نهایی، اجرای تستهای Vitest و بررسی ESLint در دسترس هستند.
Key environment variables (see .env.example for full list):
DJANGO_SETTINGS_MODULE=config.settings.dev
SECRET_KEY=your-secret-key
DATABASE_URL=postgres://apatye:apatye@db:5432/apatye
REDIS_URL=redis://redis:6379/0
CITY_NAME=Abadeh
KAVENEGAR_API_KEY=your-kavenegar-api-key
SMS_ENABLED=Falsemake help # Show all available commands
make up # Start all services
make down # Stop all services
make restart # Restart all services
make logs # Show logs
make migrate # Run migrations
make makemigrations # Create new migrations
make shell # Open Django shell
make test # Run tests
make test-cov # Run tests with coverage
make lint # Run linting
make fmt # Format code
make clean # Clean up containers and volumesapatye_backend/
├── apps/ # Django applications
│ ├── common/ # Shared utilities and base classes
│ ├── users/ # User management & authentication
│ ├── vendors/ # Service providers
│ ├── services/ # Available services
│ ├── appointments/ # Doctor appointment scheduling
│ ├── delivery/ # Motorcycle delivery service
│ ├── notifications/ # SMS & push notifications
│ └── billing/ # Business plan boost subscriptions
├── config/ # Django configuration
│ ├── settings/ # Settings (base, dev, prod)
│ ├── urls.py # URL configuration
│ ├── wsgi.py # WSGI application
│ ├── asgi.py # ASGI application
│ └── celery.py # Celery configuration
├── requirements/ # Python dependencies
│ ├── base.txt # Base requirements
│ ├── dev.txt # Development requirements
│ └── prod.txt # Production requirements
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Docker image definition
├── Makefile # Development commands
├── manage.py # Django management script
├── .env.example # Example environment variables
└── README.md # This file
- Language: Persian (fa-IR)
- Timezone: Asia/Tehran
- City: Abadeh
Mobile-based authentication using OTP (One-Time Password):
- SMS integration with Kavenegar
- Development mode: OTP codes logged to console
- Production mode: OTP codes sent via SMS
Run tests with pytest:
# Run all tests
make test
# Run tests with coverage
make test-covTarget: ≥ 80% coverage on critical paths
Interactive API documentation is available at:
- Swagger UI: http://localhost:8000/api/docs/
- ReDoc: http://localhost:8000/api/redoc/
- OpenAPI Schema: http://localhost:8000/api/schema/
- Revenue Model: Business Plan Boost subscriptions only
- No transaction commissions
- Payment Gateway: Zibal (زیبال)
- Pricing: Starting from 500,000 Rials/month with volume discounts
- 3 months: 5% discount
- 6 months: 10% discount
- 12 months: 15% discount
- ✅ Zibal IPG integration
- ✅ Idempotent payment requests
- ✅ Automatic payment verification
- ✅ Subscription auto-activation
- ✅ Payment reconciliation (manual & automated)
- ✅ Comprehensive logging and monitoring
See ZIBAL_INTEGRATION.md for detailed documentation.
# Format code
make fmt
# Run linters
make lint# Create migrations
make makemigrations
# Apply migrations
make migrate
# Open database shell
make dbshell# Check Celery status
make celery-status
# Start Flower (Celery monitoring)
make flowerSee CONTRIBUTING.md for contribution guidelines.
- HTTPS enforced in production
- CORS configured for specific origins
- Rate limiting ready (needs to be applied to endpoints)
- Secure cookie settings in production
- Database credentials use environment variables
- Sentry error tracking (optional, production)
Important: See SECURITY.md for:
- Security configuration checklist
- Dependency security status
- Secret management best practices
- Production deployment security
[Your License Here]
[Your Contact Information]
Apatye uses Zibal as the payment gateway for subscription payments.
# 1. Start payment
curl -X POST http://localhost:8000/api/billing/subscriptions/start/ \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"plan_type": "business", "months": 3}'
# Response includes redirect_url
# Redirect user to: https://gateway.zibal.ir/start/{trackId}
# 2. After payment, callback is received automatically
# GET /api/payments/zibal/callback?trackId=123456789
# 3. Check subscription status
curl http://localhost:8000/api/billing/subscriptions/me/ \
-H "Authorization: Bearer YOUR_TOKEN"For development and testing:
ZIBAL_MERCHANT_ID=zibal
ZIBAL_SANDBOX=True# Manual reconciliation of pending payments
python manage.py zibal_reconcile --hours=24
# Dry run (no changes)
python manage.py zibal_reconcile --dry-runFull payment integration guide: ZIBAL_INTEGRATION.md