Skip to content

yashthakur1/rapsap-shelftalker

Repository files navigation

AOPS - Automated Offer Print System

A full-stack web application that automates generating and printing offer tags from CSV files. Supports both preset and custom HTML/CSS templates for PDF generation.

🎯 Features

  • CSV Upload: Batch import offers from CSV files
  • Offer Management: View and select offers in an intuitive grid
  • Template System: Choose from preset templates or upload custom designs
  • PDF Generation: Server-side rendering with Jinja2 templating
  • Responsive Design: Works seamlessly on all devices
  • Real-time Preview: See changes instantly
  • Batch Processing: Generate PDFs for multiple offers at once

πŸ—οΈ Tech Stack

Backend

  • FastAPI - Modern Python web framework
  • Motor - Async MongoDB driver
  • Pyppeteer - Headless browser for PDF generation
  • Pydantic - Data validation
  • Jinja2 - Template rendering

Frontend

  • React 18 - UI framework
  • Vite - Build tool
  • Tailwind CSS - Utility-first CSS
  • Axios - HTTP client
  • React Hot Toast - Notifications

Database

  • MongoDB - NoSQL database for offers and templates

πŸ“ Project Structure

aops/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”‚   β”œβ”€β”€ offers.py          # Offer endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ templates.py        # Template endpoints
β”‚   β”‚   β”‚   └── pdf.py              # PDF generation endpoints
β”‚   β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”‚   β”œβ”€β”€ offer.py            # Offer Pydantic model
β”‚   β”‚   β”‚   └── template.py         # Template Pydantic model
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”œβ”€β”€ db.py               # MongoDB operations
β”‚   β”‚   β”‚   β”œβ”€β”€ pdfgen.py           # PDF generation service
β”‚   β”‚   β”‚   └── storage.py          # File storage service
β”‚   β”‚   β”œβ”€β”€ templates/
β”‚   β”‚   β”‚   β”œβ”€β”€ preset_minimal.html # Minimal template
β”‚   β”‚   β”‚   β”œβ”€β”€ preset_promo.html   # Promotional template
β”‚   β”‚   β”‚   └── preset_multi.html   # Multi-column template
β”‚   β”‚   └── main.py                 # FastAPI app entry point
β”‚   └── requirements.txt
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ UploadCSV.jsx       # CSV upload component
β”‚   β”‚   β”‚   β”œβ”€β”€ OfferPreview.jsx    # Offer grid component
β”‚   β”‚   β”‚   β”œβ”€β”€ TemplateManager.jsx # Template selection
β”‚   β”‚   β”‚   └── PDFGenerator.jsx    # PDF generation
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   β”œβ”€β”€ Dashboard.jsx       # Main dashboard
β”‚   β”‚   β”‚   └── Settings.jsx        # Settings page
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   └── api.js              # API calls
β”‚   β”‚   β”œβ”€β”€ App.jsx                 # Main app component
β”‚   β”‚   β”œβ”€β”€ main.jsx                # React entry point
β”‚   β”‚   └── index.css               # Global styles
β”‚   β”œβ”€β”€ vite.config.js
β”‚   β”œβ”€β”€ tailwind.config.js
β”‚   └── package.json
└── README.md

πŸš€ Quick Start

Backend Setup

  1. Install Dependencies
cd backend
pip install -r requirements.txt
  1. Configure MongoDB
# Default: mongodb://localhost:27017
# Or set env variable: MONGODB_URI=your_mongodb_url
  1. Run Server
python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

Backend will be available at http://localhost:8000 API docs available at http://localhost:8000/docs

Frontend Setup

  1. Install Dependencies
cd frontend
npm install
  1. Start Development Server
npm run dev

Frontend will be available at http://localhost:5173

  1. Build for Production
npm run build

πŸ“ API Endpoints

Offers

  • POST /offers/upload-csv - Upload CSV file
  • GET /offers?skip=0&limit=50 - Get offers with pagination
  • GET /offers/{offer_id} - Get single offer

Templates

  • POST /templates/upload - Upload custom template ZIP
  • GET /templates - Get all templates
  • GET /templates/preset - Get preset templates only
  • GET /templates/{template_id} - Get single template

PDF Generation

  • POST /pdf/generate - Generate PDF with selected offers
  • POST /pdf/preview - Preview PDF as HTML

πŸ“Š CSV Format

Expected columns in CSV file:

product_id,product_name,brand,offer_type,offer_details,price,mrp,valid_till
PRD-001,Wireless Headphones,TechBrand,Discount,20% off,4999,6999,2025-12-31
PRD-002,Smart Watch,TechBrand,Seasonal,Limited Time,7999,9999,2025-12-15

🎨 Preset Templates

  1. Minimal Clean - Simple 4-column grid with essential info
  2. Promotional Bold - Eye-catching design with vibrant colors
  3. Detailed Multi-Column - 2-column layout with pricing breakdown

πŸ“¦ Custom Templates

Upload a ZIP file containing:

  • index.html - Main template file with Jinja2 syntax
  • styles.css (optional) - Additional CSS
  • Other assets (images, fonts, etc.)

Use {{ offer.field }} in templates to reference offer data:

  • {{ offer.product_name }}
  • {{ offer.brand }}
  • {{ offer.price }}
  • {{ offer.mrp }}
  • {{ offer.valid_till }}
  • {{ offer.offer_type }}
  • {{ offer.offer_details }}

πŸ”§ Environment Variables

Backend (.env)

MONGODB_URI=mongodb://localhost:27017
ENVIRONMENT=development
DEBUG=true

Frontend (.env)

VITE_API_URL=http://localhost:8000

πŸ“š Usage Workflow

  1. Upload CSV - Select and upload your offers CSV file
  2. Preview Offers - View uploaded offers in grid format
  3. Select Offers - Check which offers to include in PDF
  4. Choose Template - Select a preset or upload custom template
  5. Generate PDF - Click to create PDF with selected offers
  6. Download - Download the generated PDF to print

🎯 Key Features Details

CSV Upload

  • Validates data against Pydantic models
  • Skips invalid rows and provides feedback
  • Shows preview of first 5 uploaded offers
  • Returns count of successfully inserted documents

Offer Grid

  • Responsive grid with auto-fill columns
  • Checkbox selection for batch operations
  • Pagination support for large datasets
  • Shows key offer information

Template System

  • Preset templates with professional designs
  • Custom template upload via ZIP files
  • Live template selection with instant preview
  • Layout options (page size, offers per page, orientation)

PDF Generation

  • Server-side rendering using Jinja2
  • Async processing with pyppeteer
  • Configurable page layout and spacing
  • Download links for generated PDFs

πŸ› Troubleshooting

MongoDB Connection Issues

# Ensure MongoDB is running
mongod

# Check connection string in .env
MONGODB_URI=mongodb://localhost:27017

PDF Generation Fails

  • Ensure Node.js dependencies are installed
  • Check pyppeteer installation
  • Verify sufficient disk space for temporary files

CORS Errors

  • Backend CORS is configured for localhost:3000 and localhost:5173
  • Add additional origins in app/main.py if needed

Missing Preset Templates

  • Preset templates are auto-initialized on server startup
  • Check database connection and permissions

🚒 Production Deployment

  1. Build Frontend
cd frontend
npm run build
  1. Set Environment Variables
ENVIRONMENT=production
MONGODB_URI=your_production_mongodb
FRONTEND_URL=your_frontend_url
  1. Run Backend
uvicorn app.main:app --host 0.0.0.0 --port 8000
  1. Serve Frontend
  • Deploy frontend/dist to static file server
  • Or use FastAPI static file serving

πŸ“„ License

MIT

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“§ Support

For issues or questions, please open an issue on GitHub.


AOPS - Making offer tag printing automated and effortless! 🏷️

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •