Skip to content

AditthyaSS/DynQR

Repository files navigation

dynQR - Open Source Dynamic QR Platform

dynQR Logo

Create QR codes that can be updated anytime without reprinting

Next.js TypeScript Supabase License


🎯 What is Dynamic QR?

Unlike static QR codes that point directly to a URL, dynamic QR codes point to a redirect endpoint. This means you can change where the QR leads without printing a new code.

Traditional Static QR:
[QR Code] β†’ https://example.com  ❌ Can't change

Dynamic QR (dynQR):
[QR Code] β†’ https://app.com/qr/abc123 β†’ https://example.com  βœ… Update anytime!
How dynQR Works
One QR code, multiple destinations - change anytime without reprinting!

Perfect For:

  • 🍽️ Restaurants - Update menus without reprinting table stickers
  • πŸŽ‰ Events - Change event details after flyers are distributed
  • πŸ“¦ Products - Update product pages without new packaging
  • πŸͺ Retail - Rotate promotional offers with the same QR

πŸ—οΈ How Prototype Works - Architecture

flowchart TB
    subgraph USER["πŸ‘€ User Flow"]
        A[πŸ“± Scan QR Code] --> B[🌐 GET /qr/abc123]
    end
    
    subgraph NEXTJS["⚑ Next.js App"]
        B --> C{Active?}
        C -->|Yes| D[βœ… HTTP 302 Redirect]
        C -->|No| E[❌ Show Error Page]
    end
    
    subgraph SUPABASE["πŸ—„οΈ Supabase"]
        C -.->|Query| F[(PostgreSQL)]
        F -.->|Response| C
        D -.->|Update scan_count| F
    end
    
    subgraph DASHBOARD["πŸ“Š Dashboard"]
        G[πŸ” Auth User] --> H[Create/Edit QR]
        H --> F
        G --> I[View Analytics]
        F --> I
    end
    
    D --> J[🎯 Destination URL]
    
    style USER fill:#e1f5fe
    style NEXTJS fill:#fff3e0
    style SUPABASE fill:#e8f5e9
    style DASHBOARD fill:#f3e5f5
Loading

Architecture Components

Component Technology Purpose
Frontend Next.js 14 + React Server-side rendering, dynamic routes
API Layer Next.js API Routes CRUD operations, QR generation
Database Supabase PostgreSQL Store QR codes, analytics, user data
Authentication Supabase Auth User login, signup, session management
QR Engine qrcode npm package Generate QR code images on-demand

Request Flow

1. πŸ“± User scans QR β†’ Points to: https://app.com/qr/abc123
                          ↓
2. ⚑ Next.js Route β†’ /qr/[shortId]/page.tsx handles request
                          ↓
3. πŸ—„οΈ Database Query β†’ SELECT * FROM qr_codes WHERE short_id = 'abc123'
                          ↓
4. πŸ”€ Decision Point β†’ Is code active AND exists?
         ↓                              ↓
       βœ… YES                         ❌ NO
         ↓                              ↓
5a. πŸ“Š Update Stats           5b. 🚫 Show Error
    (scan_count++)                 (404 or inactive)
         ↓
6. 🎯 HTTP 302 Redirect β†’ User lands on current_url

Security Layers

  • Row Level Security (RLS) - Users can only access their own QR codes
  • Authenticated Routes - Dashboard requires login via Supabase Auth
  • Public Redirect - /qr/[shortId] is public for scanning without login
  • Service Role Key - Used only in secure API routes for privileged operations

✨ Features

  • βœ… Unlimited QR Codes - Create as many as you need, forever free
  • βœ… Instant URL Updates - Change destinations in seconds
  • βœ… Scan Analytics - Track scan counts and last scan times
  • βœ… Active/Inactive Toggle - Deactivate QR codes without deleting
  • βœ… High-Quality Downloads - PNG exports with error correction
  • βœ… Mobile Responsive - Works on all devices
  • βœ… 100% Open Source - MIT licensed, fork and modify freely

πŸ› οΈ Tech Stack

Category Technology
Frontend Next.js 14 (App Router)
Language TypeScript (Strict Mode)
Styling Tailwind CSS
UI Components shadcn/ui + Radix UI
Backend Next.js API Routes
Database Supabase (PostgreSQL)
Authentication Supabase Auth
QR Generation qrcode npm package

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • npm or yarn
  • A Supabase account (free tier works!)

1. Clone the Repository

git clone https://github.com/AditthyaSS/DynQR.git
cd DynQR

2. Install Dependencies

npm install

3. Set Up Supabase

  1. Create a new project at supabase.com
  2. Go to SQL Editor and run the contents of schema.sql
  3. Go to Settings β†’ API and copy your credentials

4. Configure Environment Variables

cp .env.local.example .env.local

Edit .env.local with your Supabase credentials:

NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key

5. Run the Development Server

npm run dev

Open http://localhost:3000 in your browser.


πŸ“ Project Structure

dynqr/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ (auth)/           # Auth pages (login, signup, etc.)
β”‚   β”‚   β”œβ”€β”€ api/              # API routes
β”‚   β”‚   β”‚   β”œβ”€β”€ codes/        # QR CRUD endpoints
β”‚   β”‚   β”‚   └── generate-qr/  # QR image generation
β”‚   β”‚   β”œβ”€β”€ dashboard/        # Protected dashboard pages
β”‚   β”‚   β”œβ”€β”€ qr/[shortId]/     # Public redirect handler
β”‚   β”‚   └── page.tsx          # Landing page
β”‚   β”œβ”€β”€ components/ui/        # shadcn/ui components
β”‚   └── lib/
β”‚       β”œβ”€β”€ supabase/         # Supabase clients
β”‚       β”œβ”€β”€ types/            # TypeScript types
β”‚       └── utils/            # Utility functions
β”œβ”€β”€ schema.sql                # Database schema
└── .env.local.example        # Environment template

πŸ” How the Redirect Works

  1. User scans QR code pointing to https://your-app.com/qr/abc123
  2. /qr/[shortId]/page.tsx receives the request
  3. Server queries database for short_id = abc123
  4. If active, increments scan count and redirects (HTTP 302) to current_url
  5. If inactive or not found, shows appropriate error page

This redirect is public - no authentication required for scanning.


🌐 Deployment

Google IDX

This project includes .idx/dev.nix for easy deployment to Google IDX:

  1. Import the project to Google IDX
  2. Add environment variables in IDX settings
  3. The preview URL will be your QR base URL

Vercel

npm i -g vercel
vercel

Add your environment variables in the Vercel dashboard.

Other Platforms

Works with any platform that supports Next.js 14:

  • Netlify
  • Railway
  • Render
  • Self-hosted with npm run build && npm start

πŸ“Š Database Schema

The qr_codes table stores all QR code data:

Column Type Description
id UUID Primary key
user_id UUID Owner (references auth.users)
short_id VARCHAR(8) Unique redirect identifier
name VARCHAR(255) Display name
current_url TEXT Destination URL
description TEXT Optional description
scan_count INTEGER Total number of scans
is_active BOOLEAN Whether redirects work
created_at TIMESTAMP Creation time
updated_at TIMESTAMP Last update time
last_scanned_at TIMESTAMP Most recent scan

Row Level Security (RLS) ensures users can only access their own QR codes.


🀝 Contributing

Contributions are welcomed! πŸŽ‰

Whether it's bug fixes, new features, documentation improvements, or ideas - we'd love your help!

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Ideas for Contributions:

  • 🎨 Custom QR code colors/logos
  • πŸ“Š Advanced analytics dashboard
  • πŸ”— Bulk QR code creation
  • πŸ“± PWA support
  • 🌍 Internationalization (i18n)

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments


Made with ❀️ for the open source community

⭐ Star this repo if you find it useful!

About

A modern micro-SaaS for dynamic QR codes with editable redirects and real-time analytics πŸš€

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors