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

# Backend Implementation

This guide provides an overview of implementing secure tenant dashboard management using HMAC signature authentication for enterprise-grade multi-tenant security.

## Architecture Overview

```
Your API (Tenant Management)
    ↓
HMAC Signed Request → Papermap Dashboard API
    ↓
Dashboard Created/Retrieved
    ↓
Generate Iframe Token (HMAC Signed)
    ↓
Frontend Embeds Dashboard
```

### Key Components

1. **TenantDashboard Model** - Maps tenants to Papermap dashboards
2. **HMAC Signature Service** - Securely authenticates API requests
3. **Dashboard Handler** - Creates dashboards and generates embed tokens
4. **Dashboard Router** - API endpoints for dashboard operations

## Quick Start

Follow these guides in order to implement the backend:

**1. Set Up Authentication**

Implement HMAC signature authentication to securely communicate with the
Papermap API.

> [card] [HMAC Authentication](https://docs.papermap.ai/documentation/multi-tenancy/authentication.md)
>
> Learn how to implement HMAC-SHA256 signature authentication

**2. Create Dashboards**

Set up the ability to create and manage dashboards for your tenants.

> [card] [Creating Dashboards](https://docs.papermap.ai/documentation/multi-tenancy/creating-dashboards.md)
>
> Learn how to create dashboards via the Papermap API

**3. Generate Embed Tokens**

Generate secure tokens to embed dashboards in your frontend.

> [card] [Iframe Embed Tokens](https://docs.papermap.ai/documentation/multi-tenancy/iframe-tokens.md)
>
> Learn how to generate secure embed tokens

**4. Build API Endpoints**

Create REST API endpoints for your frontend to interact with.

> [card] [API Endpoints](https://docs.papermap.ai/documentation/multi-tenancy/api-endpoints.md)
>
> Example REST API endpoints for dashboard operations

**5. Secure Your Implementation**

Follow security best practices for production deployment.

> [card] [Security Best Practices](https://docs.papermap.ai/documentation/multi-tenancy/security.md)
>
> Learn about security considerations and best practices

## Database Model

First, create a model to link your tenants to their Papermap dashboards:

> [!NOTE]
>
> It is not required to save it this way, but you need to have a way to map your tenant to their dashboards.

```python Python theme={null}
from sqlalchemy import  Column, String

from .database import Base
class TenantDashboard(BaseModel):
    __tablename__ = 'tenant_dashboards'

    tenant_id = Column(String(255), nullable=False, index=True)
    workspace_id = Column(String(255), nullable=False)
    dashboard_id = Column(String(255), nullable=False)
```

```sql POSTGRESQL theme={null}
  CREATE TABLE tenant_dashboards (
    id SERIAL PRIMARY KEY,
    tenant_id VARCHAR(255) NOT NULL,
    workspace_id VARCHAR(255) NOT NULL,
    dashboard_id VARCHAR(255) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX idx_tenant_id ON tenant_dashboards (tenant_id);
```

```sql MYSQL theme={null}
CREATE TABLE tenant_dashboards (
    id INT AUTO_INCREMENT PRIMARY KEY,
    tenant_id VARCHAR(255) NOT NULL,
    workspace_id VARCHAR(255) NOT NULL,
    dashboard_id VARCHAR(255) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    INDEX idx_tenant_id (tenant_id)
);
```

**Purpose**: Links your tenant to a Papermap dashboard ID for secure access and isolation.

## Prerequisites

Before implementing, ensure you have:

* Papermap API credentials (API Key ID and Secret Key)
* Your workspace ID
* API endpoint URL (obtain from your Papermap dashboard settings)

> [!WARNING]
>
> **Security Best Practices:** - Never hardcode API endpoints, keys, or secrets
> in your code - Always use environment variables or a secrets management system
>
> * The API endpoint URL should be treated as sensitive configuration - Store
>   credentials securely and rotate them regularly

## Environment Configuration

Store your credentials securely in environment variables:

```bash .env theme={null}
PAPERMAP_API_KEY_ID=your-api-key-id
PAPERMAP_SECRET_KEY=your-secret-key-never-share
PAPERMAP_API_URL=<your-api-endpoint>
```

> [!NOTE]
>
> **Obtaining Your Configuration:** - **API Credentials**: Available in your
> Papermap dashboard under **Settings → API Keys** - **API Endpoint**: Available
> in **Settings → API Configuration** - Always use the values provided in your
> dashboard for your specific workspace

## Implementation Guides

> [card] [HMAC Authentication](https://docs.papermap.ai/documentation/multi-tenancy/authentication.md)
>
> Implement secure HMAC signature authentication

> [card] [Creating Dashboards](https://docs.papermap.ai/documentation/multi-tenancy/creating-dashboards.md)
>
> Create and manage dashboards for tenants

> [card] [Iframe Tokens](https://docs.papermap.ai/documentation/multi-tenancy/iframe-tokens.md)
>
> Generate secure embed tokens

> [card] [API Endpoints](https://docs.papermap.ai/documentation/multi-tenancy/api-endpoints.md)
>
> Build REST API endpoints

> [card] [Tenant Usage](https://docs.papermap.ai/documentation/multi-tenancy/tenant-usage.md)
>
> Track per-tenant credit consumption

> [card] [Security](https://docs.papermap.ai/documentation/multi-tenancy/security.md)
>
> Security best practices

> [card] [Best Practices](https://docs.papermap.ai/documentation/multi-tenancy/best-practices.md)
>
> Performance and scalability tips

## Common Pattern Reference

The HMAC signature pattern for tenant dashboards follows this flow:

```
1. Create Payload
   payload = workspace_id + valid_until

2. Generate Signature
   signature = HMAC-SHA256(payload, secret_key)

3. Send Request with Headers
   X-API-Key-ID: <api_key>
   X-Workspace-ID: <workspace_id>
   X-Valid-Until: <timestamp>
   X-Signature: <signature>

4. Store Result
   tenant_id → dashboard_id mapping

5. Generate Embed Token
   Encode {tenant_id, dashboard_id, signature, expires} as base64
```

This pattern ensures secure, time-limited access to tenant-specific dashboards.

## Next Steps

> [card] [Frontend Setup](https://docs.papermap.ai/documentation/multi-tenancy/setup.md)
>
> Learn how to embed dashboards in your frontend application


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