SemiLayerDocs

Connect a Source

A Source is a connection to an existing data source — a database, API, file store, or anything a Bridge can read from. Sources are scoped to an Environment and their credentials are stored encrypted per-organization.


What You'll Need

  • A running SemiLayer environment (see Organization Setup)
  • A bridge package for your data source type (e.g. @semilayer/bridge-postgres)
  • Connection credentials (URL, API key, etc.)

Connect via the CLI

semilayer sources connect

The wizard prompts for:

  1. Bridge — the package name (e.g. @semilayer/bridge-postgres)
  2. Source name — the identifier used in sl.config.ts (e.g. main-db)
  3. Connection details — URL or other bridge-specific config

After connecting, SemiLayer introspects the source and lists available tables, collections, or endpoints.


Connect via the Console

Settings → Sources → Connect source

Fill in the same fields. After saving, the Console shows the introspected targets and their schema (column names, types, estimated row count).


Reference in sl.config.ts

Once a source is connected, reference it by name in your config:

import { defineConfig } from '@semilayer/core'

export default defineConfig({
  stack: 'my-app',
  sources: {
    'main-db': {
      bridge: '@semilayer/bridge-postgres',
    },
  },
  lenses: {
    products: {
      source: 'main-db',      // ← matches the source name above
      table: 'public.products',
      // ...
    },
  },
})

The connection string itself lives in the service (stored encrypted) — not in sl.config.ts. Your config only references the bridge type and source name.


Available Bridges

Data SourcePackage
PostgreSQL@semilayer/bridge-postgres
More — contribute yoursBridge SDK

Bridges are installed as npm packages. The worker resolves them at runtime via @semilayer/bridge-resolver.


Multiple Sources

A single environment can have multiple sources. Each lens declares which source it reads from:

sources: {
  'postgres-main': { bridge: '@semilayer/bridge-postgres' },
  'postgres-analytics': { bridge: '@semilayer/bridge-postgres' },
},
lenses: {
  products:  { source: 'postgres-main',      table: 'products', /* ... */ },
  pageviews: { source: 'postgres-analytics', table: 'pageviews', /* ... */ },
},

Managing Sources

semilayer sources list           # list all sources in the current environment
semilayer sources remove --name main-db

Or from the Console: Settings → Sources.


Next Steps

With a source connected:

  1. Schema (Config) — define lenses over your source
  2. Push & Ingest — push the config and start indexing