Enterprise-grade URL Shortening REST API β ASP.NET Core 8 Β· Clean Architecture Β· CQRS Β· MediatR Β· EF Core Β· JWT Β· Serilog Β· GitHub Actions
- Overview
- Key Features
- Architecture
- Solution Structure
- Technology Stack
- API Endpoints
- Security
- Performance
- Health Checks
- Testing
- Running Locally
- Configuration
- CI/CD
- Screenshots
- Roadmap
- Engineering Practices
- License
- Author
The URL Shortener API is a production-ready, enterprise-grade RESTful service built with ASP.NET Core 8, following Clean Architecture, CQRS, and Domain-Driven Design principles.
This project serves as a comprehensive reference implementation demonstrating modern backend engineering practices β from JWT Authentication and CQRS with MediatR, to distributed caching, background services, comprehensive integration testing, and automated CI/CD pipelines.
| Domain | Capabilities |
|---|---|
| Authentication & Identity | JWT Bearer Tokens Β· User Registration Β· User Login Β· Protected Endpoints Β· Claims-based Access |
| URL Management | Create Short URLs Β· Custom Aliases Β· Update URLs Β· Delete URLs Β· URL Expiration |
| URL Lifecycle | Activate URLs Β· Deactivate URLs Β· User-specific URL Management |
| Redirect Engine | Fast URL Resolution Β· Click Tracking Β· Visit Logging Β· Expiry & Status Validation |
| Analytics | Total Click Count Β· Browser Statistics Β· OS Statistics Β· Recent Visits Β· Analytics Caching |
| Performance | In-Memory Cache Β· URL Cache Β· Analytics Cache Β· Optimized Queries Β· Pagination |
| Reliability | Health Checks Β· Background Cleanup Service Β· Global Exception Handling Β· Correlation IDs |
| Observability | Serilog Structured Logging Β· Health Endpoints Β· Rate Limiting |
| Testing | 29+ Integration Tests Β· xUnit Β· FluentAssertions Β· SQLite In-Memory Testing |
| DevOps | GitHub Actions CI Β· Automated Build, Restore & Test Pipeline |
The system strictly adheres to Clean Architecture with enforced layer boundaries and a unidirectional dependency rule.
flowchart TD
Client["π Client / Browser"]
API["βοΈ API Layer\nControllers Β· Middleware Β· Auth"]
APP["π Application Layer\nCQRS Β· MediatR Β· Validation Β· Use Cases"]
DOMAIN["π Domain Layer\nEntities Β· Aggregates Β· Business Rules"]
INFRA["π§ Infrastructure\nLogging Β· Caching Β· Background Services"]
PERSIST["π Persistence\nEF Core Β· Repositories Β· Unit of Work"]
DB[("ποΈ SQL Server / SQLite")]
Client --> API
API --> APP
APP --> DOMAIN
APP --> INFRA
APP --> PERSIST
PERSIST --> DB
classDef api fill:#2563EB,color:#ffffff,stroke:#1E40AF,stroke-width:2px
classDef app fill:#059669,color:#ffffff,stroke:#047857,stroke-width:2px
classDef domain fill:#7C3AED,color:#ffffff,stroke:#6D28D9,stroke-width:2px
classDef infra fill:#EA580C,color:#ffffff,stroke:#C2410C,stroke-width:2px
classDef db fill:#1F2937,color:#ffffff,stroke:#111827,stroke-width:2px
class API api
class APP app
class DOMAIN domain
class INFRA,PERSIST infra
class DB db
flowchart TD
A["π Client"]
B["π API Endpoint\n(Controller)"]
C["π¨ MediatR Dispatcher"]
D["β‘ Command / Query"]
E["π§ Handler\n(Business Logic)"]
F["π¦ Repository\n(Abstraction)"]
G["π§ Entity Framework Core"]
H[("πΎ Database")]
A --> B
B --> C
C --> D
D --> E
E --> F
F --> G
G --> H
classDef api fill:#2563EB,color:#ffffff,stroke:#1E40AF,stroke-width:2px
classDef app fill:#059669,color:#ffffff,stroke:#047857,stroke-width:2px
classDef infra fill:#EA580C,color:#ffffff,stroke:#C2410C,stroke-width:2px
classDef db fill:#7C3AED,color:#ffffff,stroke:#6D28D9,stroke-width:2px
class B api
class C,D,E app
class F,G infra
class H db
Dependency Rule: Dependencies flow strictly inward. The Domain layer has zero external dependencies. Application depends only on Domain. Infrastructure and Persistence depend on Application β never the reverse.
UrlShortener/
β
βββ src/
β βββ UrlShortener.API # Presentation β Controllers, Middleware, Configuration
β βββ UrlShortener.Application # Use Cases β CQRS Commands, Queries, Handlers, Validators
β βββ UrlShortener.Domain # Core Business β Entities, Aggregates, Domain Rules
β βββ UrlShortener.Infrastructure # Cross-cutting β Logging, Caching, Background Services
β βββ UrlShortener.Persistence # Data β EF Core Context, Repositories, Migrations
β
βββ tests/
β βββ UrlShortener.UnitTests # Domain & Business Logic Tests
β βββ UrlShortener.IntegrationTests # End-to-End API Tests (SQLite In-Memory)
β
βββ UrlShortener.sln
| Category | Technology |
|---|---|
| Framework | ASP.NET Core 8 |
| Language | C# 12 |
| ORM | Entity Framework Core 8 |
| Database | SQL Server / SQLite |
| Architecture | Clean Architecture |
| Design Patterns | CQRS Β· MediatR Β· Repository Β· Unit of Work |
| Authentication | ASP.NET Identity Β· JWT Bearer |
| Validation | FluentValidation |
| Logging | Serilog |
| Caching | IMemoryCache |
| Background Services | .NET Hosted Services |
| API Documentation | Swagger / OpenAPI |
| Testing | xUnit Β· FluentAssertions Β· SQLite In-Memory |
| CI/CD | GitHub Actions |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/auth/register |
Register a new user account |
POST |
/api/auth/login |
Authenticate and receive JWT token |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/urls |
Create a new shortened URL |
GET |
/api/urls |
Retrieve all URLs for authenticated user |
PUT |
/api/urls/{id} |
Update an existing URL |
DELETE |
/api/urls/{id} |
Delete a URL permanently |
PUT |
/api/urls/{id}/activate |
Activate a deactivated URL |
PUT |
/api/urls/{id}/deactivate |
Deactivate an active URL |
GET |
/api/urls/{id}/analytics |
Retrieve analytics for a specific URL |
| Method | Endpoint | Description |
|---|---|---|
GET |
/{shortCode} |
Resolve and redirect to the original URL |
| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Returns system health status |
- β JWT Bearer Token Authentication
- β Claims-based Authorization Policies
- β Secure Password Hashing (ASP.NET Identity)
- β
Protected Endpoints with
[Authorize] - β API Rate Limiting to prevent abuse
- β Secure Middleware Pipeline
- β Global Exception Handling β no stack traces exposed
- β In-Memory URL Caching for fast redirect resolution
- β Analytics Result Caching to reduce database load
- β Background Cleanup Service for expired URL removal
- β Optimized EF Core Queries with AsNoTracking
- β Pagination support for large datasets
The application exposes a health endpoint for infrastructure monitoring:
GET /health
| Check | Description |
|---|---|
| Database | Validates SQL Server / SQLite connectivity |
| Memory | Monitors application memory pressure |
| Cache | Validates IMemoryCache availability |
The project includes a comprehensive automated test suite:
| Type | Count | Coverage |
|---|---|---|
| Integration Tests | 29+ | Auth, CRUD, Redirect, Analytics, Health |
| Unit Tests | β | Domain Logic, Validators |
Tests use SQLite In-Memory for fast, isolated database testing without external dependencies.
Run all tests:
dotnet test1. Clone the Repository
git clone https://github.com/chintanchhapgar/core.git
cd UrlShortener2. Restore Dependencies
dotnet restore3. Build the Solution
dotnet build4. Run the API
dotnet run --project src/UrlShortener.API5. Access Swagger UI
https://localhost:5001/swagger
Update appsettings.json with your environment values:
{
"ConnectionStrings": {
"DefaultConnection": "Your_Database_Connection_String"
},
"Jwt": {
"Issuer": "your-issuer",
"Audience": "your-audience",
"SecretKey": "your-secret-key-minimum-32-characters"
},
"Serilog": {
"MinimumLevel": "Information"
}
}GitHub Actions automatically runs on every push and pull request:
flowchart LR
A["π¦ Push / PR"] --> B["π Restore Packages"]
B --> C["π¨ Build Solution"]
C --> D["π§ͺ Run All Tests"]
D --> E{"β
Pass / β Fail"}
| Step | Description |
|---|---|
| Restore | Restores all NuGet packages |
| Build | Compiles the entire solution |
| Test | Executes all unit and integration tests |
| Feature | Status |
|---|---|
| Docker Support | π Planned |
| Redis Distributed Cache | π Planned |
| Refresh Token Support | π Planned |
| PostgreSQL Support | π Planned |
| Azure Deployment | π Planned |
| Kubernetes Support | π Planned |
| OpenTelemetry Integration | π Planned |
| Prometheus Metrics | π Planned |
| Email Verification | π Planned |
- β Clean Architecture with strict layer separation
- β CQRS Pattern (Commands & Queries via MediatR)
- β Repository & Unit of Work Pattern
- β Domain-Driven Design (DDD) concepts
- β Dependency Injection throughout
- β SOLID Principles
- β JWT Authentication & Authorization Policies
- β Background Services for automated cleanup
- β In-Memory Caching Strategy
- β Structured Logging & Observability (Serilog)
- β Global Exception Handling Middleware
- β API Rate Limiting
- β Health Check Endpoints
- β Integration & Unit Testing
- β Automated CI/CD via GitHub Actions
This project is licensed under the MIT License β see the LICENSE file for details.
Built with precision Β· Engineered for scale Β· Designed for clarity




