How shenleeosialai/oshen-comics works
Project Type & Purpose
• Full-stack, Django-based e-commerce web application.
• Purpose: allow users to browse comics & merchandise, manage carts, apply coupons, receive recommendations, and pay via M-Pesa or Stripe.
• Runs in Docker Compose with separate containers for web, workers, database, and Redis.
File Structure
• Top-level directories:
• account, cart, coupons, orders, payment, shop → Django apps implementing business domains.
• myshop/settings → multi-environment Django settings (base, local, prod).
• config/nginx & config/uwsgi → reverse-proxy and WSGI server configuration.
• data/cache → Redis dump for sessions/cache.
• static, templates → compiled front-end assets and site-wide templates.
• Docker-related: Dockerfile, docker-compose.yml, wait-for-it.sh.
• Celery integration: myshop/celery.py + orders.tasks, payment.tasks → background jobs.
• External API clients: payment/mpesa/client.py, Stripe SDK via Python.
README for Insights
• Confirm tech stack: Django, PostgreSQL, Redis (cache & broker), Celery, Nginx, uWSGI, Docker.
Main Components & Their Relationships
A. Client Layer (Browser / Mobile)
• Public user interface (templates rendered by Django).
• Admin interface (Django Admin under /admin).
B. Ingress Layer
• Docker-Compose “web” service includes Nginx reverse proxy (config/nginx/default.conf.template).
• uWSGI application server (config/uwsgi/uwsgi.ini) hosting Django.
C. Application Layer
• Django monolith with apps:
1. account (auth, profiles)
2. cart (Redis-backed session & cart logic)
3. coupons (coupon code logic)
4. shop (catalog, recommendations via shop.recommender)
5. orders (order placement, tracking, PDF receipts)
6. payment (MPesa & Stripe flows, webhooks)
• Celery worker(s) reading from Redis broker to handle email notifications, countdown deals, Mpesa polling.
D. Data Storage & Cache
• PostgreSQL container storing relational data (all Django models in each app).
• Redis container used as:
• Session store (cart, user sessions)
• Cache backend (Django cache for product lists, count-down deals)
• Celery broker (tasks queue).
E. External Services
• M-Pesa API endpoints for mobile payments.
• Stripe API for credit card payments.
F. Static & Media
• Django’s ‘static’ directory served via Nginx.
G. Docker & Deployment
• Docker Compose orchestrates services: web, worker, db (Postgres), cache (Redis).
• SSL termination at Nginx (ssl/myshop.crt, .key).
Data & Control Flows
• User → HTTPS → Nginx → uWSGI → Django view →
• Query/Post → PostgreSQL
• Session/Cache read-write → Redis
• Trigger background job → Celery (puts task in Redis)
• External API calls → M-Pesa / Stripe
• Render response → Nginx → User.
• Celery Worker → Redis (broker) → executes tasks (email, order fulfillment, Mpesa polling) → writes back to PostgreSQL or triggers outbound API calls.
Architectural Patterns & Design Principles
• Monolithic Django MVC (models, views, templates) with logical separation into apps.
• Containerized micro-services style orchestrated by Docker Compose.
• Asynchronous task pattern (Celery) for non-blocking background work.
• Cache-aside pattern with Redis for session & caching layers.
• Twelve-factor app compliance: environment-specific configs, stateless web processes, backing services as attached resources.