Prerequisites
Before you begin, ensure you have the following installed:Backend Requirements
- Go 1.21+: Download Go
- Docker: For running MongoDB locally
Frontend Requirements
- Node.js 18+: Download Node.js
- npm: Comes with Node.js
Optional: Install air for Go live reload during development
Setup Instructions
Backend Setup
Navigate to the backend directory and configure your environment:Edit the This command starts MongoDB in a Docker container. The database will be accessible at You should see:The backend API is now running at
Configure Environment Variables
Copy the example environment file and update it with your values:.env file with your configuration:Start MongoDB
Use Docker to run MongoDB locally:mongodb://localhost:27017.Start the Backend Server
Run the Go server:http://localhost:8080.Alternative: Live Reload with Air
Alternative: Live Reload with Air
For development with automatic reloading:If
air is not installed, the Makefile will prompt you to install it.Frontend Setup
Open a new terminal window and navigate to the frontend directory:This installs all required packages including React, TypeScript, Vite, and TailwindCSS.The frontend will start on
Install Dependencies
Start the Development Server
http://localhost:5173 (default Vite port) with hot module replacement (HMR) enabled.The Vite dev server provides instant updates when you modify your code.
Making Your First API Call
The scaffold comes with authentication endpoints ready to use. Let’s register a user and login.Register a New User
Use curl or your favorite API client to register:Expected Response:
The user is created with a
pending status by default. In a production app, you’d verify the email before activating.Login and Get JWT Token
Authenticate with the registered user:Expected Response:The response includes:
token: JWT token for authenticated requests (valid for 24 hours)status: Authentication success status- HTTP-only cookies are automatically set for secure session management
Understanding Authentication Flow
Here’s how authentication works in the scaffold:
- Password Hashing: Passwords are hashed using bcrypt with cost factor 14
- JWT Generation: Upon successful login, a JWT token is generated with the user ID
- Cookie Storage: The token is stored in HTTP-only cookies for security
- Token Expiration: Tokens expire after 24 hours
View the Backend Implementation
View the Backend Implementation
The authentication logic is in Password hashing with bcrypt cost 14:
backend/auth/controller.go:backend/auth/controller.go
backend/auth/controller.go
Common Development Commands
Here are the commands you’ll use most often during development:- Backend
- Frontend
Next Steps
Now that you have the scaffold running:Explore the Structure
Learn about the project architecture and how the pieces fit together
Add Custom Endpoints
Extend the API by adding new routes and handlers in the backend
Build the UI
Create React components using TypeScript and TailwindCSS
Deploy
Learn how to deploy your application to production
Troubleshooting
Backend won't start - MongoDB connection error
Backend won't start - MongoDB connection error
Problem:
connection refused or no reachable serversSolution:- Ensure MongoDB is running:
make docker-run - Check the
MONGODB_URIin your.envfile - Verify Docker is running:
docker ps
Frontend can't connect to backend
Frontend can't connect to backend
Problem: API calls fail with CORS errors or connection refusedSolution:
- Ensure backend is running on port 8080
- Check that CORS middleware is enabled in
main.go - Verify the API URL in your frontend code
JWT token not working
JWT token not working
Problem: Authentication fails with invalid tokenSolution:
- Ensure
SESSION_KEYis set in.env - Check that the token hasn’t expired (24 hour validity)
- Verify the token is being sent in requests
Port already in use
Port already in use
Problem:
address already in use errorSolution:- Backend: Change
PORTin.env - Frontend: Vite will automatically try the next available port
- Or kill the process using the port:
lsof -ti:8080 | xargs kill