← Back to Projects

UPS-Amazon

PythonDjangoPostgreSQLProtocol BuffersDocker

Overview

Full-stack delivery logistics simulation built for ECE 568 (Duke): a Django web app backed by PostgreSQL where users track packages, view a live delivery map, and redirect shipments in transit. A multithreaded daemon communicates with an external World Simulator over TCP/Protobuf and coordinates with a paired Amazon service over HTTP/JSON.

Description

Mini-UPS models the carrier side of a logistics system. The Django app serves authenticated users a dashboard, package tracker, and live map via server-rendered templates and AJAX APIs. A background UPSDaemon thread (started from CoreConfig.ready()) manages truck assignment, monitors fleet state, and drives two persistent integration layers: WorldConnection for TCP/Protobuf exchanges with the simulator (sequence/ack, pickup commands, delivery updates, error recovery) and AmazonCommunication for DB-backed outgoing HTTP/JSON messages with retry. Reliability patterns include sequence tracking, a command retry queue, an outbox table for Amazon messages, and an error log for simulator faults.

Core Components

  • UPSDaemon — orchestrates truck assignment, fleet monitoring, and spawns world/Amazon worker threads
  • WorldConnection — TCP client encoding/decoding protobuf messages; handles acks, retries, and maps world events to DB state
  • AmazonCommunication — persistent outbox queue (AmazonMessage) with worker thread; decouples HTTP failures from the main request cycle
  • `models.py` — trucks, warehouses, packages, items, notifications, sequence/ack state, command logs, retry queues, and per-user notification preferences
  • `views.py` — REST/JSON APIs (/api/truck/, /api/package/, /api/map-data/, /api/notifications/) consumed by front-end AJAX alongside full-page Django views
  • `notification_manager.py` — in-app and email notifications with per-user preferences

Demo

No live demo. Run via Docker Compose (docker-compose up); the app starts on port 8000 with Postgres on 5433. See ups/README.md for environment variables, API list, and protobuf/Amazon message reference.

Tech & Tools

Python · Django · PostgreSQL · Protocol Buffers · Docker · psycopg2 · requests · JavaScript (AJAX)

Highlights

  • Multithreaded Django daemon handling real-time TCP/Protobuf communication with a world simulator
  • DB-backed outbox and retry queues for reliable Amazon service coordination
  • Live package tracking map and in-transit delivery redirection via web UI
  • Per-user email and in-app notification preferences
  • Admin fleet overview and world control panel

More Projects