npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@dzangolab/fastify-multi-tenant

v0.79.0

Published

Fastify multi-tenant plugin

Readme

@dzangolab/fastify-multi-tenant

A Fastify plugin that adds support for multi-tenant architecture in your API.

Requirements

Tenants table

You need to create a table containing the tenants. You can name the table as you wish. The default name is tenants.

The table should contain the following columns:

| Purpose | Type | Constraints | Default column name | |--------------|-----------------------------------|---------------------------|----------------------| | Identifier | integer \| varchar(255) \| uuid | PK | id | | Display name | varchar(255) | NOT NULL | name | | Owner ID | varchar(36) | | owner_id | | Slug | varchar(63) | NOT NULL UNIQUE | slug | | Domain | varchar(255) | UNIQUE | domain | | created_at | TIMESTAMP | DEFAULT NOW() NOT NULL | created_at | | updated_at | TIMESTAMP | DEFAULT NOW() NOT NULL | updated_at |

The owner_id column serves as a foreign key referencing the id column in the users table.

Installation

Install with npm:

npm install @dzangolab/fastify-config @dzangolab/fastify-mailer @dzangolab/fastify-slonik @dzangolab/fastify-multi-tenant @dzangolab/fastify-user

Install with pnpm:

pnpm add --filter "@scope/project" @dzangolab/fastify-config @dzangolab/fastify-mailer @dzangolab/fastify-slonik @dzangolab/fastify-multi-tenant @dzangolab/fastify-user

Usage

Register the fastify plugin

Register the plugin with your Fastify instance:

import configPlugin from "@dzangolab/fastify-config";
import mailerPlugin from "@dzangolab/fastify-mailer";
import multiTenantPlugin, { tenantMigrationPlugin } from "@dzangolab/fastify-multi-tenant"
import slonikPlugin, { migrationPlugin } from "@dzangolab/fastify-slonik"
import userPlugin from "@dzangolab/fastify-user";
import Fastify from "fastify";

import config from "./config";

import type { ApiConfig } from "@dzangolab/fastify-config";
import type { FastifyInstance } from "fastify";

const start = async () => {
  // Create fastify instance
  const fastify = Fastify({
    logger: config.logger,
  });
  
  // Register fastify-config plugin
  await fastify.register(configPlugin, { config });

  // Register mailer plugin
  await fastify.register(mailerPlugin, config.mailer);
  
  // Register database plugin
  await fastify.register(slonikPlugin, config.slonik);
  
  // Register multi tenant plugin
  await fastify.register(multiTenantPlugin);
  
  // Register user plugin
  await fastify.register(userPlugin);
  
  // Run app database migrations
  await fastify.register(migrationPlugin, config.slonik);
  
  // Run tenant database migrations
  await fastify.register(tenantMigrationPlugin);

  await fastify.listen({
    port: config.port,
    host: "0.0.0.0",
  });
};

start();

Configuration

If you are not using the default table name and columns, add the following configuration to your config:

const config: ApiConfig = {
  // ...
  multiTenant: {
    reserved: {
      slugs: ["..."],
      domains: ["..."],
    },
    rootDomain: "";
    table: {
      columns: {
        id: "...",
        domain: "...",
        name: "...",
        ownerId: "...",
        slug: "...",
      },
      name: "...",
    },
  }
};

Using GraphQL

This package supports integration with @dzangolab/fastify-graphql.

Configuration

Add the required context for the fastify-user package by including multiTenantPlugin in your GraphQL configuration as shown below:

import multiTenantPlugin from "@dzangolab/fastify-multi-tenant";
import userPlugin from "@dzangolab/fastify-user";
import type { ApiConfig } from "@dzangolab/fastify-config";

const config: ApiConfig = {
  // ...other configurations...
  graphql: {
    // ...other graphql configurations...
    plugins: [userPlugin, multiTenantPlugin],
  },
  // ...other configurations...
};

Schema Integration

This package does not provide a predefined schema. To integrate it into your GraphQL setup, add the following to your GraphQL schema:

type Tenant {
  id: Int!
  name: String
  slug: String!
  domain: String
  ownerId: String
  createdAt: Float!
  updatedAt: Float!
}

type Tenants {
  totalCount: Int
  filteredCount: Int
  data: [Tenant]!
}

input TenantCreateInput {
  name: String
  slug: String!
  domain: String
}

type Mutation {
  createTenant(data: TenantCreateInput): Tenant @auth
}

type Query {
  allTenants(fields: [String]): [Tenant]! @auth
  tenant(id: Int): Tenant @auth
  tenants(limit: Int, offset: Int, filters: Filters, sort: [SortInput]): Tenants! @auth
}

Resolver Integration

To integrate the resolvers provided by this package, import them and merge with your application's resolvers:

import { tenantResolver } from "@dzangolab/fastify-multi-tenant";

import type { IResolvers } from "mercurius";

const resolvers: IResolvers = {
  Mutation: {
    // ...other mutations ...
    ...tenantResolver.Mutation,
  },
  Query: {
    // ...other queries ...
    ...tenantResolver.Query,
  },
};

export default resolvers;