A simple, production-ready URL shortener built with Java, Spring Boot, and PostgreSQL. Features a RESTful API, click tracking, access metrics (IP, user agent, timestamp), Docker support, and Traefik integration.
- 🔗 Shorten URLs with unique 6-character codes
- ↪️ Redirect to original URLs
- 📊 Track clicks and access logs (IP, user agent, timestamp)
- 🛠️ RESTful API for management
- 🐳 Dockerized for easy deployment
- 🚦 Traefik integration for routing and reverse proxy
- ☕ Java 21
- 🌱 Spring Boot 3
- 🐘 PostgreSQL
- 🐳 Docker & Docker Compose
- 🚦 Traefik (reverse proxy)
- 🗃️ JPA/Hibernate
- 🦾 Lombok
- ⚙️ Gradle
- Docker & Docker Compose
- Java 21 (for local development)
- Gradle
- Clone the repository:
git clone https://github.com/fsousac/weshorten.git cd weshorten - Start the stack:
docker compose up --build
- Access the application:
- API: http://short.local/api
- Shortened links: http://short.local/{shortCode}
- Note: Add
127.0.0.1 short.localto your/etc/hostsfor local testing.
- POST
/api/shorten - Body:
{ "originalUrl": "https://example.com" } - Response:
{ "shortenedUrl": "https://short.local/abc123", "originalUrl": "https://example.com" }
- GET
/api/links - Response:
[ { "shortenedUrl": "https://short.local/abc123", "originalUrl": "https://example.com", "clicks": 5 } ]
- DELETE
/api/links/{shortCode}
- GET
/{shortCode} - Redirects to the original URL and logs access metrics.
On each redirect, the following are stored:
- Short code
- IP address
- User agent
- Access timestamp (UTC)
- Profiles:
dev: Local development (application-dev.properties)prod: Production (application-prod.properties)
- Database:
- PostgreSQL (see
.envfor credentials)
- PostgreSQL (see
- Start PostgreSQL locally or via Docker.
- Set the active profile to dev:
export SPRING_PROFILES_ACTIVE=dev - Build and run:
./gradlew bootRun
Run:
./gradlew testDistributed under GNU GPL v3.
Open an issue or check additional documentation in HELP.md.
Um encurtador de URLs simples, pronto para produção, feito com Java, Spring Boot e PostgreSQL. Inclui API RESTful, rastreamento de cliques, métricas de acesso (IP, user agent, timestamp), suporte a Docker e integração com Traefik.
- 🔗 Encurte URLs com códigos únicos de 6 caracteres
- ↪️ Redirecione para URLs originais
- 📊 Rastreie cliques e logs de acesso (IP, user agent, timestamp)
- 🛠️ API RESTful para gerenciamento
- 🐳 Dockerizado para fácil deploy
- 🚦 Integração com Traefik para roteamento e proxy reverso
- ☕ Java 21
- 🌱 Spring Boot 3
- 🐘 PostgreSQL
- 🐳 Docker & Docker Compose
- 🚦 Traefik (reverse proxy)
- 🗃️ JPA/Hibernate
- 🦾 Lombok
- ⚙️ Gradle
- Docker & Docker Compose
- Java 21 (para desenvolvimento local)
- Gradle
- Clone o repositório:
git clone https://github.com/fsousac/weshorten.git cd weshorten - Suba o stack:
docker compose up --build
- Acesse a aplicação:
- API: http://short.local/api
- Links encurtados: http://short.local/{shortCode}
- Obs: Adicione
127.0.0.1 short.localao seu/etc/hostspara testes locais.
- POST
/api/shorten - Body:
{ "originalUrl": "https://example.com" } - Resposta:
{ "shortenedUrl": "https://short.local/abc123", "originalUrl": "https://example.com" }
- GET
/api/links - Resposta:
[ { "shortenedUrl": "https://short.local/abc123", "originalUrl": "https://example.com", "clicks": 5 } ]
- DELETE
/api/links/{shortCode}
- GET
/{shortCode} - Redireciona para a URL original e registra métricas de acesso.
A cada redirecionamento, são armazenados:
- Código curto
- Endereço IP
- User agent
- Timestamp de acesso (UTC)
- Perfis:
dev: Desenvolvimento local (application-dev.properties)prod: Produção (application-prod.properties)
- Banco de dados:
- PostgreSQL (veja
.envpara credenciais)
- PostgreSQL (veja
- Inicie o PostgreSQL localmente ou via Docker.
- Defina o profile ativo para dev:
export SPRING_PROFILES_ACTIVE=dev - Build e execute:
./gradlew bootRun
Execute:
./gradlew testDistribuído sob a GNU GPL v3.
Abra uma issue ou consulte a documentação adicional em HELP.md.