> ## Documentation Index
> Fetch the complete documentation index at: https://docs.altitut-sma-center.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Firebase Setup for Self-Hosting Altitut

> Configure your own Firebase project when self-hosting Altitut. Covers creating a project, enabling Firestore and Storage, and setting the required environment variables.

Altitut uses Firebase as its primary persistence layer. Firestore stores all structured application data while Firebase Storage holds the media files your team uploads before publishing. If you are using the hosted Altitut service, Firebase is already configured for you — this guide is for teams **self-hosting** their own Altitut instance who need to connect their own Firebase project.

## What Firebase Powers

> [card] Firestore Database
>
> Real-time NoSQL storage for all your content, posts, and workspace data.

> [card] Firebase Storage
>
> Binary file hosting for videos and images used in the Auto-Post Composer.

> [card] Real-Time Updates
>
> The dashboard reflects data changes instantly without requiring manual refreshes.

> [card] Direct Browser Uploads
>
> Media files upload straight from the browser to Storage, keeping large payloads off your API server.

## Setup

**1. Create a Firebase project**

Go to the [Firebase Console](https://console.firebase.google.com), click **Add project**, and follow the setup wizard. You can reuse an existing Google Cloud project if you have one.

**2. Enable Firestore**

In the Firebase Console, navigate to **Build → Firestore Database** and click **Create database**. Choose **Production mode** and select a region close to your users.

> [!TIP]
>
> Pick a region that matches your API server's region to minimize read/write latency.

**3. Enable Firebase Storage**

Navigate to **Build → Storage** and click **Get started**. Accept the default security rules for now — you will update them in the next step.

**4. Configure Storage security rules**

Update your Storage rules to allow authenticated users to upload media while keeping download URLs publicly readable:

```
rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read: if true;
      allow write: if request.auth != null;
    }
  }
}
```

**5. Register a web app and get client credentials**

In the Firebase Console, go to **Project settings → General** and click **Add app**, selecting the **Web** platform. Firebase will display a configuration object containing your API key, project ID, and other public values — copy these for the environment variables below.

**6. Create a service account**

Go to **Project settings → Service accounts** and click **Generate new private key**. Save the downloaded JSON file securely — you cannot download it again. This is your `FIREBASE_SERVICE_ACCOUNT_JSON`.

**7. Set environment variables**

Add the following variables to your server environment:

```bash theme={null}
# .env.local

# Firebase client SDK (safe to expose to the browser)
NEXT_PUBLIC_FIREBASE_API_KEY=your_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your_project.firebasestorage.app
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_sender_id
NEXT_PUBLIC_FIREBASE_APP_ID=your_app_id

# Firebase Admin SDK (server-only — never expose to the browser)
FIREBASE_SERVICE_ACCOUNT_JSON='{ "type": "service_account", ... }'
FIREBASE_STORAGE_BUCKET=your_project.firebasestorage.app
```

**NEXT\_PUBLIC\_FIREBASE\_**\* `string` *required*

Client SDK configuration values found in **Project settings → General → Your apps**. These are safe to include in browser-side code.

**FIREBASE\_SERVICE\_ACCOUNT\_JSON** `string` *required*

The full service account JSON as a single-line string. Used exclusively by the server to perform privileged operations. Never expose this to the browser.

**FIREBASE\_STORAGE\_BUCKET** `string` *required*

Your Storage bucket name (e.g., `your-project.firebasestorage.app`). Required by the server to reference the correct bucket.

> [!WARNING]
>
> Never commit `FIREBASE_SERVICE_ACCOUNT_JSON` to source control or expose it in client-side code. A leaked service account key grants full read/write access to your Firestore database and Storage bucket.

**8. Verify the connection**

Start your development server and open the Altitut dashboard. If Firestore is connected correctly, the Content Creation and Auto-Post tabs will load data (or display empty states) without console errors. Upload a test image in the Auto-Post Composer to confirm Storage is working.

> [!NOTE]
>
> If you are deploying to Google Cloud (Cloud Run, App Engine, etc.), the server can use **Application Default Credentials** attached to the service account of your Cloud resource — you may not need to supply `FIREBASE_SERVICE_ACCOUNT_JSON` in that environment.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.