Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Shopify Order Fulfillment Automation Demo

License: MIT Python 3.11+ Django 5.0

🎯 Project Overview

Enterprise-grade demonstration of Shopify webhook automation showcasing professional software architecture, design patterns, and scalable order fulfillment processing.

Key Features:

  • βœ… Event-driven webhook architecture with unified endpoint
  • βœ… Multiple design patterns (Factory, Strategy, Observer, Chain of Responsibility)
  • βœ… Idempotent processing with deduplication
  • βœ… Async-ready architecture (Celery structure)
  • βœ… SOLID principles and clean code
  • βœ… Comprehensive testing and documentation

πŸ›οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Shopify       │───▢│  Webhook         │───▢│  Handler        β”‚
β”‚   Webhook       β”‚    β”‚  Validator       β”‚    β”‚  Factory        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚                        β”‚
                                β–Ό                        β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚  Deduplication   β”‚    β”‚  Strategy       β”‚
                       β”‚  Service         β”‚    β”‚  Selector       β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚                        β”‚
                                β–Ό                        β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚  Database        β”‚    β”‚  Fulfillment    β”‚
                       β”‚  Storage         β”‚    β”‚  Execution      β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚                        β”‚
                                β–Ό                        β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚  Observer        β”‚    β”‚  Result         β”‚
                       β”‚  Notifications   β”‚    β”‚  Response       β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🎨 Design Patterns Used

Factory Pattern

Creates appropriate webhook handlers based on event type:

handler = WebhookHandlerFactory.create_handler('orders/create')

Strategy Pattern

Selects fulfillment strategy based on order characteristics:

  • AutoFulfillmentStrategy: All items in stock
  • PartialFulfillmentStrategy: Some items available
  • ManualReviewStrategy: High-value orders (>$1000)
  • ExpressFulfillmentStrategy: VIP customers

Observer Pattern

Notifies multiple observers of webhook events:

  • LoggingObserver: Detailed event logging
  • MetricsObserver: Processing statistics
  • NotificationObserver: Alert system

Chain of Responsibility

Validation pipeline:

HMAC Validation β†’ Schema Validation β†’ Deduplication β†’ Business Rules

πŸš€ Quick Start

Local Development

  1. Clone and Setup
git clone <repository-url>
cd shopify_automation_demo
uv sync
  1. Environment Configuration
cp .env.example .env
# Edit .env with your configuration
  1. Database Setup
uv run python manage.py migrate
uv run python manage.py createsuperuser
  1. Run Development Server
uv run python manage.py runserver

Docker Development

# Build and start all services
docker-compose up --build

# Run migrations
docker-compose exec web python manage.py migrate

# Create superuser
docker-compose exec web python manage.py createsuperuser

πŸ§ͺ Testing Webhooks

Using cURL

curl -X POST http://localhost:8000/webhooks/shopify/ \
  -H "Content-Type: application/json" \
  -H "X-Shopify-Topic: orders/create" \
  -H "X-Shopify-Webhook-Id: unique-id-123" \
  -H "X-Shopify-Shop-Domain: test-shop.myshopify.com" \
  -d @webhooks/tests/fixtures/orders_create.json

Using Management Command

# Simulate different webhook events
uv run python manage.py simulate_webhook orders/create
uv run python manage.py simulate_webhook orders/updated
uv run python manage.py simulate_webhook orders/cancelled

Supported Webhook Events

  • orders/create - New order processing
  • orders/updated - Order modifications
  • orders/cancelled - Order cancellations
  • orders/fulfilled - Fulfillment updates
  • products/create - New product notifications
  • customers/create - Customer registration

πŸ“Š Monitoring & Observability

Django Admin Dashboard

  • Webhook Events: /admin/webhooks/webhookevent/
  • Orders: /admin/webhooks/shopifyorder/
  • Fulfillment Tasks: /admin/webhooks/fulfillmenttask/

Logs

# View webhook processing logs
tail -f logs/webhooks.log

# Docker logs
docker-compose logs -f web

Metrics

Processing statistics are automatically tracked:

  • Total webhooks processed
  • Success/failure rates
  • Processing times
  • Event type distribution

πŸ”’ Security Features

  • HMAC Signature Validation: Verifies webhook authenticity
  • Idempotent Processing: Prevents duplicate processing
  • Request Size Limits: Protects against large payloads
  • SQL Injection Prevention: Django ORM protection
  • Environment-based Configuration: No hardcoded secrets

πŸ“ˆ Performance Considerations

  • Database Indexing: Optimized queries on webhook_id, order_id
  • Redis Caching: Fast deduplication checks
  • Async Processing Ready: Celery integration structure
  • Connection Pooling: PostgreSQL optimization
  • Batch Processing: Scalable for high-volume scenarios

πŸ§ͺ Running Tests

# Run all tests
uv run python manage.py test

# Run with coverage
uv run pytest --cov=webhooks --cov-report=html

# Run specific test modules
uv run python manage.py test webhooks.tests.test_handlers

πŸ“ API Documentation

Webhook Endpoint

POST /webhooks/shopify/

Headers:

  • X-Shopify-Topic: Event type (required)
  • X-Shopify-Webhook-Id: Unique webhook ID (required)
  • X-Shopify-Shop-Domain: Shop domain (required)
  • X-Shopify-Hmac-SHA256: HMAC signature (required in production)

Response:

{
  "status": "success",
  "webhook_id": "unique-id-123",
  "event_topic": "orders/create",
  "result": {
    "fulfillment_method": "automatic",
    "status": "fulfilled",
    "tracking_numbers": ["1Z999AA1234567890"]
  }
}

πŸŽ“ Learning Resources

πŸ’Ό Portfolio Highlights

βœ… Enterprise Architecture Patterns
βœ… Production-Ready Code Quality
βœ… Comprehensive Error Handling
βœ… Scalable Design (1000+ webhooks/hour)
βœ… Docker Containerization
βœ… Professional Documentation
βœ… SOLID Principles Applied
βœ… Test-Driven Development

πŸ› οΈ Tech Stack

  • Backend: Django 5.0, Django REST Framework
  • Database: PostgreSQL (production), SQLite (development)
  • Cache: Redis
  • Task Queue: Celery (structure ready)
  • Containerization: Docker, Docker Compose
  • Testing: pytest, factory-boy
  • Code Quality: black, flake8, mypy

πŸ“„ License

MIT License - see LICENSE file for details.

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite
  6. Submit a pull request

πŸ“ž Contact

For questions about this portfolio project or potential collaboration opportunities, please reach out through:

  • Portfolio: [Your Portfolio URL]
  • LinkedIn: [Your LinkedIn Profile]
  • Email: [Your Professional Email]

This project demonstrates enterprise-level set up for high-value e-commerce automation projects.

About

Enterprise-grade demonstration of Shopify webhook automation showcasing professional software architecture, design patterns, and scalable order fulfillment processing.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages