Shawty π
A URL shortener built with ASP.NET Core, featuring a beautiful UI, automatic link expiration, and Docker support. currently hosted here.
- β‘ Fast & Lightweight: Built with ASP.NET Core Minimal API
- π Automatic Cleanup: Links expire after 72 hours
- π³ Docker Ready: Full Docker and Docker Compose support
- π Domain Agnostic: Works with any custom domain
- πΎ SQLite Database: Simple, file-based storage with indexing
- π Background Service: Automatic cleanup of expired URLs
- .NET 9.0 SDK
- Docker (optional)
-
Clone the repository
git clone https://github.com/agrimrules/shawty.git cd shawty -
Run the application
cd shawty dotnet run -
Open your browser
http://localhost:5277
-
Start the containers
docker-compose up --build -d
-
Access the application
http://localhost:5277 -
Stop the containers
docker-compose down
- Add OpenAI API key as environment variable before starting
export OPENAI_API_KEY=xyz
- Navigate to the home page
- Paste your long URL into the input field
- Click "Shorten URL"
- Copy and share your shortened link!
Note: All shortened links are valid for 72 hours.
POST /api/shorten
Content-Type: application/json
{
"url": "https://example.com/very/long/url"
}Response:
{
"shortCode": "a1b2c3d4"
}GET /{shortCode}Redirects to the original URL or returns a 404 page if not found.
- Backend: ASP.NET Core 9.0 (Minimal API + Razor Pages)
- Database: SQLite with Microsoft.Data.Sqlite
- Hashing: MD5 (8-character Base64 encoding)
- Styling: Vanilla CSS with custom design system
- Fonts: Google Fonts (Outfit)
shawty/
βββ Database/
β βββ DatabaseManager.cs # SQLite operations
βββ Pages/
β βββ Index.cshtml # Home page
β βββ Index.cshtml.cs # Home page logic
β βββ NotFound.cshtml # Custom 404 page
β βββ Shared/
β β βββ _Layout.cshtml # Layout template
β βββ _ViewImports.cshtml # Razor imports
βββ Services/
β βββ UrlCleanupService.cs # Background cleanup job
βββ wwwroot/
β βββ css/
β βββ site.css # Premium styling
βββ Program.cs # Application entry point
βββ Dockerfile # Docker configuration
βββ docker-compose.yml # Docker Compose setup
The SQLite database is stored at ../sqlite/data.db relative to the application directory.
Links expire after 72 hours. To change this, modify the cleanup service:
// In Services/UrlCleanupService.cs
DatabaseManager.DeleteOldUrls(72); // Change 72 to desired hoursThe background service runs every 1 hour. To change this:
// In Services/UrlCleanupService.cs
private readonly TimeSpan _period = TimeSpan.FromHours(1); // Adjust as neededThe application works on any platform that supports:
- Docker containers
- ASP.NET Core 9.0 runtime
- Port mapping
dotnet builddotnet testCREATE TABLE urls (
url TEXT,
encoded TEXT,
timestamp DATETIME
);
CREATE INDEX idx_urls_encoded ON urls(encoded);Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the GPL-3.0 License.
- Built with ASP.NET Core
- Styled with Google Fonts