An open API service indexing awesome lists of open source software.

https://github.com/05sanjaykumar/url-shortern

A scalable, Dockerized URL Shortener built with Node.js and Redis โ€” designed to explore backend architecture, caching, and deployment concepts.
https://github.com/05sanjaykumar/url-shortern

devops docker express express-js nginx node redis url-shortener

Last synced: 2 months ago
JSON representation

A scalable, Dockerized URL Shortener built with Node.js and Redis โ€” designed to explore backend architecture, caching, and deployment concepts.

Awesome Lists containing this project

README

          

# ๐Ÿ”— URL Shortener

A full-stack, production-grade URL shortening service built with **Node.js**, **Express**, **Redis**, and **Docker** โ€” complete with rate limiting, RESTful API, unit tests, and deployment on Render.

---

## ๐ŸŒ Live Demo

> ๐ŸŸข Deployed on [Render](https://url-shortern-9qxj.onrender.com/)
> Frontend: Static `HTML + JS`
> Backend: Node.js + Redis
> Dockerized with `Dockerfile` and `nginx` (for local use)

---

## ๐Ÿงฐ Tech Stack

- **Frontend**: HTML, JavaScript (Vanilla)
- **Backend**: Node.js + Express
- **Database**: Redis (for storing shortened URLs)
- **Testing**: Jest
- **Rate Limiting**: Custom Express middleware
- **DevOps**:
- Docker & docker-compose (for local setup)
- Render (for cloud deployment)
- NGINX (proxy for containerized routing)

---

## ๐Ÿ“ Project Structure

```

โ”œโ”€โ”€ public/ # Static frontend
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ controllers/ # Shorten & redirect logic
โ”‚ โ”œโ”€โ”€ routes/ # API endpoints
โ”‚ โ”œโ”€โ”€ services/ # Redis + URL generation
โ”‚ โ””โ”€โ”€ middleware/ # Rate limiter
โ”œโ”€โ”€ test/ # Unit tests (with mocks)
โ”œโ”€โ”€ Dockerfile # Container setup
โ”œโ”€โ”€ docker-compose.yml # Dev orchestration
โ”œโ”€โ”€ server.js # Entry point
โ”œโ”€โ”€ README.md # Project info

````

---

## โœ… Features

- ๐Ÿ”— Shortens long URLs to 6-character codes
- ๐Ÿš€ Redirects to original URL from code
- ๐Ÿง  Stores data in **Redis**
- ๐Ÿ›ก๏ธ Built-in **rate limiter** middleware (basic DDoS protection)
- ๐Ÿงช Unit tested with mocks for Redis
- ๐Ÿณ Local Docker support
- ๐ŸŒ Deployed on **Render**

---

## ๐Ÿš€ Running Locally

### Option 1: Docker (Recommended for full stack)

```bash
docker-compose up
````

### Option 2: Manual

```bash
npm install
redis-server
npm start
```

Then visit: [http://localhost:3000](http://localhost:3000)

---

## ๐Ÿงช Run Tests

```bash
npm test
```

Includes mocks for Redis to ensure unit isolation.

---

## ๐ŸŒ Deployment (Render)

The backend and frontend are deployed using **Render.com**:

* **Backend**: Connected to Redis instance
* **Frontend**: Served via static files or nginx
* **Base URL** is set dynamically in production

---

## ๐Ÿ“Œ Learnings

* ๐Ÿ“ฆ **Modular Express structure** with `controllers`, `routes`, and `services`
* ๐Ÿงช Wrote **unit tests** with Redis mocks
* ๐Ÿณ Learned how to containerize full-stack apps with Docker
* ๐Ÿš€ Deployed using **Render** and explored cloud hosting
* ๐Ÿ›ก๏ธ Implemented basic **rate limiting**
* ๐ŸŒฑ Explored logging, monitoring, and optional CI/CD pipelines

---

## ๐Ÿ™Œ Author

**Sanjay Kumar** โ€” *Lifelong learner, Polyglot dev, and builder of things.*