A very performant and light (2mb in memory) link shortener and tracker. Written in Rust and React and uses Postgres/SQLite.
Find a file
2025-01-26 01:30:51 -05:00
.sqlx almost production ready 2025-01-26 01:30:51 -05:00
frontend almost production ready 2025-01-26 01:30:51 -05:00
migrations fixes to db stuff 2025-01-25 03:41:45 -05:00
src almost production ready 2025-01-26 01:30:51 -05:00
.gitignore almost production ready 2025-01-26 01:30:51 -05:00
.preludeignore almost production ready 2025-01-26 01:30:51 -05:00
API.md Add auth 2025-01-25 03:16:35 -05:00
build.sh almost production ready 2025-01-26 01:30:51 -05:00
Cargo.lock almost production ready 2025-01-26 01:30:51 -05:00
Cargo.toml almost production ready 2025-01-26 01:30:51 -05:00
DEPLOYMENT.md almost production ready 2025-01-26 01:30:51 -05:00
docker-compose.yml almost production ready 2025-01-26 01:30:51 -05:00
Dockerfile almost production ready 2025-01-26 01:30:51 -05:00
README.md almost production ready 2025-01-26 01:30:51 -05:00

SimpleLink

A modern link shortening and tracking service built with Rust and React.

Features

  • 🔗 Link shortening with custom codes
  • 📊 Click tracking and analytics
  • 🔒 User authentication
  • 📱 Responsive design
  • 🌓 Dark/light mode
  • 📈 Source attribution tracking

Tech Stack

Backend

  • Rust
  • Actix-web
  • SQLx
  • PostgreSQL
  • JWT Authentication

Frontend

  • React
  • TypeScript
  • Tailwind CSS
  • Shadcn/ui
  • Vite
  • Recharts

Development Setup

Prerequisites

  • Rust (latest stable)
  • Bun (or Node.js)
  • PostgreSQL
  • Docker (optional)

Environment Variables

Backend (.env)

DATABASE_URL=postgres://user:password@localhost:5432/simplelink
SERVER_HOST=127.0.0.1
SERVER_PORT=3000
JWT_SECRET=your-secret-key

Frontend Environment Files

Development (.env.development):

VITE_API_URL=http://localhost:3000

Production (.env.production):

VITE_API_URL=https://your-production-domain.com

Local Development

  1. Clone the repository:
git clone https://github.com/yourusername/simplelink.git
cd simplelink
  1. Set up the database:
psql -U postgres
CREATE DATABASE simplelink;
  1. Run database migrations:
cargo run --bin migrate
  1. Start the backend server:
cargo run
  1. In a new terminal, start the frontend development server:
cd frontend
bun install
bun run dev

The app will be available at:

Building for Production

Use the build script to create a production build:

./build.sh

This will:

  1. Build the frontend with production settings
  2. Copy static files to the correct location
  3. Prepare everything for deployment

You can override the API URL during build:

VITE_API_URL=https://api.yoursite.com ./build.sh

Docker Deployment

Build and run using Docker Compose:

docker-compose up --build

Or build and run the containers separately:

# Build the image
docker build -t simplelink .

# Run the container
docker run -p 3000:3000 \
  -e DATABASE_URL=postgres://user:password@db:5432/simplelink \
  -e JWT_SECRET=your-secret-key \
  simplelink

Project Structure

simplelink/
├── src/                    # Rust backend code
│   ├── handlers/          # Request handlers
│   ├── models/           # Database models
│   └── main.rs           # Application entry point
├── migrations/            # Database migrations
├── frontend/             # React frontend
│   ├── src/
│   │   ├── components/   # React components
│   │   ├── api/         # API client
│   │   └── types/       # TypeScript types
│   └── vite.config.ts    # Vite configuration
├── static/               # Built frontend files (generated)
├── Cargo.toml            # Rust dependencies
├── docker-compose.yml    # Docker composition
└── build.sh             # Build script

API Endpoints

  • POST /api/auth/register - Register new user
  • POST /api/auth/login - Login user
  • POST /api/shorten - Create short link
  • GET /api/links - Get all user links
  • DELETE /api/links/{id} - Delete link
  • GET /api/links/{id}/clicks - Get click statistics
  • GET /api/links/{id}/sources - Get source statistics
  • GET /{short_code} - Redirect to original URL

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.