CUTR is a URL shortening service with support for storing and caching links in PostgreSQL and Redis. The application is written in C++ using the Drogon framework and is fully asynchronous.
URL Input:
Shortened Link:
- Create short links for long URLs
- Redirect from a short link to the original URL
- Cache links in Redis to speed up redirects
- Track link usage statistics (hit counts)
- Persistent storage using PostgreSQL
- Controllers:
LinkControllerhandles API endpoints for creating and redirecting links - Services:
LinkServiceandRedirectServiceimplement business logic - Repositories: interact with data through the
ILinkRepositoryinterface and concrete implementations for PostgreSQL and Redis - Caching: Redis is used for fast lookup and redirect
- Asynchronous: all database and cache operations are performed in coroutines
Below are the primary endpoints exposed by CUTR.
All responses are JSON.
POST /shorten
{
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
}curl -X POST http://localhost:8080/shorten \
-H "Content-Type: application/json" \
-d '{"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"}'{
"shortCode": "r/AbC123"
}GET /{short-code}
curl http://localhost:8080/r/AbC123HTTP/1.1 302 Found
Location: https://www.youtube.com/watch?v=dQw4w9WgXcQ
If the short link does not exist:
HTTP/1.1 404 Not Found
Short link not found
CUTR provides a fully containerized setup using docker-compose.
This includes the application itself, PostgreSQL, and Redis.
Make sure to clone the project together with all submodules:
git clone --recurse-submodules https://github.com/capybaracplusplus/cutr.gitcd cutrCreate a .env file in the project root:
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=cutr
POSTGRES_HOST=127.0.0.1
DB_PORT=5432
REDIS_HOST=cutr-redis
REDIS_PORT=6379
LISTEN_ADDR=0.0.0.0
LISTEN_PORT=8080Run the following command in the project directory:
docker-compose build --no-cache# Start in foreground (recommended for development)
docker-compose up# Start in background
docker-compose up -d
