Skip to content

felipprodrigues/brevly-url

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FTR - PΓ³s-graduΓ§Γ£o Tech Developer 360ΒΊ - Brev.ly

URL Shortener application built with Fastify (Backend) and React (Frontend).

πŸš€ Quick Start

Prerequisites

  • Docker installed and running
  • Node.js 18+ installed
  • pnpm installed (npm install -g pnpm)

1. Clone the Repository

git clone <your-repo-url>
cd brev-ly

2. Backend Setup

cd server

# Install dependencies
pnpm install

# Copy environment variables
cp .env.example .env

# Run setup script (starts Docker PostgreSQL and runs migrations)
chmod +x setup-dev.sh
./setup-dev.sh

# Start the development server
pnpm dev

The backend will be running at:

3. Frontend Setup

Open a new terminal:

cd web

# Install dependencies
pnpm install

# Copy environment variables
cp .env.example .env

# Start the development server
pnpm dev

The frontend will be running at: http://localhost:5173

πŸ“ Project Structure

brev-ly/
β”œβ”€β”€ server/          # Backend (Fastify + PostgreSQL + Drizzle ORM)
β”œβ”€β”€ web/            # Frontend (React + Vite)
└── README.md

πŸ—„οΈ Database Management

Start PostgreSQL

cd server
docker-compose up -d postgres

Run Migrations

cd server
pnpm run db:migrate

Access Database

docker exec -it server-postgres-1 psql -U postgres -d brevly
# Password: brevlypass

Stop Database

cd server
docker-compose down

πŸ”§ Environment Variables

Backend (server/.env)

PORT=3000
NODE_ENV=development
HOST=127.0.0.1
DATABASE_URL=postgresql://postgres:brevlypass@localhost:5432/brevly
CLOUDFLARE_ACCOUNT_ID=your_account_id
CLOUDFLARE_ACCESS_KEY_ID=your_access_key
CLOUDFLARE_SECRET_ACCESS_KEY=your_secret_key
CLOUDFLARE_BUCKET=your_bucket_name
CLOUDFLARE_PUBLIC_URL=your_public_url

Frontend (web/.env)

VITE_API_URL=http://localhost:3000/links

🎯 Features

  • βœ… Create shortened URLs
  • βœ… Delete URLs
  • βœ… List all URLs
  • βœ… Track access counts (hits)
  • βœ… Export links to CSV
  • βœ… CSV storage on Cloudflare R2 (CDN)
  • βœ… Redirect to original URL via short URL

πŸ› οΈ Available Scripts

Backend

pnpm dev          # Start development server with hot reload
pnpm build        # Build for production
pnpm start        # Start production server
pnpm test         # Run tests
pnpm db:generate  # Generate new migration
pnpm db:migrate   # Apply migrations
pnpm db:push      # Push schema changes
pnpm db:studio    # Open Drizzle Studio

Frontend

pnpm dev          # Start development server
pnpm build        # Build for production
pnpm preview      # Preview production build

🐳 Docker

Run the entire stack with Docker:

cd server
docker-compose up --build

This will start:

  • PostgreSQL on port 5432
  • Backend on port 3000
  • Frontend on port 8080

πŸ§ͺ Testing the API

Create a Link

curl -X POST http://localhost:3000/api/links \
  -H "Content-Type: application/json" \
  -d '{"originalUrl": "https://google.com", "shortUrl": "google"}'

List All Links

curl http://localhost:3000/api/links

Access a Short Link

curl -L http://localhost:3000/google

🎨 Design

πŸ“Έ Screenshots

Tela Principal

Tela de Redirecionamento

Tela de Link nΓ£o encontrado

πŸ› Troubleshooting

Port Already in Use

If ports 3000 or 5173 are already in use, you can change them in the respective .env files.

Database Connection Issues

Make sure Docker is running and PostgreSQL container is up:

docker ps | grep postgres

Migrations Not Applied

Run migrations manually:

cd server
pnpm run db:migrate

πŸ‘€ Author

@felipprodrigues

πŸ“„ License

ISC

About

URL shortener application built with Fastify backend and React frontend. Features PostgreSQL database with Drizzle ORM, containerized development environment with Docker, and a full-stack monorepo structure

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages