How ankush-hegde/url-shortener works
This repository implements a URL-shortening HTTP service. A client submits a long URL; the service validates it, reuses or creates a short-code mapping, and returns a short URL. On a short-code request, the service checks Redis, falls back to MongoDB on a miss or cache error, and returns a redirect response. The README also identifies the OpenAPI/Swagger interface and database caching as product capabilities. The graph follows shown wiring; generated-controller internals and some documentation asset serving are not expanded beyond the excerpts.
Main entry points: main.go HTTP server setup · app_url_shorten_service_impl.go Shortener service · resolve_short_url.go Resolve short code · db.go MongoDB adapter
Components 16
HTTP interface
- HTTP server setup
cmd/url_shortener/main.go - Request middleware
internal/pkg/server/middleware/middleware.go - Generated API routes
internal/pkg/server/gen/routers.go - API controller
internal/pkg/server/gen/api_default.go - Shortener service
internal/pkg/server/service/app_url_shorten_service_impl.go - Prometheus endpoint
cmd/url_shortener/main.go
Short URL workflows
- Create short URL
internal/app/createshorturl/create_short_url.go - Resolve short code
internal/app/resolveshorturl/resolve_short_url.go - Runtime configuration
config/config.go
Mapping storage
- MongoDB adapter
internal/pkg/database/mongodb/db.go - MongoDB mappings
- Redis cache adapter
internal/pkg/redis/redis.go - Redis cache
API documentation
- OpenAPI specification
api/url-shortener/url-shortener.openapi.yaml - Swagger UI setup
api/url-shortener/swagger-initializer.js
Other components
- HTTP client
Connections 16
- HTTP client → HTTP server setup: sends requests
cmd/url_shortener/main.go - HTTP server setup → Generated API routes: registers controllers
cmd/url_shortener/main.go - HTTP server setup → Request middleware: installs middleware
cmd/url_shortener/main.go - Generated API routes → API controller: routes to handlers
- API controller → Shortener service: dispatches API calls
- Shortener service → Create short URL: creates mappings
internal/pkg/server/service/app_url_shorten_service_impl.go - Shortener service → Resolve short code: resolves codes
internal/pkg/server/service/app_url_shorten_service_impl.go - HTTP server setup → Runtime configuration: loads settings
cmd/url_shortener/main.go - Create short URL → MongoDB adapter: queries and writes
internal/app/createshorturl/create_short_url.go - Resolve short code → Redis cache adapter: checks and caches
internal/app/resolveshorturl/resolve_short_url.go - Resolve short code → MongoDB adapter: loads on miss
internal/app/resolveshorturl/resolve_short_url.go - MongoDB adapter → MongoDB mappings: reads and writes
internal/pkg/database/mongodb/db.go - Redis cache adapter → Redis cache: reads and writes
internal/pkg/redis/redis.go - HTTP server setup → Prometheus endpoint: registers endpoint
cmd/url_shortener/main.go - HTTP server setup → Swagger UI setup: serves UI assets
cmd/url_shortener/main.go - Swagger UI setup → OpenAPI specification: loads specification
api/url-shortener/swagger-initializer.js