A high-performance URL shortener built with Rust and Next.js, featuring clean architecture, efficient storage, modern UI, and robust security.
- ⚡ High-performance URL shortening with Rust backend
- 🎨 Modern, responsive UI built with Next.js and Tailwind CSS
- 🔐 Secure URL encryption
- 🔄 Concurrent request handling
- 💾 Persistent storage using Sled embedded database
- ✨ Clean architecture with proper separation of concerns
- 🛡️ Input validation and error handling
- 📝 Basic logging
- 🔍 Health check endpoint
- 🚀 API versioning
- 🎯 Minimal dependencies
The project follows a full-stack architecture with separate frontend and backend components:
- Handlers: HTTP request handlers
- Services: Business logic layer
- Repositories: Data access layer
- Middleware: Request validation and processing
- Pages: Next.js pages and routing
- Components: Reusable UI components
- Styles: Tailwind CSS styling
- API: Frontend-backend integration
├── frontend/ # Next.js frontend application
│ ├── src/ # Frontend source code
│ ├── public/ # Static assets
│ └── ... # Frontend configuration files
├── src/ # Rust backend
│ ├── handlers/ # HTTP request handlers
│ ├── services/ # Business logic
│ ├── repositories/ # Data access layer
│ ├── middleware/ # Request middleware
│ ├── config.rs # Configuration management
│ └── main.rs # Application entry point
└── encryption.key # Encryption key for URL security
Core backend dependencies:
actix-web: Web framework with macros supportactix-cors: CORS middlewaresled: Embedded databasenanoid: URL shorteningurl: URL validationserde: Serializationtokio: Async runtimetracing: Logging systemring: Cryptographybase64: Encoding
Core frontend dependencies:
- Next.js 14
- React
- Tailwind CSS
- TypeScript
- ESLint
- Rust 1.70 or higher
- Node.js 18 or higher
- npm or yarn
# Clone the repository
git clone https://github.com/yourusername/blazing-fast-url-shortner.git
cd blazing-fast-url-shortner
# Build the backend
cargo build --release
# Run the backend
cargo run# Navigate to frontend directory
cd frontend
# Install dependencies
npm install
# Run development server
npm run dev
# For production build
npm run build
npm startPOST /api/v1/shorten
Content-Type: application/json
{
"url": "https://example.com"
}Response:
{
"original_url": "https://example.com",
"short_url": "http://localhost:8080/abc123",
"short_code": "abc123"
}GET /{short_code}Response: 302 Redirect to original URL
GET /api/v1/healthResponse:
{
"status": "ok"
}The application uses environment variables for configuration:
SERVER_HOST: Server host (default: "127.0.0.1")SERVER_PORT: Server port (default: "8080")SERVER_WORKERS: Number of worker threads (default: 4)STORAGE_PATH: Database path (default: "url_db")STORAGE_CACHE_SIZE_MB: Cache size in MB (default: 64)STORAGE_FLUSH_INTERVAL_MS: Storage flush interval (default: 1000)RUST_LOG: Log level (default: "info")
- Efficient storage using Sled embedded database
- High-throughput mode for better performance
- 64MB default cache for faster access
- Fixed worker thread pool (4 workers by default)
- Periodic data flushing for durability
- Path normalization for consistent handling
Minimal set of core dependencies:
actix-web: Web frameworksled: Embedded databasenanoid: URL shorteningurl: URL validationserde: Serializationtokio: Async runtimetracing: Basic logging
The application provides clear error responses:
- Invalid URL format
- URL not found
- Storage errors
- Internal server errors
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.