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