# Local Development Setup (No Docker)

## Backend Setup

1. **Create Virtual Environment** (if not already done):

```bash
cd backend
python3 -m venv venv
source venv/bin/activate  # On Mac/Linux
```

2. **Install Dependencies**:

```bash
pip install -r requirements.txt
```

3. **Set Environment Variables**:

```bash
export DATABASE_URL="sqlite:///./elmeg.db"
export SECRET_KEY="your-secret-key-for-jwt"
```

4. **Run Migrations**:

```bash
alembic upgrade head
```

5. **Start Backend**:

```bash
uvicorn main:app --reload --port 8000
```

Backend will be available at: `http://localhost:8000`

---

## Frontend Setup

1. **Install Dependencies**:

```bash
cd frontend
npm install
```

2. **Set Environment Variables**:
Create `frontend/.env.local`:

```
NEXT_PUBLIC_API_URL=http://localhost:8000
```

3. **Start Frontend**:

```bash
npm run dev
```

Frontend will be available at: `http://localhost:3000`

---

## Testing the Application

1. **Create a User**:
   - Navigate to `http://localhost:3000`
   - Register a new account

2. **Test Features**:
   - Browse shows at `/archive`
   - Search with `Cmd+K`
   - Create a group at `/groups`
   - Check settings at `/settings`
   - View admin dashboard at `/admin` (if superuser)

3. **Create Superuser** (for admin access):

```bash
# In backend directory with venv activated
python -c "
from database import engine
from models import User
from sqlmodel import Session, select
from passlib.context import CryptContext

pwd_context = CryptContext(schemes=['bcrypt'], deprecated='auto')

with Session(engine) as session:
    user = session.exec(select(User).where(User.email == 'your@email.com')).first()
    if user:
        user.is_superuser = True
        user.role = 'admin'
        session.add(user)
        session.commit()
        print(f'User {user.email} is now a superuser')
    else:
        print('User not found')
"
```

---

## Common Issues

### Backend won't start

- Check if port 8000 is already in use: `lsof -i :8000`
- Ensure virtual environment is activated
- Verify all dependencies installed: `pip list`

### Frontend won't start

- Check if port 3000 is already in use: `lsof -i :3000`
- Clear `.next` cache: `rm -rf .next`
- Reinstall dependencies: `rm -rf node_modules && npm install`

### Database issues

- Delete and recreate: `rm elmeg.db` then `alembic upgrade head`
- Check migration status: `alembic current`
