How developerdiary/nodejs-lld-url-shortener works
This is a layered URL-shortener API. A client submits a long URL or requests a short code; Express routes dispatch to a controller, which delegates shortening or resolution to the service. The service generates codes through an injected strategy, stores URL records and click counts through the repository, and uses Redis as a cache. MongoDB provides persistence. The README documents both Base62 and MD5 strategies and click tracking; the route wiring shown selects MD5. Edges reflect shown calls and wiring, with the documented database persistence link marked unverified.
Main entry points: url.routes.js URL routes · url.service.js URL service · app.js Express app · redis.js Redis client
Components 15
HTTP entry
- Server entry
src/server.js - Express app
src/app.js - URL routes
src/routes/url.routes.js - URL controller
src/controllers/url.controller.js
Shortening logic
- URL service
src/services/url.service.js - MD5 strategy
src/strategies/md5.strategy.js - Base62 strategy
src/strategies/base62.strategy.js - Strategy contract
src/strategies/shortCode.strategy.js
Storage and cache
- URL repository
src/repositories/url.repository.js - URL model
src/models/url.model.js - Mongo connection
src/config/mongo.js - MongoDB
- Redis client
src/config/redis.js - Redis cache
Other components
- API client
Connections 19
- Server entry → Express app: starts
src/server.js - Express app → URL routes: mounts
src/app.js - API client → URL routes: sends requests
README.md - URL routes → URL controller: dispatches
src/routes/url.routes.js - URL routes → URL service: constructs
src/routes/url.routes.js - URL routes → MD5 strategy: selects
src/routes/url.routes.js - URL routes → Base62 strategy: offers alternative
src/routes/url.routes.js - URL controller → URL service: delegates
src/controllers/url.controller.js - URL service → Strategy contract: uses injected strategy
README.md - MD5 strategy → Strategy contract: extends
src/strategies/md5.strategy.js - Base62 strategy → Strategy contract: extends
src/strategies/base62.strategy.js - URL service → URL repository: reads and writes
src/services/url.service.js - URL service → Redis client: gets and sets cache
src/services/url.service.js - URL repository → URL model: queries
src/repositories/url.repository.js - URL model → MongoDB: persists records
README.md - Express app → Mongo connection: connects
src/app.js - Express app → Redis client: connects
src/app.js - Mongo connection → MongoDB: opens connection
src/config/mongo.js - Redis client → Redis cache: opens connection
src/config/redis.js