# Redirect Intelligence v2

A comprehensive URL redirect tracking and analysis platform built with Node.js, React, and PostgreSQL.

## 🚀 Quick Start

### Prerequisites

- Node.js 20+
- Docker & Docker Compose
- Git

### Development Setup

1. **Clone and setup environment:**
   ```bash
   git clone <your-repo-url>
   cd redirect-intelligence-v2
   cp .env.example .env
   ```

2. **Start development environment:**
   ```bash
   npm run dev
   ```

   This will start all services:
   - API: http://localhost:3333
   - Web: http://localhost:3000
   - PostgreSQL: localhost:5432
   - Redis: localhost:6379

3. **Access the application:**
   - Main App: http://localhost:3000
   - API Docs: http://localhost:3333/api/docs
   - Health Check: http://localhost:3333/health

## 📋 Project Structure

```
├── apps/
│   ├── api/          # Express.js API server (TypeScript)
│   ├── web/          # React frontend (Chakra UI)
│   └── worker/       # BullMQ background worker
├── packages/
│   ├── database/     # Prisma schema & migrations
│   └── shared/       # Shared types & utilities
└── docker-compose.yml
```

## 🔄 Backward Compatibility

All existing API endpoints are preserved:

- `POST /api/track` (legacy)
- `POST /api/v1/track` 
- `GET /api/v1/track`

Rate limiting: 100 requests/hour per IP (unchanged)

## 🛠️ Development Commands

```bash
# Start all services
npm run dev

# Individual services
npm run dev:api
npm run dev:web

# Database operations
npm run db:migrate
npm run db:studio
npm run db:seed

# Build & test
npm run build
npm run test
npm run lint
```

## 📖 API Documentation

Visit http://localhost:3333/api/docs for interactive API documentation.

## 🔍 Current Status

**Phase 0: Complete** ✅
- Docker Compose setup
- TypeScript migration
- Monorepo structure
- Backward compatibility preserved

**Next: Phase 1** - PostgreSQL + Prisma + Authentication

## 🧪 Testing

Test the backward compatibility:

```bash
# Test legacy endpoint
curl -X POST http://localhost:3333/api/track \
  -H "Content-Type: application/json" \
  -d '{"url": "github.com"}'

# Test v1 endpoint
curl -X POST http://localhost:3333/api/v1/track \
  -H "Content-Type: application/json" \
  -d '{"url": "github.com", "method": "GET"}'
```

## 📚 Documentation

- [Implementation Plan](./IMPLEMENTATION_PLAN.md) - Detailed phase-by-phase plan
- [Original Plan](./redirect_intelligence_v2_plan.md) - High-level requirements

## 🤝 Contributing

See [IMPLEMENTATION_PLAN.md](./IMPLEMENTATION_PLAN.md) for development phases and guidelines.
