Overview
This guide covers the essential steps for deploying your Go + React scaffold application to production, including building both frontend and backend, environment configuration, and deployment considerations.Building for Production
Backend Build
The backend uses a simple Makefile to build the Go application into a standalone binary.main in the backend directory. The build command is defined as:
Frontend Build
The frontend uses Vite to create an optimized production build.frontend/dist/ directory, optimized and minified for production.
To preview the production build locally:
Environment Setup
Backend Environment Variables
Create a production.env file in the backend/ directory:
Required Variables
- APP_ENV: Set to
productionto enable production mode - MONGODB_URI: Your production MongoDB connection string
- PORT: Server port (default: 8080)
- SESSION_KEY: Strong random secret for JWT signing (use a cryptographically secure random generator)
Optional Integration Variables
- REDIS_URL: Redis connection string for caching/sessions
- PAYPACK_CLIENT_ID: Paypack payment integration client ID
- PAYPACK_CLIENT_SECRET: Paypack API secret
- USE_PLUNK: Enable Plunk email integration
- TELEGRAM_BOT_ID: Telegram bot token for notifications
- TELEGRAM_CHAT_ID: Telegram chat ID
Frontend Environment
For frontend environment variables, create a.env.production file in the frontend/ directory:
VITE_ to the client-side code.
Deployment Strategies
Container Deployment (Docker)
Create aDockerfile for the backend:
Platform-as-a-Service (PaaS)
Common PaaS options:- Backend: Railway, Fly.io, Render, Google Cloud Run
- Frontend: Vercel, Netlify, Cloudflare Pages
- Database: MongoDB Atlas (managed MongoDB service)
Virtual Private Server (VPS)
- Build the backend binary locally or on the server
- Build the frontend and serve with nginx or Apache
- Use a process manager like
systemdto keep the backend running - Set up reverse proxy (nginx) to route traffic to the backend
Database Deployment
MongoDB Atlas (Recommended)
MongoDB Atlas provides a fully managed MongoDB service:- Create a cluster on MongoDB Atlas
- Whitelist your application server IPs
- Create a database user with appropriate permissions
- Copy the connection string to your
MONGODB_URIenvironment variable
Self-Hosted MongoDB
If self-hosting MongoDB:Health Checks
Implement health check endpoints for monitoring:Pre-Deployment Checklist
- Build and test both frontend and backend locally
- Run
make testfor backend tests - Run
npm run lintfor frontend code quality - Set all required environment variables
- Configure CORS for production domain
- Set up SSL/TLS certificates
- Configure logging and monitoring
- Set up database backups
- Test with production-like data
- Review security settings
Next Steps
Production Configuration
Configure security, performance, and optimization settings
Contributing
Learn how to contribute to the project