How harshit3011/url-shortener works
This repository is a Go/Gin URL-shortener backend; the Client directory is only a placeholder. The main workflows are account registration/login and authenticated URL creation/listing, plus shortcode redirects with click recording. Redirects check Redis first and on a miss look up MongoDB and cache the mapping; clicks are persisted and published to Kafka for downstream consumption. The graph also shows token-based route protection and rate limiting. Unexcerpted modules are included only where the README or source index supports them; connections without visible evidence are omitted.
Main entry points: url.controllers.go URL handlers · routes.go HTTP routes · user.controllers.go Account handlers · database.connection.go Mongo access
Components 21
HTTP API
- HTTP routes
Server/routes/routes.go
Identity and Access
- Account handlers
Server/controllers/user.controllers.go - Auth middleware
Server/middleware/auth.middleware.go - Rate limiting
Server/middleware/rateLimiter.go - Token utilities
Server/utils/tokenUtility.go - User model
Server/models/user.model.go
URL and Clicks
- URL handlers
Server/controllers/url.controllers.go - URL model
Server/models/url.model.go - Click model
Server/models/click.model.go - Counter model
Server/models/counters.model.go
Persistence and Events
- Mongo access
Server/database/database.connection.go - Mongo indexes
Server/database/indexes.go - MongoDB
- Redis access
Server/database/redis.go - Redis
- Click producer
Server/kafka/producer.go - Click consumer
Server/kafka/consumer.go - Kafka broker
Service Runtime
- Service startup
Server/main.go - Request observability
Server/middleware
Other components
- API client
Connections 25
- API client → HTTP routes: sends requests
README.md - Service startup → HTTP routes: registers routes
Server/main.go - Service startup → Request observability: installs middleware
Server/main.go - HTTP routes → Account handlers: routes auth
Server/routes/routes.go - HTTP routes → URL handlers: routes URLs
Server/routes/routes.go - HTTP routes → Auth middleware: protects routes
Server/routes/routes.go - HTTP routes → Rate limiting: limits shortening
Server/routes/routes.go - Account handlers → Mongo access: reads and writes
Server/controllers/user.controllers.go - URL handlers → Mongo access: reads and writes
Server/controllers/url.controllers.go - Account handlers → Token utilities: generates tokens
Server/controllers/user.controllers.go - Auth middleware → Token utilities: validates tokens
Server/middleware/auth.middleware.go - Token utilities → Mongo access: checks session
Server/utils/tokenUtility.go - Rate limiting → Redis access: increments limit
Server/middleware/rateLimiter.go - URL handlers → Redis access: caches redirects
Server/controllers/url.controllers.go - Mongo access → MongoDB: connects
README.md - Mongo indexes → MongoDB: indexes collections
- Redis access → Redis: connects
README.md - URL handlers → Click producer: publishes clicks
Server/controllers/url.controllers.go - Click producer → Kafka broker: writes events
Server/kafka/producer.go - Service startup → Click consumer: starts consumer
Server/main.go - Click consumer → Kafka broker: reads events
Server/kafka/consumer.go - Account handlers → User model: uses account data
Server/controllers/user.controllers.go - URL handlers → URL model: uses URL data
Server/controllers/url.controllers.go - URL handlers → Click model: creates click records
Server/controllers/url.controllers.go - URL handlers → Counter model: increments shortcode counter
Server/controllers/url.controllers.go