# Deployment Guide

This guide details the process for deploying the Encord application to a production environment. Given the decoupled architecture (React Frontend + Supabase Backend), deployment involves two distinct, critical stages.

### 1. Backend Deployment (Supabase)

The backend is fully managed by the Supabase platform, but requires critical configuration of the database schema and security policies.

#### 1.1. Project Initialization

1. **Supabase Project Creation**: Create a new project within the Supabase dashboard. Note the **Project URL** and the **Anon Public Key**.
2. **Database Migration**: Execute all SQL migration files located in the local project's `/supabase/migrations` directory against the new Supabase PostgreSQL instance. This step creates the `users`, `conversations`, and `messages` tables, along with all necessary indices and foreign key constraints.
3. **Function and Trigger Setup**: Ensure that custom PostgreSQL functions (e.g., `get_or_create_conversation`, `increment_points`) are correctly defined and installed, typically by including them in the migration scripts.
4. **Row Level Security (RLS) Activation**: **MANDATORY**: Verify that Row Level Security is enabled on all core tables (`users`, `conversations`, `messages`) and that the associated policies are active. This is the primary security mechanism protecting data integrity.

#### 1.2. Environment Variables

Ensure the production environment variables match the Supabase project configuration:

* `VITE_SUPABASE_URL`: The production URL of the Supabase instance.
* `VITE_SUPABASE_ANON_KEY`: The production anonymous key.

### 2. Frontend Deployment (Vite/React)

The React single-page application (SPA) can be deployed to any static site hosting service (e.g., Vercel, Netlify, Cloudflare Pages) or a CDN (Content Delivery Network) for low-latency global access.

#### 2.1. Build Process

The application must be compiled for production using the Vite build tool.

1. **Set Production Variables**: Ensure the production environment variables are correctly injected into the build process.
2. **Execute Build Command**:

   ```
   npm run build
   ```
3. **Artifact Generation**: This command generates the optimized static assets (HTML, CSS, bundled JavaScript) in the `dist` directory.

#### 2.2. Hosting Configuration

1. **Deployment**: Upload the contents of the `dist` directory to the chosen static hosting provider.
2. **Single-Page Application (SPA) Routing**: Configure the hosting service to redirect all unmatched routes to the `index.html` file. This is crucial for client-side routing, preventing 404 errors when a user navigates directly to a sub-route (e.g., `/chat/123`).
3. **HTTPS Enforcement**: **MANDATORY**: Ensure that the deployed application is served exclusively over HTTPS. All cryptographic operations, especially key generation and proof validation, require a secure context.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://encord.gitbook.io/encord-docs/advanced-guides-and-reference/deployment-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
