# TranscriptIQ Backend — Sprint 1 Setup

## What is in Sprint 1

Foundation layer — database, auth, Docker, project structure.
No pipeline logic yet. That is Sprint 2.

## Prerequisites (already on DGX Spark)

- Docker + Docker Compose
- PostgreSQL 15 (or will run in Docker)
- Redis 7 (or will run in Docker)
- Ollama running with llama3.3 loaded
- Tailscale tunnel active
- Python 3.11 (for local dev without Docker)

## Setup Steps

### 1. Clone the repo

```bash
git clone <repo-url>
cd transcriptiq-backend
```

### 2. Create your .env file

```bash
cp .env.example .env
# Edit .env — fill in DB_PASSWORD and SECRET_KEY at minimum
# Generate SECRET_KEY:
python -c "import secrets; print(secrets.token_hex(32))"
```

### 3. Start all services

```bash
docker-compose up -d
```

This starts:
- PostgreSQL on port 5432
- Redis on port 6379
- FastAPI app on port 8000
- Celery worker (idle until Sprint 2)

The `migrations/001_initial.sql` runs automatically on first start — all tables are created.

### 4. Verify everything is running

```bash
# Check all containers are healthy
docker-compose ps

# Test the health endpoint
curl http://localhost:8000/health

# Expected response:
# {"status":"ok","version":"1.0.0"}
```

### 5. Test auth endpoints

```bash
# Register
curl -X POST http://localhost:8000/auth/register \
  -H "Content-Type: application/json" \
  -d '{"email":"test@test.com","password":"test123","full_name":"Test User","org_name":"Test Org"}'

# Login
curl -X POST http://localhost:8000/auth/login \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "username=test@test.com&password=test123"

# Get current user (use token from login response)
curl http://localhost:8000/auth/me \
  -H "Authorization: Bearer <token>"
```

### 6. View API docs (dev mode only)

Set `DEBUG=true` in .env, then visit:
```
http://localhost:8000/docs
```

## Tailscale Access

Once Sprint 1 is confirmed working locally, make the app accessible via Tailscale:

```bash
# The app runs on port 8000
# Add to your existing Tailscale routing or expose via nginx on DGX
# Frontend will call: https://transcriptiq-api.<your-tailscale-domain>
```

## Folder Structure Created in Sprint 1

```
transcriptiq-backend/
├── app/
│   ├── main.py              ← FastAPI entry point + CORS
│   ├── config.py            ← All env vars
│   ├── database.py          ← PostgreSQL connection
│   ├── models/
│   │   ├── __init__.py
│   │   ├── user.py
│   │   ├── workspace.py
│   │   ├── project.py
│   │   ├── transcript.py
│   │   └── code_result.py
│   ├── routes/
│   │   └── auth.py          ← register, login, logout, me
│   └── core/
│       └── security.py      ← JWT + password hashing
├── migrations/
│   └── 001_initial.sql      ← Full DB schema
├── docker-compose.yml
├── Dockerfile
├── requirements.txt
├── .env.example
└── .gitignore
```

## What Sprint 2 Adds

- Upload endpoint (PDF/DOCX → text)
- Job queue (Celery tasks wrapping your 10 existing scripts)
- Pipeline API endpoints
- Results and export endpoints

## Questions?

Review the Technical Briefing Document (TranscriptIQ_Technical_Briefing.docx)
or raise questions before Sprint 2 starts.
