# Monorepo Migration Summary

This document summarizes the migration from separate `punimtag` and `punimtag-viewer` projects to a unified monorepo structure.

## Migration Date
December 2024

## Changes Made

### Directory Structure

**Before:**
```
punimtag/
├── src/web/          # Backend API
└── frontend/         # Admin React frontend

punimtag-viewer/      # Separate repository
└── (Next.js viewer)
```

**After:**
```
punimtag/
├── backend/          # FastAPI backend (renamed from src/web)
├── admin-frontend/   # React admin interface (renamed from frontend)
└── viewer-frontend/  # Next.js viewer (moved from punimtag-viewer)
```

### Import Path Changes

All Python imports have been updated:
- `from src.web.*` → `from backend.*`
- `import src.web.*` → `import backend.*`

### Configuration Updates

1. **install.sh**: Updated to install dependencies for both frontends
2. **package.json**: Created root package.json with workspace scripts
3. **run_api_with_worker.sh**: Updated to use `backend.app` instead of `src.web.app`
4. **run_worker.sh**: Updated to use `backend.worker` instead of `src.web.worker`
5. **docker-compose.yml**: Updated service commands to use `backend.*` paths

### Environment Files

- **admin-frontend/.env**: Backend API URL configuration
- **viewer-frontend/.env.local**: Database and NextAuth configuration

### Port Configuration

- **Admin Frontend**: Port 3000 (unchanged)
- **Viewer Frontend**: Port 3001 (configured in viewer-frontend/package.json)
- **Backend API**: Port 8000 (unchanged)

## Running the Application

### Development

**Terminal 1 - Backend:**
```bash
source venv/bin/activate
export PYTHONPATH=$(pwd)
uvicorn backend.app:app --host 127.0.0.1 --port 8000
```

**Terminal 2 - Admin Frontend:**
```bash
cd admin-frontend
npm run dev
```

**Terminal 3 - Viewer Frontend:**
```bash
cd viewer-frontend
npm run dev
```

### Using Root Scripts

```bash
# Install all dependencies
npm run install:all

# Run individual services
npm run dev:backend
npm run dev:admin
npm run dev:viewer
```

## Benefits

1. **Unified Setup**: Single installation script for all components
2. **Easier Maintenance**: All code in one repository
3. **Shared Configuration**: Common environment variables and settings
4. **Simplified Deployment**: Single repository to deploy
5. **Better Organization**: Clear separation of admin and viewer interfaces

## Migration Checklist

- [x] Rename `src/web` to `backend`
- [x] Rename `frontend` to `admin-frontend`
- [x] Copy `punimtag-viewer` to `viewer-frontend`
- [x] Update all Python imports
- [x] Update all scripts
- [x] Update install.sh
- [x] Create root package.json
- [x] Update docker-compose.yml
- [x] Update README.md
- [x] Update scripts in scripts/ directory

## Notes

- The viewer frontend manages the `punimtag_auth` database
- Both frontends share the main `punimtag` database
- Backend API serves both frontends
- All database schemas remain unchanged

## Next Steps

1. Test all three services start correctly
2. Verify database connections work
3. Test authentication flows
4. Update CI/CD pipelines if applicable
5. Archive or remove the old `punimtag-viewer` repository


