A high-performance URL shortener service built with Go, PostgreSQL, and Redis, designed to efficiently shorten long URLs and provide analytics.
- URL Shortening: Convert long URLs into short, manageable links
- Custom Short Codes: Option to specify custom short codes
- Expiration Control: Set expiration time for shortened URLs
- Rate Limiting: Built-in rate limiting to prevent abuse
- Tagging System: Add tags to organize and categorize shortened URLs
- High Performance: Utilizes Redis for caching and fast redirects
- RESTful API: Clean and simple API design
- Docker Support: Easy deployment with Docker and Docker Compose
Client → Load Balancer → Go Application → Redis (Cache) → PostgreSQL (Persistence)
- Backend: Go (Golang)
- Database: PostgreSQL
- Cache: Redis
- Containerization: Docker & Docker Compose
- Docker and Docker Compose
- Clone the repository:
git clone https://github.com/ahmadrizal1st/url-shortener.git
cd url-shortener- Copy the environment file and configure:
cp .env.example .env
# Edit .env with your configuration if needed- Start the services:
docker-compose up -d
- The application will be available at
http://localhost:3000
The application uses the following environment variables:
| Variable | Description | Default Value |
|---|---|---|
DB_ADDRESS |
Redis database address | db:6379 |
DB_PASSWORD |
Redis database password | Empty |
APP_PORT |
Application server port | 8000 |
DOMAIN |
Domain for shortened URLs | localhost:5173 |
API_QUOTA |
Rate limit quota per window | 10 |
DB_ADDRESS="db:6379" DB_PASSWORD="" APP_PORT="8000" DOMAIN="localhost:5173" API_QUOTA=10
For comprehensive API documentation including testing procedures and examples, please refer to the API Documentation in the testing branch.
The testing branch contains detailed information about:
- All available API endpoints
- Request and response formats
- Testing examples using Postman
- Error codes and responses
- Rate limiting details
- Development:
http://localhost:3000
For the latest development features, improvements, and contribution guidelines, please visit the development branch.
The development branch includes:
- Latest features and enhancements
- Development setup instructions
- Contribution guidelines
- Code standards and best practices
- Roadmap and upcoming features
The docker-compose.yml file includes:
- App Service: Go application server
- Redis Service: For caching and rate limiting
- PostgreSQL Service: For persistent data storage
# Start all services docker-compose up -d # View logs docker-compose logs -f # Stop services docker-compose down
docker build -t url-shortener .
docker run -p 3000:8000 --env-file .env url-shortenerurl-shortener/
├── api/
│ ├── database/
│ │ └── database.go
│ ├── models/
│ │ └── models.go
│ ├── routes/
│ │ ├── addTag.go
│ │ ├── deleteUrl.go
│ │ ├── editUrl.go
│ │ ├── getUrl.go
│ │ └── shorten.go
│ └── utils/
│ └── utils.go
├── db/
│ └── (database migration files, if any)
├── Dockerfile
├── .env
├── docker-compose.yml
├── go.mod
├── go.sum
├── main.go
└── README.md
We welcome contributions! Please see our development branch for detailed contribution guidelines.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions or issues, please open an issue on GitHub.
- Analytics and tracking
- User authentication and management
- API key management
- Bulk URL shortening
- QR code generation
- Go community for excellent libraries and tools
- PostgreSQL and Redis for reliable data storage and caching
- Docker for containerization support