# FORGE AI Installation & Setup Guide

This guide will walk you through setting up the **FORGE AI** platform locally using Docker.

## 📋 Prerequisites

*   **Docker & Docker Desktop**: Ensure Docker Engine is running.
*   **Git**: Version control.
*   **API Keys**: You will need keys for the services you intend to use (Runway, Google Vertex, OpenAI, etc.).

## 🛠️ Step-by-Step Installation

### 1. Clone the Repository
```bash
git clone https://bitbucket.org/zlalani/forge.git
cd forge-ai
```

### 2. Configure Environment Variables
Copy the example environment file and configure it with your secrets.

```bash
cp .env.example .env
```
Open `.env` in your editor and fill in the following critical sections:
*   **Database**: `POSTGRES_PASSWORD` (Default: `forge_secure_password_2024`)
*   **Runway ML**: `RUNWAY_API_KEY` (Required for Video Generation)
*   **Google**: `GOOGLE_API_KEY`, `GOOGLE_PROJECT_ID` (Required for Veo)
*   **Topaz**: `TOPAZ_API_KEY` (Required for Upscaling)

### 3. Build and Start Services
Use Docker Compose to build the containers and start the application.

```bash
# Build and start in detached mode
docker-compose up -d --build
```
*Note: The initial build may take 5-10 minutes as it installs Python dependencies and builds the Next.js frontend.*

### 4. Verify Installation
Check the status of your containers:
```bash
docker ps
```
You should see the following healthy containers:
*   `forge-frontend` (Port 3000)
*   `forge-backend` (Port 8000)
*   `forge-postgres` (Port 5432)
*   `forge-redis` (Port 6379)
*   `forge-worker`

### 5. Access the Application
Open your browser and navigate to:
*   **Dashboard**: [http://localhost:3000](http://localhost:3000)
*   **API Docs**: [http://localhost:8000/docs](http://localhost:8000/docs)

---

## 🛑 Management Commands

### Stopping the App
```bash
docker-compose down
```

### Viewing Logs
To see logs for a specific service (e.g., backend):
```bash
docker logs -f forge-backend
```

### Database Access
To inspect the database manually:
```bash
docker exec -it forge-postgres psql -U forge_user -d forge_ai
```

---

## ⚠️ Troubleshooting

**Issues with Gen-4 Turbo / Permissions (403)**
*   Ensure your `RUNWAY_API_KEY` has access to the models you are selecting.
*   Gen-4 Turbo is **Image-Only**. Ensure you are uploading an image.

**Frontend not reflecting changes**
*   If you change `.env` or backend configs, restart the frontend to clear cache:
```bash
docker restart forge-frontend
```

**Database Connection Error**
*   Ensure no other local Postgres service is running on port 5432, or update `DOCKER_PORT` in `.env`.
