A template for building web applications with a Go backend and a React frontend. It includes cookie-based Google authentication with refresh token functionality and uses Tailwind CSS and shadcn/ui for styling. The project integrates Traefik for reverse proxy management and automatic SSL certificates with Let's Encrypt for production deployments. Docker Compose is used for containerization in production. The monorepo structure uses Turborepo for efficient project management and builds.
- Features
- Getting Started
- Prerequisites
- Configuration
- Usage
- Production Deployment with Docker Compose
- API Documentation
- Project Structure
- Contributing
- License
- Go backend using Gin framework
- React frontend with TypeScript
- Tailwind CSS and shadcn/ui for styling
- Cookie-based Google OAuth authentication with refresh token support
- Traefik reverse proxy with automatic Let's Encrypt SSL certificates (production)
- Docker Compose setup for containerized production deployment
- Monorepo structure managed with Turborepo
To use this template:
-
Use the Template:
- Click the "Use this template" button at the top of this repository.
- Name your new repository and set its visibility.
- Click "Create repository from template".
-
Clone the Repository:
git clone https://github.com/yourusername/your-repo-name.git cd your-repo-name
- Node.js (v20 or later)
- Go (v1.23 or later)
- Google Cloud Platform Account (for OAuth credentials)
- Docker & Docker Compose (for production deployment)
- Domain Name (pointing to your server's IP address for production)
- Valid Email Address (for Let's Encrypt SSL certificate registration in production)
Create a .env
file in the services/backend/
directory with the following variables:
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_HOSTED_DOMAIN=
GOOGLE_REDIRECT_URL=http://localhost:5173/callback
JWT_SECRET=your_jwt_secret
HASH_KEY=your_hash_key
BLOCK_KEY=your_block_key
- For local development, set
GOOGLE_REDIRECT_URL
tohttp://localhost:5173/callback
. - Replace the placeholder values with your actual configuration.
For production deployment, create a .env
file in the project root directory with:
ACME_EMAIL=your_email@example.com
DOMAIN_NAME=yourdomain.com
- Replace
your_email@example.com
with your email. - Replace
yourdomain.com
with your domain.
Ensure your domain name points to your server's IP address for SSL certificate validation.
-
Install Dependencies:
npm install
-
Start Backend Server:
Navigate to the backend service directory and run the server:
cd services/backend go run main.go
The backend server will start on port
8080
by default. -
Start Frontend Development Server:
Open a new terminal window, navigate to the frontend service directory, and start the development server:
cd services/frontend npm install npm run dev
The frontend development server will start on
http://localhost:5173
. -
Run Tests:
npm run test
-
Build the Project:
npm run build
-
Lint Code:
npm run lint
-
Format Code:
npm run format
- The backend server expects the frontend to be running on
http://localhost:5173
. - Ensure that the
GOOGLE_REDIRECT_URL
in your backend.env
file matches the frontend URL.
For production deployment, use Docker Compose to build and run the application with Traefik for reverse proxy and automatic SSL.
- Ensure you have a domain name pointing to your server's IP address.
- Ports
80
and443
should be open and accessible.
- Set up the
.env
file in the project root with your production domain and email. - Update the
GOOGLE_REDIRECT_URL
inservices/backend/.env
tohttps://yourdomain.com/callback
.
-
Build and Start Containers:
docker-compose up --build -d
-
Access the Application:
- Frontend:
https://yourdomain.com
- Backend API:
https://yourdomain.com/api
- Frontend:
- Traefik Service:
- Reverse proxy and SSL management with Let's Encrypt.
- Frontend Service:
- Serves the React application.
- Backend Service:
- Provides the API endpoints and authentication.
Ensure all required environment variables are set in your .env
files as per the configuration steps.
sqlite_data
: Persists the SQLite database.letsencrypt
: Stores SSL certificates.
-
Stop Containers:
docker-compose down
-
Stop and Remove Volumes:
docker-compose down -v
-
View Logs:
docker-compose logs
-
Rebuild Images:
docker-compose build
-
Check Logs for Errors:
docker-compose logs
-
Verify Environment Variables:
Ensure all variables are correctly set.
-
Confirm Domain DNS:
Your domain should point to your server's IP.
-
Check Open Ports:
Ports 80 and 443 should be accessible.
GET /auth/google
: Initiate Google OAuth login.GET /auth/google/callback
: Handle OAuth callback.POST /auth/refresh
: Refresh user session.GET /auth/logout
: Log out user.
GET /api/user/profile
: Get authenticated user profile.
Note: Protected endpoints require a valid session cookie.
.
βββ services/
β βββ backend/
β β βββ auth/
β β βββ model/
β β βββ repository/
β β βββ main.go
β β βββ ...
β βββ frontend/
β βββ src/
β βββ public/
β βββ ...
βββ package.json
βββ turbo.json
βββ docker-compose.yml
βββ .env # (Production environment variables)
βββ README.md
Contributions are welcome.
-
Fork the Repository
-
Create a Branch
git checkout -b feature/your-feature
-
Make Changes
-
Commit Changes
git commit -m 'Add your feature'
-
Push to Branch
git push origin feature/your-feature
-
Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.
For support or more information, please open an issue on this repository.