A production-oriented RESTful API for managing restaurant customers, orders, behavioral segmentation, and marketing campaigns. Built with Django and Django REST Framework, this project focuses on business-driven workflows beyond basic CRUD.
- Key Features
- Technology Stack
- Project Structure
- API Endpoints
- Getting Started
- Prerequisites
- Setup / Installation
- Environment Variables
- Running the Application
- Running Tests
- License
- Customer management with full CRUD support
- Order tracking with status updates
- Relationship between customers, orders, and campaigns
- Dynamic customer segments (computed, not stored)
- Segment preview and customer listing
- Default system segments creation
- ORM-based filtering and aggregation logic
- Campaign creation and configuration
- Campaign lifecycle management:
DRAFT → SCHEDULED → RUNNING → DONE / FAILED / CANCELED - Execution statistics and message inspection
- Campaign execution designed for background processing
- Retry and cancel semantics
- Execution result tracking (sent / failed)
- RESTful endpoints using DRF ViewSets
- Custom business actions beyond CRUD
- Clear separation between data access and business logic
- Clean project structure
- Testable business logic
- Ready for Docker and async execution (Celery-compatible)
- Language: Python 3.10+
- Framework: Django, Django REST Framework
- Database: PostgreSQL
- Async / Background Jobs: Celery (design-ready)
- Caching / Broker: Redis (recommended)
- Testing: Pytest / Django TestCase
- API Documentation: DRF Browsable API
- Containerization: Docker (optional)
/
├── manage.py
├── config/ # Project settings and URLs
├── apps/
│ ├── customers/ # Customer domain
│ ├── orders/ # Order domain
│ ├── segments/ # Behavioral segmentation
│ ├── campaigns/ # Campaign lifecycle & execution
│ └── common/ # Shared utilities
├── requirements.txt
├── .env
└── tests/
Each app is structured with:
- models
- serializers
- views (ViewSets)
- services / selectors (business & query logic)
- tests
POST /api/v1/customers/GET /api/v1/customers/GET /api/v1/customers/{id}/PUT /api/v1/customers/{id}/PATCH /api/v1/customers/{id}/DELETE /api/v1/customers/{id}/POST /api/v1/customers/{id}/refresh_metrics/
POST /api/v1/orders/GET /api/v1/orders/PATCH /api/v1/orders/{id}/status/
POST /api/v1/segments/GET /api/v1/segments/GET /api/v1/segments/{id}/preview/GET /api/v1/segments/{id}/customers/POST /api/v1/segments/create-defaults/
POST /api/v1/campaigns/GET /api/v1/campaigns/{id}/POST /api/v1/campaigns/{id}/schedule/POST /api/v1/campaigns/{id}/execute/POST /api/v1/campaigns/{id}/retry/POST /api/v1/campaigns/{id}/cancel/GET /api/v1/campaigns/{id}/stats/GET /api/v1/campaigns/{id}/messages/
- Python 3.10+
- PostgreSQL
- pip / virtualenv
- Clone the repository:
git clone https://github.com/your-username/restaurant-crm-backend.git
cd restaurant-crm-backend- Create and activate virtual environment:
python -m venv venv
source venv/bin/activate- Install dependencies:
pip install -r requirements.txtCreate a .env file in the root directory:
DEBUG=True
SECRET_KEY=your-secret-key
DATABASE_URL=postgres://user:password@localhost:5432/restaurant_crmpython manage.py migrate
python manage.py runserverAPI available at:
http://127.0.0.1:8000/
pytestTests focus on:
- segmentation correctness
- campaign lifecycle behavior
- business actions beyond CRUD
MIT License.
See the LICENSE file for details.
- Author: Amir Doustdar
- Email: amirrdoustdar1@gmail.com
- GitHub: @Amirrdoustdar
- Issues: GitHub Issues
- Discussions: GitHub Discussions