Skip to content

Repository files navigation

Restaurant CRM & Campaign Management API

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.


📜 Table of Contents

  • Key Features
  • Technology Stack
  • Project Structure
  • API Endpoints
  • Getting Started
    • Prerequisites
    • Setup / Installation
    • Environment Variables
    • Running the Application
    • Running Tests
  • License

✨ Key Features

Core CRM

  • Customer management with full CRUD support
  • Order tracking with status updates
  • Relationship between customers, orders, and campaigns

Behavioral Segmentation

  • Dynamic customer segments (computed, not stored)
  • Segment preview and customer listing
  • Default system segments creation
  • ORM-based filtering and aggregation logic

Campaign Management

  • Campaign creation and configuration
  • Campaign lifecycle management: DRAFT → SCHEDULED → RUNNING → DONE / FAILED / CANCELED
  • Execution statistics and message inspection

Asynchronous Workflows

  • Campaign execution designed for background processing
  • Retry and cancel semantics
  • Execution result tracking (sent / failed)

API Design

  • RESTful endpoints using DRF ViewSets
  • Custom business actions beyond CRUD
  • Clear separation between data access and business logic

Developer Experience

  • Clean project structure
  • Testable business logic
  • Ready for Docker and async execution (Celery-compatible)

🛠️ Technology Stack

  • 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)

📁 Project Structure

/
├── 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

🔌 API Endpoints

Customers

  • 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/

Orders

  • POST /api/v1/orders/
  • GET /api/v1/orders/
  • PATCH /api/v1/orders/{id}/status/

Segments

  • 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/

Campaigns

  • 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/

🚀 Getting Started

Prerequisites

  • Python 3.10+
  • PostgreSQL
  • pip / virtualenv

Setup / Installation

  1. Clone the repository:
git clone https://github.com/your-username/restaurant-crm-backend.git
cd restaurant-crm-backend
  1. Create and activate virtual environment:
python -m venv venv
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt

Environment Variables

Create a .env file in the root directory:

DEBUG=True
SECRET_KEY=your-secret-key
DATABASE_URL=postgres://user:password@localhost:5432/restaurant_crm

Running the Application

python manage.py migrate
python manage.py runserver

API available at:

http://127.0.0.1:8000/

✅ Running Tests

pytest

Tests focus on:

  • segmentation correctness
  • campaign lifecycle behavior
  • business actions beyond CRUD

📄 License

MIT License.
See the LICENSE file for details.

📧 Contact & Support

About

A production-oriented backend built with Django and Django REST Framework for managing restaurant customers and orders, dynamically segmenting users based on behavior, and executing marketing campaigns through stateful and asynchronous workflows.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages