Overview
The backend is built with Go 1.23, Echo framework, and MongoDB. It provides RESTful API endpoints for user authentication and management.Prerequisites
- Go 1.23 or higher
- MongoDB (local or Atlas)
- Make (for build commands)
Installation
1. Navigate to Backend Directory
2. Install Dependencies
The project uses Go modules. Dependencies are defined ingo.mod:
Environment Configuration
1. Create Environment File
Copy the example environment file:2. Configure Environment Variables
Edit.env with your configuration:
Application environment (
development, staging, or production)MongoDB connection string (e.g.,
mongodb://localhost:27017 or Atlas URI)Server port number (e.g.,
8080)Secret key for JWT signing and session encryption (use a strong random string)
Redis connection URL for caching (optional)
The
.env file is loaded automatically via github.com/joho/godotenv/autoload imported in main.go. Never commit this file to version control.Example Configuration
.env
Running the Server
Development Mode
Run the server with automatic reloading:go run main.go and starts the server on the configured port.
Build and Run
Build the binary and run:Live Reload (with Air)
For automatic reloading during development:This command will prompt to install Air if not already installed.
Server Initialization
The server initialization inmain.go:16-31 follows this sequence:
main.go
Middleware Stack
- Logger - Logs all HTTP requests
- Recover - Recovers from panics
- CORS - Enables cross-origin requests
Database Connection
Theconfigs.ConnectDB() function establishes MongoDB connection on startup. The database name is automatically set to {APP_ENV}-backend.
Docker Support
Run MongoDB and other dependencies with Docker:Testing
Run tests:No tests are currently implemented. When adding tests, create
*_test.go files in the appropriate packages.Project Structure
Troubleshooting
MongoDB Connection Failed
Ensure MongoDB is running and theMONGODB_URI is correct:
Port Already in Use
Change thePORT in .env to an available port:
Module Import Errors
Rungo mod tidy to clean up dependencies:
Next Steps
Authentication
Learn about JWT authentication implementation
Database
Understand MongoDB configuration and operations
User Model
Explore the User model structure and CRUD operations