Got it. With monthly stock changes and variant-specific price (size+color), you can keep the storefront static-fast and still have a WooCommerce-like “easy editing” experience for the parts that change (variants/stock/prices).
Below is a step-by-step plan (no coding), with a clear day-to-day workflow.
- Storefront (static, super fast): product pages, category pages, home, checkout page UI)
- API (dynamic): variants + prices + stock, and order creation
This makes browsing fast and keeps your small server safe.
yourdomain.com→ storefront (static)api.yourdomain.com→ Koyeb Go Fiber API
(You can do single domain routing later, but this is simpler and more reliable.)
Pick one:
- Recommended: Cloudflare Pages (or any static host behind Cloudflare)
- Alternative: serve static from Koyeb (works, but slower and puts load on your tiny server)
Cloudflare Pages is just “a place to upload HTML/CSS/JS” so Cloudflare can serve it fast globally.
You want WooCommerce-like ease for variants/stock/price.
Use a hybrid model:
A) Product content (rare changes): name, description, images, category, slug
→ keep this in a simple file (like products.json) used to build static pages.
B) Variant data (frequent-ish changes): size, color, variant price, stock → keep this in Postgres and edit via a small admin dashboard.
Why this fits you:
- You only update stock about once per month
- But variant pricing and stock should be editable without rebuilding pages
Per product:
- Sizes: S, M, L
- Colors: 3 colors
- Total variants per product: up to 9 Each variant has:
- price
- stock count
- active/inactive (hide sold out or discontinued)
Generate these pages:
- Home
- Category listing pages
- Product pages (
/p/slug) - Checkout page
- Thank-you page
- Policies pages
These pages:
- load instantly
- are cached by Cloudflare
- do not hit your Koyeb server for browsing
Each product page should:
- show product details from static HTML
- load variants (size/color/price/stock) from the API with one lightweight request
- render selectors (size/color dropdowns/buttons)
- show the correct price based on selected variant
- show stock availability (or just “in stock / out of stock”)
This keeps pages static-fast while still being flexible.
- “Get variants for a product”
- “Create order (COD)”
- Optional: “Admin CRUD for products/variants”
- Optional: “Order list + update status” (admin)
That’s it.
At checkout:
-
customer selects a variant (size+color)
-
API verifies:
- variant exists
- variant is active
- stock is enough (if you enforce stock)
- server calculates totals (never trust browser price)
-
API stores an order snapshot (variant name/price at time of order)
Pages you need (keep it basic HTML forms):
-
Products
- list products
- enable/disable product
-
Variants per product
- add variants (size/color combos)
- set price per variant
- set stock per variant
- enable/disable variant
-
Orders
- list orders
- update status (new / confirmed / shipped / canceled)
This gives you the “Woo feel” for daily operations without building a heavy CMS.
Use one of these:
- Best & easiest: Cloudflare Access (protect
/admin/*with login) - Or at minimum: strong password + basic auth + IP restriction
Cloudflare caches:
- HTML pages
- CSS/JS
- product pages So browsing stays extremely fast.
Variants don’t change often (monthly), so you can:
- Cache “variants JSON” for 10–60 minutes
- When you update variants/stock, you can purge that one endpoint cache (or just wait)
Result:
- product pages still feel instant
- API is barely hit
POST /ordersshould never be cached- Add rate limiting for spam protection
- Open admin
- Choose product → variants
- Update stock numbers (and prices if needed)
- Save
- (Optional) purge cached variants endpoint
✅ No redeploy needed.
- Admin → product → variants
- Edit price
- Save
- Optional cache purge
✅ No redeploy needed.
- Add product content (name/slug/images/category) in your product file
- Rebuild + deploy static storefront
- Admin: add variants for that product (9 combos) with stock + price
✅ Simple, predictable.
- Run migrations (only needed if new migrations were added)
- Import products into the database
go run ./cmd/migrate
go run ./cmd/import-productsOptional: deactivate products not present in products.json
go run ./cmd/import-products --deactivate-missing- Admin: disable product (or disable all variants)
- Optionally remove product from static file later
- Rebuild when convenient
✅ Immediate removal from checkout via “inactive”.
You won’t get Woo’s huge plugin ecosystem and themes for free.
But with this plan you do get the core “store owner convenience” you care about:
- Add/edit variants (size/color)
- Set price per variant
- Set stock per variant
- Manage orders
…without slowing the site down or overloading your tiny server.
This repository implements the plan above with the following enhancements:
Core Architecture:
- Static storefront hosted on Cloudflare Pages (
bhomanshah.com) - Tiny Go API on Koyeb (
api.bhomanshah.com) using Fiber framework - MySQL database (TiDB Cloud compatible)
Product Management:
- Products stored in
products.json(static content) - Variants stored in database (dynamic pricing/stock)
- Admin dashboard for CRUD operations on products and variants
E-commerce Features:
- Product catalog with variants (size/color combinations)
- Shopping cart (client-side)
- COD order creation with stock validation
- Order management (admin)
Security & Performance:
- JWT-based admin authentication (secure, expiring tokens)
- Rate limiting on order creation (5/min per IP)
- HTTP caching for variants (30 minutes)
- Input validation and sanitization
The admin panel uses JWT (JSON Web Tokens) for secure authentication:
-
Login Process:
- Admin enters API key on
/admin/login - Server validates key and returns JWT token (expires in 24 hours)
- Token stored securely in browser localStorage
- Admin enters API key on
-
API Access:
- All admin API calls include
Authorization: Bearer <token>header - Server validates token signature and expiry on each request
- Automatic logout on expired tokens
- All admin API calls include
-
Backward Compatibility:
- Legacy
X-API-Keyheader still supported as fallback
- Legacy
Environment Setup:
# Copy environment file
cp .env.example .env
# Configure required variables
# - DATABASE_URL: MySQL connection string
# - ADMIN_SECRET: Your admin API key
# - JWT_SECRET: Random string for JWT signing (min 32 chars)
# - CORS_ORIGIN: Your frontend domainBuild & Run:
# Build the application
go build -o koyeb-go .
# Run locally
./koyeb-go
# Or deploy to Koyeb with environment variablesDatabase Setup:
# Run migrations
go run ./cmd/migrate
# Import products from products.json
go run ./cmd/import-productsPublic Endpoints:
GET /api/products- List active productsGET /api/products/:slug/variants- Get variants for a productPOST /api/orders- Create COD order
Admin Endpoints:
POST /admin/api/login- Authenticate and get JWT tokenGET /admin/api/products- List all products (including inactive)POST /admin/api/products- Create productPUT /admin/api/products/:id- Update productPATCH /admin/api/products/:id- Toggle product active statusGET /admin/api/products/:id/variants- List variants for productPOST /admin/api/products/:id/variants- Create variantPATCH /admin/api/variants/:id- Update variantDELETE /admin/api/variants/:id- Delete variantGET /admin/api/orders- List orders with filtersGET /admin/api/orders/:id- Get order detailsPATCH /admin/api/orders/:id- Update order statusPOST /admin/api/cache/purge- Purge cache
Key environment variables:
| Variable | Description | Example |
|---|---|---|
PORT |
Server port | 8080 |
DATABASE_URL |
MySQL connection | user:pass@tcp(host:3306)/db |
CORS_ORIGIN |
Frontend domain | https://bhomanshah.com |
ADMIN_SECRET |
Admin API key | your-secret-key |
JWT_SECRET |
JWT signing key | random-32-char-string |
JWT_EXPIRY_HOURS |
Token expiry | 24 |
- Static Content: All product pages served from Cloudflare CDN
- API Caching: Variant data cached for 30 minutes
- Database Indexing: Optimized queries for products, variants, orders
- Rate Limiting: Prevents abuse on order creation
- Input Validation: Prevents malformed data and XSS attacks
Project Structure:
├── main.go # Server entry point
├── internal/
│ ├── config/ # Configuration management
│ ├── database/ # Database connection
│ ├── handlers/ # HTTP handlers
│ ├── middleware/ # Custom middleware
│ ├── models/ # Data models
│ ├── repository/ # Database operations
│ └── validator/ # Input validation
├── cloudflare-pages-frontend/ # Static frontend
├── migrations/ # Database schema
└── cmd/ # CLI tools (migrate, import)
Adding New Features:
- Define models in
internal/models/ - Add repository methods in
internal/repository/ - Create handlers in
internal/handlers/ - Add routes in
main.go - Update frontend as needed
This implementation successfully delivers the "static-fast storefront + tiny API" vision while providing WooCommerce-like admin capabilities for managing variants and orders.