A fast, secure e-commerce application built with Go, featuring real-time updates and type-safe templates.
- Go 1.25.3 - Core programming language
- Chi Router v5.2.3 - HTTP routing and middleware
- MySQL 9.5.0 - Database with connection pooling
- Stripe API v72.122.0 - Payment processing
- SCS v2.9.0 - Session management with MySQL backend
- Server-Sent Events (SSE) - Real-time server-to-client notifications
- Templ v0.3.960 - Type-safe Go templates compiled to Go code
- Datastar (Open Source) - Reactive UI framework with data-binding
- Bootstrap 5.3.3 - CSS framework
- SweetAlert2 - Beautiful alert dialogs
- Stripe.js - Client-side payment processing
- CORS middleware - Environment-based origin control
- Session-based authentication - Secure user sessions
- Panic recovery - Graceful error handling
- Request logging - Comprehensive audit trail
The application consists of three services:
- Web Service (
cmd/web) - Main frontend application (port 4000) - API Service (
cmd/api) - RESTful API backend (port 4001) - Invoice Service (
cmd/micro/invoice) - Microservice for invoice generation
- β Single & recurring payment processing via Stripe
- β Real-time logout notifications using SSE
- β Admin dashboard for user/order management
- β Virtual terminal for manual charges
- β Password reset functionality
- β Type-safe templates with compile-time validation
- β Database connection pooling (25 connections, 5min lifetime)
- β Comprehensive middleware (panic recovery, logging, CORS)
- Go 1.25+
- MySQL 9.5+ (or compatible)
- Stripe account (test keys for development)
- Templ CLI (
go install github.com/a-h/templ/cmd/templ@latest)
-
Clone the repository
git clone https://github.com/carlomunguia/maize.git cd maize -
Install dependencies
go mod download go mod verify
-
Set up MySQL database
# Create database and user mysql -u root -p << EOF CREATE DATABASE maize; CREATE USER 'maize'@'localhost' IDENTIFIED BY 'maize'; GRANT ALL PRIVILEGES ON maize.* TO 'maize'@'localhost'; FLUSH PRIVILEGES; EOF
-
Run database migrations
# Install migrate tool brew install golang-migrate # Run migrations migrate -path migrations -database "mysql://maize:maize@tcp(localhost:3306)/maize" up
-
Configure environment variables
# Create .env file in project root cat > .env << EOF SECRET_KEY=$(openssl rand -base64 32) STRIPE_KEY=pk_test_your_publishable_key STRIPE_SECRET=sk_test_your_secret_key EOF
# Web application
go build -o dist/web ./cmd/web
# API service
go build -o dist/api ./cmd/api
# Invoice microservice
go build -o dist/invoice ./cmd/micro/invoice# Generate Go code from .templ files
templ generate
# Watch mode for development
templ generate --watch# Web service (port 4000)
./dist/web
# API service (port 4001)
./dist/api
# Or run in background with logging
nohup ./dist/web > /tmp/web.log 2>&1 &
nohup ./dist/api > /tmp/api.log 2>&1 &./dist/web \
-port 4000 \
-env development \
-dsn "maize:maize@tcp(localhost:3306)/maize?parseTime=true&tls=false" \
-api "http://localhost:4001" \
-frontend "http://localhost:4000"go test ./...# Vet code
go vet ./...
# Check for unused code
staticcheck -checks=U1000 ./...# Public pages
curl http://localhost:4000/
curl http://localhost:4000/login
curl http://localhost:4000/plans/bronze
# Admin pages (requires authentication)
curl http://localhost:4000/admin/all-users
curl http://localhost:4000/admin/all-sales.
βββ cmd/
β βββ api/ # API service
β βββ micro/invoice/ # Invoice microservice
β βββ web/ # Web frontend
β βββ *.templ # Templ templates (16 files)
β βββ handlers.go
β βββ routes.go
β βββ main.go
βββ internal/
β βββ cards/ # Payment card handling
β βββ driver/ # Database driver
β βββ encryption/ # Encryption utilities
β βββ models/ # Database models
β βββ urlsigner/ # URL signing for security
β βββ validator/ # Input validation
βββ migrations/ # Database migrations (17 files)
βββ static/ # CSS, JS, images
βββ go.mod
- users - User accounts with authentication
- customers - Customer information for orders
- maize - Products catalog (2 seeded products)
- orders - Order tracking
- transactions - Payment transactions
- transaction_statuses - Payment status tracking
- statuses - Order status definitions
- tokens - Password reset tokens
- sessions - User session data
GET /- Home pageGET /login- Login pagePOST /login- Authenticate userGET /logout- Logout (broadcasts SSE event)GET /maize/{id}- Product purchase pageGET /plans/bronze- Subscription plan pageGET /admin/*- Admin dashboard (authenticated)GET /sse- Server-Sent Events streamPOST /internal/broadcast- Trigger SSE broadcasts
POST /api/payment-intent- Create Stripe payment intentPOST /api/authenticate- User authenticationPOST /api/admin/all-users- List all usersPOST /api/admin/all-sales- List all salesPOST /api/admin/refund- Process refundPOST /api/forgot-password- Send password reset emailPOST /api/reset-password- Reset user password
- Make changes to .templ files
- Generate Go code:
templ generate - Build:
go build -o dist/web ./cmd/web - Restart server:
pkill web && ./dist/web - Test endpoints:
curl http://localhost:4000/
# Build with optimizations
CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o dist/web ./cmd/web
CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o dist/api ./cmd/api- Set
STRIPE_KEYandSTRIPE_SECRETwith production keys - Use strong
SECRET_KEY(32+ bytes) - Configure MySQL with SSL in production
- Set proper CORS origins in production mode
- Use reverse proxy (nginx/caddy) for HTTPS
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Run
go vetandstaticcheck - Submit a pull request
See LICENSE file for details.
- Chi Router - HTTP routing
- Templ - Type-safe templates
- Datastar - Reactive UI framework
- Stripe - Payment processing
- SCS - Session management