A full-stack QR code generation platform with a robust, well-tested Go backend API and a modern Next.js TypeScript frontend.
- Backend: Go API with comprehensive testing (
/root directory) - Frontend: Next.js + TypeScript UI (
/frontenddirectory)
- Multiple Formats: Generate QR codes as PNG or SVG
- Configurable Size: Customize dimensions (64-2048 pixels)
- Error Correction Levels: Support for L, M, Q, and H levels
- Base64 Encoding: Returns QR codes as base64-encoded strings
- Comprehensive Testing: Unit and integration tests with excellent coverage
- RESTful API: Clean, simple HTTP endpoints
- Health Check: Built-in health monitoring endpoint
# Install Go dependencies
go mod download
# Run the backend server
go run main.goThe server starts on port 8080 by default. Set the PORT environment variable to use a different port:
PORT=3000 go run main.go# Navigate to frontend directory
cd frontend
# Install dependencies
npm install
# Run the development server
npm run devOpen http://localhost:3000 to use the QR code generator UI.
-
Terminal 1 - Run the backend:
go run main.go
-
Terminal 2 - Run the frontend:
cd frontend && npm run dev
-
Open http://localhost:3000 in your browser
Generate a QR code with custom configuration.
Endpoint: POST /api/qr/generate
Request Body:
{
"content": "https://example.com",
"size": 512,
"error_correction_level": "H",
"format": "png"
}Parameters:
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
content |
string | Yes | - | Data to encode in the QR code |
size |
integer | No | 256 | Width/height in pixels (64-2048) |
error_correction_level |
string | No | "M" | L (~7%), M (~15%), Q (~25%), H (~30%) |
format |
string | No | "png" | Output format: "png" or "svg" |
Note: SVG output dimensions are calculated to fit the QR code modules plus quiet zone. The actual size may be slightly smaller than requested to maintain proper module proportions.
Response:
{
"data": "iVBORw0KGgoAAAANSUhEUgAA...",
"format": "png",
"size": 512
}Response Fields:
data: Base64-encoded QR code imageformat: Output format usedsize: Actual size of the generated QR code
Check the API health status.
Endpoint: GET /health
Response:
{
"status": "healthy"
}curl -X POST http://localhost:8080/api/qr/generate \
-H "Content-Type: application/json" \
-d '{"content":"https://example.com"}'curl -X POST http://localhost:8080/api/qr/generate \
-H "Content-Type: application/json" \
-d '{
"content": "https://github.com/edwardwieczorek/qr-api",
"size": 1024,
"error_correction_level": "H",
"format": "png"
}'curl -X POST http://localhost:8080/api/qr/generate \
-H "Content-Type: application/json" \
-d '{
"content": "mailto:test@example.com",
"format": "svg"
}'curl -X POST http://localhost:8080/api/qr/generate \
-H "Content-Type: application/json" \
-d '{"content":"https://example.com"}' \
| jq -r '.data' \
| base64 -d > qrcode.pngWiFi Network:
{
"content": "WIFI:T:WPA;S:NetworkName;P:password;;",
"error_correction_level": "H"
}Contact Information (vCard):
{
"content": "BEGIN:VCARD\nVERSION:3.0\nFN:John Doe\nTEL:+1234567890\nEND:VCARD"
}Plain Text:
{
"content": "Hello, World!"
}The API returns appropriate HTTP status codes and error messages:
400 Bad Request:
- Empty content
- Invalid size (outside 64-2048 range)
- Invalid format (not "png" or "svg")
- Invalid error correction level (not L, M, Q, or H)
405 Method Not Allowed:
- Using GET instead of POST on generation endpoint
413 Request Entity Too Large:
- Content exceeds maximum length (4296 characters)
Error Response Format:
{
"error": "Bad Request",
"message": "content cannot be empty"
}Run all tests:
go test -v ./...Run tests with coverage:
go test -cover ./...Generate coverage report:
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.outqr-api/
├── main.go # Application entry point
├── integration_test.go # Integration tests
├── internal/
│ ├── handlers/ # HTTP handlers
│ │ ├── qr.go
│ │ ├── qr_test.go
│ │ └── routes.go
│ ├── models/ # Data models
│ │ └── qr.go
│ └── qr/ # QR generation logic
│ ├── generator.go
│ └── generator_test.go
├── go.mod
└── README.md
- github.com/skip2/go-qrcode - QR code generation library
PORT: Server port (default: 8080)
- Default Size: 256 pixels
- Min Size: 64 pixels
- Max Size: 2048 pixels
- Max Content Length: 4296 characters
- Default Error Correction: M (Medium)
The codebase is organized for easy extension:
- Add new endpoints: Update
internal/handlers/routes.go - Add business logic: Update or create new files in
internal/qr/ - Add models: Update
internal/models/qr.go - Write tests: Add corresponding test files
- All packages have comprehensive unit tests
- Integration tests cover full request/response cycles
- Error handling tested with various edge cases
- Input validation with clear error messages
MIT
Potential features for frontend integration:
- CORS support for browser-based clients
- Rate limiting
- Caching for frequently generated QR codes
- WebSocket support for real-time generation
- Batch generation endpoint
- QR code analytics
- Custom color schemes
- Logo/image overlay support