Skip to content

agrimrules/shawty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Shawty πŸ”—

A URL shortener built with ASP.NET Core, featuring a beautiful UI, automatic link expiration, and Docker support. currently hosted here.

.NET License

✨ Features

  • ⚑ 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

πŸš€ Quick Start

Prerequisites

Running Locally

  1. Clone the repository

    git clone https://github.com/agrimrules/shawty.git
    cd shawty
  2. Run the application

    cd shawty
    dotnet run
  3. Open your browser

    http://localhost:5277
    

Running with Docker Compose

  1. Start the containers

    docker-compose up --build -d
  2. Access the application

    http://localhost:5277
    
  3. Stop the containers

    docker-compose down

Using the mnemonic URL shortener feature

  1. Add OpenAI API key as environment variable before starting
    export OPENAI_API_KEY=xyz

πŸ“– Usage

Web UI

  1. Navigate to the home page
  2. Paste your long URL into the input field
  3. Click "Shorten URL"
  4. Copy and share your shortened link!

Note: All shortened links are valid for 72 hours.

API Endpoints

Shorten a URL

POST /api/shorten
Content-Type: application/json

{
  "url": "https://example.com/very/long/url"
}

Response:

{
  "shortCode": "a1b2c3d4"
}

Access a shortened URL

GET /{shortCode}

Redirects to the original URL or returns a 404 page if not found.

πŸ—οΈ Architecture

Tech Stack

  • 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)

Project Structure

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

πŸ”§ Configuration

Database Location

The SQLite database is stored at ../sqlite/data.db relative to the application directory.

Expiration Time

Links expire after 72 hours. To change this, modify the cleanup service:

// In Services/UrlCleanupService.cs
DatabaseManager.DeleteOldUrls(72);  // Change 72 to desired hours

Cleanup Frequency

The background service runs every 1 hour. To change this:

// In Services/UrlCleanupService.cs
private readonly TimeSpan _period = TimeSpan.FromHours(1);  // Adjust as needed

Other Platforms

The application works on any platform that supports:

  • Docker containers
  • ASP.NET Core 9.0 runtime
  • Port mapping

πŸ› οΈ Development

Building

dotnet build

Running Tests

dotnet test

Database Schema

CREATE TABLE urls (
    url TEXT,
    encoded TEXT,
    timestamp DATETIME
);

CREATE INDEX idx_urls_encoded ON urls(encoded);

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“ License

This project is licensed under the GPL-3.0 License.

πŸ™ Acknowledgments


About

A url shortener.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •