How nagavjm/shortlink works
ShortLink is a URL-shortening product with an Angular client and an ASP.NET API. Users create links, browse paginated mappings, deactivate links, or follow a short link to its destination; redirects also enqueue click tracking. The application service coordinates validation, code generation, persistence, caching, and analytics. The sampled source supports the main API and service calls, repository persistence, and cache behavior. Some infrastructure wiring and the client’s HTTP-to-API connection are not shown, so those links are omitted or marked unverified.
Main entry points: UrlShortenerService.cs URL use cases · app.component.ts ShortLink UI · UrlMappingRepository.cs Mapping repository · url-shortener.service.ts URL client service
Components 20
Web client
- ShortLink UI
client/src/app/app.component.ts - URL client service
client/src/app/services/url-shortener.service.ts - URL models
client/src/app/models/url.model.ts
API
- URL management API
src/ShortLink.API/Controllers/UrlsController.cs - Redirect endpoint
src/ShortLink.API/Controllers/RedirectController.cs - Exception handling
src/ShortLink.API/Middleware/ExceptionHandlingMiddleware.cs
Application workflows
- URL use cases
src/ShortLink.Application/Services/UrlShortenerService.cs - Request validation
src/ShortLink.Application/Validators/CreateUrlRequestValidator.cs - URL mapping entity
src/ShortLink.Domain/Entities/UrlMapping.cs
Infrastructure and state
- Short-code generation
src/ShortLink.Infrastructure/Services/AutoIncrementShortCodeGenerator.cs - Base62 encoding
src/ShortLink.Infrastructure/Services/Base62Service.cs - Mapping repository
src/ShortLink.Infrastructure/Data/Repositories/UrlMappingRepository.cs - EF data context
src/ShortLink.Infrastructure/Data/ShortLinkDbContext.cs - Redis cache adapter
src/ShortLink.Infrastructure/Cache/RedisCacheService.cs - Click analytics queue
src/ShortLink.Infrastructure/Services/ClickAnalyticsChannel.cs - Analytics worker
src/ShortLink.Infrastructure/BackgroundServices/ClickAnalyticsBackgroundWorker.cs
Other components
- Link user
- API caller
- PostgreSQL
- Redis
Connections 22
- Link user → ShortLink UI: uses
client/src/app/app.component.ts - ShortLink UI → URL client service: requests links
client/src/app/app.component.ts - ShortLink UI → URL models: uses types
client/src/app/app.component.ts - ShortLink UI → URL client service: deactivates links
client/src/app/app.component.ts - URL client service → URL models: uses types
client/src/app/services/url-shortener.service.ts - API caller → URL management API: manages links
src/ShortLink.API/Controllers/UrlsController.cs - API caller → Redirect endpoint: follows short link
src/ShortLink.API/Controllers/RedirectController.cs - URL management API → URL use cases: invokes use cases
src/ShortLink.API/Controllers/UrlsController.cs - Redirect endpoint → URL use cases: resolves destination
src/ShortLink.API/Controllers/RedirectController.cs - URL use cases → Mapping repository: reads and writes mappings
src/ShortLink.Application/Services/UrlShortenerService.cs - URL use cases → Redis cache adapter: looks up and warms cache
src/ShortLink.Application/Services/UrlShortenerService.cs - URL use cases → Short-code generation: generates short code
- Short-code generation → Base62 encoding: encodes identifier
- URL use cases → URL mapping entity: creates and updates
src/ShortLink.Application/Services/UrlShortenerService.cs - Mapping repository → URL mapping entity: reads and persists
src/ShortLink.Infrastructure/Data/Repositories/UrlMappingRepository.cs - Mapping repository → EF data context: queries and saves
src/ShortLink.Infrastructure/Data/Repositories/UrlMappingRepository.cs - EF data context → PostgreSQL: stores mappings
- Redis cache adapter → Redis: reads and writes
src/ShortLink.Infrastructure/Cache/RedisCacheService.cs - URL use cases → Click analytics queue: enqueues clicks
src/ShortLink.Application/Services/UrlShortenerService.cs - Analytics worker → Click analytics queue: consumes events
src/ShortLink.Infrastructure/BackgroundServices/ClickAnalyticsBackgroundWorker.cs - Analytics worker → EF data context: updates analytics
src/ShortLink.Infrastructure/BackgroundServices/ClickAnalyticsBackgroundWorker.cs - Exception handling → URL use cases: handles failures