Cryptographic Code Engine • Visual Layout Studio • 300 DPI Duplex Print PDFs • Supabase Cloud Sync • Mobile Customer Portal
██████╗ ██████╗ ██████╗ ██████╗ ███████╗██████╗ ██████╗ ██████╗ ██╗ ██╗██████╗ ██████╗ ███╗ ██╗███████╗
██╔══██╗██╔══██╗██╔═══██╗██╔══██╗██╔════╝██╔══██╗██╔════╝██╔═══██╗██║ ██║██╔══██╗██╔═══██╗████╗ ██║██╔════╝
██████╔╝██████╔╝██║ ██║██████╔╝█████╗ ██████╔╝██║ ██║ ██║██║ ██║██████╔╝██║ ██║██╔██╗ ██║███████╗
██╔═══╝ ██╔══██╗██║ ██║██╔═══╝ ██╔══╝ ██╔══██╗██║ ██║ ██║██║ ██║██╔═══╝ ██║ ██║██║╚██╗██║╚════██║
██║ ██║ ██║╚██████╔╝██║ ███████╗██║ ██║╚██████╗╚██████╔╝╚██████╔╝██║ ╚██████╔╝██║ ╚████║███████║
╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝
ProperCoupons is a full-stack, production-ready loyalty card and promotional coupon generation ecosystem.
It automates everything from cryptographic coupon generation and visual template composition to commercial duplex PDF printing, Supabase cloud synchronization, and instant mobile customer redemptions.
- 🌟 System Architecture
- ✨ Key Highlights & Features
- 📁 Project Tree
- 🚀 Quick Start Guide
- ☁️ Supabase Cloud Setup (2 Minutes)
- 🌐 Deploying the Customer Portal
- 🧪 Automated Test Suite
- 📜 License
flowchart TD
subgraph Admin & Studio Suite [ProperCoupons Studio Suite]
STUDIO[🎨 Visual Template Designer] -->|Live Position & Color Sliders| CFG[(config/templates.yaml)]
GEN[🚀 Batch Generation Engine] -->|1. Generate Codes| CRYPTO[🔐 Crypto CSPRNG Engine]
CRYPTO -->|2. Record Batch| DUAL_SYNC{🔄 Dual Sync Engine}
DUAL_SYNC -->|Local Storage| SQLITE[(Local SQLite DB)]
DUAL_SYNC -->|REST / RPC API| SUPABASE[(☁️ Supabase PostgreSQL)]
GEN -->|3. Render Layout| COMPOSITOR[🖼️ PIL 8K High-Res Compositor]
COMPOSITOR -->|4. Compile Matrix| PDF_ENG[🖨️ ReportLab Duplex PDF Engine]
PDF_ENG -->|Print Output| PDF_FILE[📄 300 DPI A4/A3 Sheets + Crop Marks]
end
subgraph Customer Mobile Journey [Customer Self-Service Experience]
CUSTOMER[📱 Customer / Contractor] -->|Scans QR Code on Pack| PORTAL[🌐 Customer Redemption Portal]
PORTAL -->|Auto-fill ?code=ABC123| RPC_CALL[⚡ Supabase Atomic Stored Procedure]
RPC_CALL -->|Row-Locking Anti-Fraud Check| SUPABASE
SUPABASE -->|🎉 Success + Reward Confirmation| PORTAL
end
subgraph Real-Time Ledger [Audit & Administration]
LEDGER[📊 Token Ledger & Audit Tab] -->|Query Real-Time Stats| DUAL_SYNC
end
- Intuitive Single-Axis Sliders: Move text and QR codes across the card freely with
↔️ Horizontal Position (Left ⟵ Center ⟶ Right)and↕️ Vertical Position (Top ⟵ Center ⟶ Bottom)sliders. - Minimal Fit Typography: Automatic bounding box fitting eliminates clipping and text overflow.
- Full Color Customization: Live color pickers for coupon text, QR foreground, and QR background.
- Real-Time Live Rendering: Preview changes on high-resolution 8K assets instantly.
- Per-Template Persistence: Click "💾 Save Settings for this Template" to save coordinates and colors directly to
config/templates.yaml.
- Cryptographically Secure RNG: Powered by Python's
secretsmodule (CSPRNG). - Ambiguity-Free Charsets: Automatically removes confusing characters (
0vsO,1vsI,L) to eliminate user typing mistakes. - 100% Collision-Free Guarantee: Checks against database and lifetime batch sets to prevent duplicates.
- Luhn Mod-36 Checksums: Optional client-side mathematical checksum validation.
- 300 DPI High-Resolution Output: Crisp vector-quality cards ready for offset and digital print shops.
- Precision Crop Marks: Subtle corner cut lines for automated guillotine and die-cutting trimmers.
- Synchronized Duplex Alignment: Front artwork and Back coupon cards are automatically mirrored in multi-up grid sheets (A4, A3, Letter) for double-sided printing.
- Offline-First Resilience: Works offline with zero dependencies using an embedded SQLite ledger (
coupons.db). - Supabase Cloud Push: Automatically dual-writes new batches to Supabase PostgreSQL in high-speed chunks.
- Atomic Fraud Protection: PostgreSQL stored procedure
redeem_tokenuses row-level locking (FOR UPDATE) to mathematically prevent double-redemption race conditions.
- Mobile-First Responsive Web App: Located in
customer_portal/, ready for 1-click free hosting on Vercel, Cloudflare Pages, or Netlify. - Auto-Fill from QR Scan: Scanning a token's printed QR code opens
https://yourdomain.com/?code=H0DOA7and populates the code automatically. - In-Browser Camera Scanner: Built-in HTML5 QR/Barcode scanner allows customers to scan directly without installing an app.
- Confetti Celebration & Receipt: Celebratory animations, credited points badge, and digital timestamped receipts.
- Collapsible Batch Cards (
st.expander): View batch metrics at a glance (Total, Redeemed, Active, Value, Date). - Comprehensive Token Inspector: Examine individual coupon codes, timestamps, and customer references.
- Multi-Field Search Bar: Instantly filter across Token Codes, Campaign Names, Customer Phone Numbers, and Invoice References.
- One-Click Exports: Download batch
.csvfiles and formatted.xlsxExcel spreadsheets directly.
ProperCoupons/
├── config/
│ ├── templates.yaml # Template profiles, coordinates, QR positions & colors
│ └── settings.yaml # Global settings, paper sizes, DPI & Supabase keys
├── customer_portal/ # Standalone Customer Web App (Deployable to Vercel/Cloudflare)
│ ├── index.html # Mobile-first customer redemption portal
│ ├── style.css # Responsive design with reward cards & animations
│ ├── app.js # Supabase RPC redemption logic & QR camera scanner
│ ├── config.js # Frontend Supabase project configuration
│ ├── vercel.json # Vercel deployment routing configuration
│ └── README.md # 1-click web portal hosting guide
├── src/
│ ├── core/
│ │ ├── code_generator.py # Cryptographic PRNG, patterns & checksums
│ │ ├── renderer.py # High-performance PIL compositor & auto-font engine
│ │ ├── sheet_layout.py # Print PDF generator, duplex alignment & crop marks
│ │ ├── database.py # SQLite lifecycle ledger & Excel/CSV export engine
│ │ └── supabase_client.py # Supabase cloud sync & remote RPC caller
│ ├── utils/
│ │ ├── helpers.py # Cross-platform path, font loader & color parser
│ │ └── config_loader.py # YAML configuration parser & persistence engine
│ └── ui/
│ ├── web_app.py # Streamlit visual studio & token ledger
│ └── cli.py # Rich interactive terminal interface
├── supabase/
│ └── schema.sql # PostgreSQL tables, indices, RLS & atomic RPC function
├── tests/ # Full automated test suite (15 unit tests)
│ ├── test_generator.py
│ ├── test_renderer.py
│ ├── test_database.py
│ └── test_supabase.py
├── run.py # Unified CLI & Web application runner
├── requirements.txt # Python package dependencies
├── .gitignore # Git ignore rules for builds & databases
├── LICENSE # MIT open source license
└── README.md # Project documentation
- Python 3.10 or higher
pippackage manager
# 1. Clone the repository
git clone https://github.com/yourusername/ProperCoupons.git
cd ProperCoupons
# 2. Install dependencies
pip install -r requirements.txtpython run.py --webOpens the interactive Visual Designer, Batch Generator, and Token Ledger in your default web browser.
# Interactive Menu
python run.py
# Headless Batch Generation (e.g. for automation / CI)
python run.py --generate -t acrylic_enhancer_5kg -c 100 -n "Fall Promo 2026" -d "100"
# Verify / Redeem a Code from Terminal
python run.py --verify H0DOA7- Create a free project at supabase.com.
- Go to SQL Editor, paste the contents of
supabase/schema.sql, and click Run. - Copy your Project URL and API Keys from Settings ➔ API.
- In
config/settings.yaml, add your credentials:supabase: enabled: true url: "https://your-project.supabase.co" key: "your-service-role-or-anon-key"
- In
customer_portal/config.js, add your public anon key:const SUPABASE_CONFIG = { url: "https://your-project.supabase.co", anonKey: "your-public-anon-key" };
Deploy the customer web app for free in under 1 minute:
- Go to vercel.com ➔ New Project.
- Select your repository.
- Set Root Directory to
customer_portal. - Click Deploy. Your customer portal is immediately live at
https://your-app.vercel.app!
Once deployed, update url_template in config/templates.yaml to point to your live URL:
qr_element:
url_template: "https://your-app.vercel.app/?code={code}"ProperCoupons includes a test suite covering cryptographic uniqueness, mathematical checksums, dynamic image composition, duplex PDF layout, SQLite queries, and Supabase client fallbacks.
Run all unit tests:
python -m unittest discover tests...............
----------------------------------------------------------------------
Ran 15 tests in 4.908s
OK
Distributed under the MIT License. See LICENSE for more information.