# Service Connections

Service connections store credentials for third‑party services such as SMTP, SharePoint or Azure AD.
Each record resides in the `service_connections` table and includes:

- `name` – display name for the connection
- `type` – driver name (e.g. `smtp`, `sharepoint`)
- `credentials` – JSON payload with driver‑specific settings
- `tenant_id` and `user_id` – scope of the connection
- `branch_id` – optional branch association

## Inheritance

`ServiceConnectionSettingsController` resolves the current connection using the following order:

1. **User level** – row matching both `tenant_id` and `user_id`.
2. **Tenant level** – row with the current `tenant_id` and a null `user_id`.
3. **Super admin** – global row where both identifiers are null.

This allows administrators to provide default credentials that can be overridden per tenant and even per user.

Super admins manage connections through the `/api/service_connections` endpoints or the UI module with the same name. Permission keys include `service_connections.*` for CRUD operations.

## Adding Drivers

Drivers implement `ConnectionInterface` under `api/services/Connections`.
To add a new service, create the driver class there and register its key inside `ConnectionFactory::createDriver()` and `availableDrivers()`.

## Dashboard Modal

The **Service Connections** modal stored in `ui_modals` displays a table of `service_connections` records. Clicking **Add Connection** opens the `Service Connection` form so administrators can create new credentials.

