A Picasso-inspired palette, bold shapes, and modern forms.
A full-stack URL shortener application built with Go backend and React frontend.
This is a monorepo containing both backend and frontend applications:
url-shortener/
├── backend/ # Go backend service
│ ├── cmd/
│ │ ├── server/ # Main application entry point
│ │ └── migrate/ # Database migration tool
│ ├── internal/ # Internal application code
│ │ ├── api/ # HTTP handlers
│ │ ├── db/ # Database layer
│ │ ├── models/ # Data models
│ │ └── service/ # Business logic
│ ├── migrations/ # Database migrations
│ └── go.mod
├── frontend/ # React frontend application
│ ├── src/
│ │ ├── components/
│ │ ├── pages/
│ │ ├── services/
│ │ └── App.jsx
│ ├── public/
│ └── package.json
├── docker-compose.yml # Docker Compose configuration
├── Makefile # Development commands
├── .gitignore
└── README.md
- Shorten long URLs to short, memorable links
- Redirect short URLs to original URLs
- Track click statistics
- Modern, responsive UI
- RESTful API
- Go 1.21 or higher
- Node.js 18 or higher
- Docker and Docker Compose (for database) OR PostgreSQL 12 or higher
- npm or yarn
- Gin - High-performance HTTP web framework
- pgx/v5 - PostgreSQL driver
- godotenv - Environment variable management
See backend/FRAMEWORK.md for framework details and alternatives.
The easiest way to get started is using Docker Compose for the database:
Note: Make sure Docker Desktop (macOS/Windows) or Docker daemon (Linux) is running. You don't need to configure DOCKER_HOST - Docker uses defaults automatically.
- Start the PostgreSQL database:
docker-compose up -dThis will start a PostgreSQL 15 container with:
- Database:
urlshortener - User:
postgres - Password:
postgres - Port:
5432
- Verify the database is running:
docker-compose ps- To stop the database:
docker-compose down- To stop and remove all data:
docker-compose down -v- Navigate to the backend directory:
cd backend- Install dependencies:
go mod download- Set up environment variables:
# Copy the example env file (if using Docker Compose, these defaults work)
cp ../.env.example ../.env
# Or create .env manually with database credentialsThe default .env.example is configured to work with the Docker Compose setup.
- Run database migrations:
go run cmd/migrate/main.go- Start the server:
go run cmd/server/main.goThe backend API will be available at http://localhost:8080
If you prefer to use a local PostgreSQL installation:
- Create the database:
createdb urlshortener-
Update your
.envfile with your local PostgreSQL credentials -
Continue with steps 4-5 from Backend Setup above
- Navigate to the frontend directory:
cd frontend- Install dependencies:
npm install- Start the development server:
npm run devThe frontend will be available at http://localhost:5173
POST /api/shorten- Create a short URLGET /api/:shortCode- Redirect to original URLGET /api/stats/:shortCode- Get statistics for a short URL
For convenience, use the Makefile commands:
# Complete setup (start DB, run migrations)
make setup
# Start database
make db-up
# Run migrations
make migrate
# Run backend
make run-backend
# Run frontend
make run-frontend
# View database logs
make db-logs
# Stop database
make db-down
# Reset database (removes all data)
make db-resetBackend:
cd backend
go test ./...Frontend:
cd frontend
npm testMIT