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!
- π½οΈ 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
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
| 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 |
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
- 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
- β 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
| 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 |
- Node.js 18+
- npm or yarn
- A Supabase account (free tier works!)
git clone https://github.com/AditthyaSS/DynQR.git
cd DynQRnpm install- Create a new project at supabase.com
- Go to SQL Editor and run the contents of
schema.sql - Go to Settings β API and copy your credentials
cp .env.local.example .env.localEdit .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-keynpm run devOpen http://localhost:3000 in your browser.
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
- User scans QR code pointing to
https://your-app.com/qr/abc123 /qr/[shortId]/page.tsxreceives the request- Server queries database for
short_id = abc123 - If active, increments scan count and redirects (HTTP 302) to
current_url - If inactive or not found, shows appropriate error page
This redirect is public - no authentication required for scanning.
This project includes .idx/dev.nix for easy deployment to Google IDX:
- Import the project to Google IDX
- Add environment variables in IDX settings
- The preview URL will be your QR base URL
npm i -g vercel
vercelAdd your environment variables in the Vercel dashboard.
Works with any platform that supports Next.js 14:
- Netlify
- Railway
- Render
- Self-hosted with
npm run build && npm start
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.
Contributions are welcomed! π
Whether it's bug fixes, new features, documentation improvements, or ideas - we'd love your help!
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- π¨ Custom QR code colors/logos
- π Advanced analytics dashboard
- π Bulk QR code creation
- π± PWA support
- π Internationalization (i18n)
This project is licensed under the MIT License - see the LICENSE file for details.
- Next.js - The React Framework
- Supabase - Open source Firebase alternative
- shadcn/ui - Beautiful UI components
- Lucide - Beautiful icons
Made with β€οΈ for the open source community
β Star this repo if you find it useful!
