Firefly is a URL shortener backend build with Node.js, Express, TypeScript, MongoDB, Redis, and Docker.
The project is being built step by step with clean backend architecture, proper TypeScript structure, Redis caching, Docker support, and future plans for authentication, analytics, email reports, and an Astro frontend.
- Create short URLs
- Optional custom aliases
- Optional expiry date for links
- Redirect short URLs to original URLs
- Track click count
- Fetch basic analytics
- Redis cache-aside support for faster redirects
- MongoDB persistence
- TypeScript + ESM setup
- Centralised error handling
- Constraints, enums, interfaces, and locale ready messages
- Docker development and production like setup
- Node.js
- Express.js
- TypeScript
- MongoDB
- Mongoose
- Redis
- Docker
- Docker Compose
src/
├── app.ts
├── server.ts
├── config/
├── constants/
├── controllers/
├── enums/
├── interfaces/
├── locales/
├── middlewares/
├── models/
├── routes/
├── services/
└── utils/GET /healthResponse:
{
"success": true,
"message": "server is running"
}POST /api/urls
Content-Type: application/jsonRequest:
{
"url": "https://example.com",
"customAlias": "example",
"expiresAt": "2026-06-01T00:00:00.000Z"
}CustomAlias and expiresAt are optional.
Response:
{
"success": true,
"message": "Short URL created successfully",
"data": {
"shortUrl": "http://localhost:3000/example",
"shortId": "example",
"originalUrl": "https://example.com",
"expiresAt": "2026-06-01T00:00:00.000Z"
}
}GET /:shortIdExample:
http://localhost:3000/example
Redirects to the original URL.
GET /api/urls/:shortId/statsExample:
GET /api/urls/example/statsResponse:
{
"success": true,
"message": "URL analytics fetched successfully",
"data": {
"shortId": "example",
"shortUrl": "http://localhost:3000/example",
"originalUrl": "https://example.com",
"clicks": 5,
"expiresAt": "2026-06-01T00:00:00.000Z",
"createdAt": "2026-05-06T00:00:00.000Z"
}
}Create Local env files from examples
cp .env.example .envcp .env.docker.dev.example .env.docker.devcp .env.docker.example .env.dockernpm installMake sure mongoDB and Redis are running locally.
npm run devThis runs API, MongoDB, and Redis inside Docker with hot reload.
npm run docker:devor directly:
docker compose -f docker-compose.dev.yml up --buildStop:
npm run docker:dev:downThis builds the TypeScript app and runs Compiled JavaScript.
npm run docker:prodor directly:
docker compose up --buildStop:
npm run docker:prod:downView Containers:
docker psView API logs:
docker compose logs -f apiStop dev stack:
docker compose -f docker-compose.dev.yml downStop production-like stack:
docker compose downRemove containers and volumes:
docker compose down -vDockerfile- production-like multi-stage buildDockerfile.dev- development setup with hot reloaddocker-compose-yml- production-like local stackdocker-compose.dev.yml- development stack.dockerignore- ignores unnecessary files during image build
Recommended branch flow:
feature/* -> develop -> main
main- production ready codedev- integration branchfeature/*- induvidual feature branches
Example:
git checkout develop
git checkout -b feature/docker-setup