A full-stack URL shortener application with a high-performance Go backend and React frontend.
- User Authentication: JWT-based authentication with secure password hashing
- URL Shortening: Generate short URLs with customizable expiration dates
- Redis Caching: Fast URL resolution with 30-minute cache TTL
- MySQL Database: Persistent storage using GORM ORM
- Metrics Dashboard: Built-in monitoring endpoint
- Security: HTTP-only cookies, CORS protection, and secure token handling
go-url-shortener/
├── api/ # Go backend (Fiber framework)
├── client/ # React frontend (Vite + TypeScript)
└── docker-compose.yml
- Framework: Fiber v2
- Database: MySQL with GORM
- Cache: Redis
- Authentication: JWT (JSON Web Tokens)
- Password Hashing: bcrypt
- Framework: React 19
- Build Tool: Vite
- Language: TypeScript
- Styling: Tailwind CSS
- Go 1.24.4 or higher
- Node.js and npm
- MySQL 8.0 or higher
- Redis server
- Docker and Docker Compose (optional)
Using Docker Compose:
docker-compose up -dThis starts MySQL on port 3306.
cd api
# Install dependencies
go mod download
# Create .env file (see api/README.md for details)
# Set environment variables:
# - APP_PORT=:8080
# - MYSQL_HOST=localhost:3306
# - MYSQL_USER=root
# - MYSQL_PASS=root
# - MYSQL_DB=url_shortener
# - REDIS_ADDR=localhost:6379
# - JWT_SECRET=your-secret-key
# Run the server
go run main.goThe API will be available at http://localhost:8080
cd client
# Install dependencies
npm install
# Start development server
npm run devThe frontend will be available at http://localhost:3000 (or the port Vite assigns)
POST /api/v1/create-user- Register new userPOST /api/v1/login- User loginPOST /api/v1/logout- User logoutGET /:short- Resolve short URL (redirects to original)
POST /api/v1/shorten- Create short URLDELETE /api/v1/delete- Delete short URL
GET /metrics- Application metrics dashboard
For detailed API documentation, see api/README.md
- Password hashing with bcrypt (cost factor 10)
- JWT tokens with HS256 signing
- HTTP-only cookies to prevent XSS
- CORS protection
- Secure cookies in production
- Transaction-safe database operations
config/- Database and Redis configurationmodels/- Data models (User, URL)routes/- API route handlersutils/- Utility functions (JWT, logger, env parser)
src/- React application source code- Built with Vite for fast development and optimized builds
The project includes a docker-compose.yml file for easy setup of MySQL. Redis can be added similarly or run separately.
See api/README.md for complete environment variable documentation.
- Backend API Documentation - Detailed API documentation, endpoints, and setup instructions
Contributions are welcome! Feel free to submit issues or pull requests.