How sqb-codes/url-shortner-mono works
This is an Express URL-shortening service. An HTTP client submits a URL through the registered API routes; the controller delegates creation to the service, which allocates and persists an ID, encodes it as Base62, and stores the short code. For redirects, the service checks Redis first and falls back to MongoDB, caching a successful lookup before returning the destination to the controller. Startup connects the database and cache before listening. The README documents these capabilities; connections not explicit in sampled code are omitted.
Main entry points: url.service.js URL Service · url.repository.js URL Repository · app.js Express App · server.js Server Startup
Components 15
HTTP API
- Express App
src/app.js - URL Routes
src/routes/url.routes.js - URL Controller
src/controllers/url.controller.js - Error Handler
src/middlewares/error.middleware.js
Shortening Logic
- URL Service
src/services/url.service.js - Base62 Encoder
src/utils/base62.js
Persistence
- URL Repository
src/repositories/url.repository.js - URL Record
src/models/url.model.js - ID Counter
src/models/url.counter.model.js
Runtime Connections
- Mongo Connection
src/config/db.js - Redis Connection
src/config/redis.js - Server Startup
server.js
Other components
- HTTP Client
- MongoDB
- Redis Cache
Connections 16
- HTTP Client → Express App: sends requests
README.md - Express App → URL Routes: mounts routes
src/app.js - Express App → Error Handler: registers handler
src/app.js - URL Routes → URL Controller: dispatches
src/routes/url.routes.js - URL Controller → URL Service: calls
src/controllers/url.controller.js - URL Service → URL Repository: persists and looks up
src/services/url.service.js - URL Service → Base62 Encoder: encodes ID
src/services/url.service.js - URL Service → Redis Cache: checks and caches
src/services/url.service.js - URL Repository → URL Record: reads and writes
src/repositories/url.repository.js - URL Repository → ID Counter: increments
src/repositories/url.repository.js - URL Repository → MongoDB: persists records
README.md - Server Startup → Express App: starts
server.js - Server Startup → Mongo Connection: connects
server.js - Server Startup → Redis Connection: connects
server.js - Mongo Connection → MongoDB: opens connection
src/config/db.js - Redis Connection → Redis Cache: opens connection
src/config/redis.js