# CloudVault 2.0 – Backend Setup Guide

This guide describes how to run and configure the CloudVault 2.0 Centralized Backend.

---

## 🚀 Quick Start (Development)

### 1. Prerequisites
- Python 3.10+
- `pip` package manager

### 2. Install Dependencies
```bash
pip install -r backend/requirements.txt
```

### 3. Run Database Migrations
CloudVault 2.0 uses SQLAlchemy and Alembic with support for both PostgreSQL and SQLite.

```bash
python -m backend.migrate
```

### 4. Start Central Backend Server
```bash
python backend/app.py
```
By default, the server listens on all network interfaces (`0.0.0.0`) on port **5000**.
Both the REST API (`/api/...`) and the built React Web App (`/`) are served simultaneously!

---

## 🐘 Production PostgreSQL Setup

To connect to a production PostgreSQL database:

1. Create a PostgreSQL database:
```sql
CREATE DATABASE cloudvault;
CREATE USER cloudvault_user WITH ENCRYPTED PASSWORD 'secure_password';
GRANT ALL PRIVILEGES ON DATABASE cloudvault TO cloudvault_user;
```

2. Set the `DATABASE_URL` environment variable:
```bash
export DATABASE_URL="postgresql://cloudvault_user:secure_password@localhost:5432/cloudvault"
```

3. Run migrations:
```bash
python -m backend.migrate
```

4. Run with a production WSGI server (e.g. Gunicorn):
```bash
gunicorn --bind 0.0.0.0:5000 backend.app:app --workers 4
```

---

## ⚙️ Environment Variables

| Variable | Default | Description |
|---|---|---|
| `DATABASE_URL` | `sqlite:///backend/cloudvault_central.db` | PostgreSQL or SQLite connection string |
| `JWT_SECRET_KEY` | `cloudvault_super_secret_jwt_key_2026` | Secret key used for signing JWT tokens |
| `PORT` | `5000` | Port on which Flask server listens |
| `GOOGLE_CLIENT_ID` | Built-in | Google Cloud OAuth 2.0 Web Client ID |
