/tenantkit

Template for running sveltekit with landlord tenancy capabilities. Each tenant runs on their own Database, ensuring tenant data is isolated per client.

Primary LanguageSvelteMIT LicenseMIT

SvelteKit Landlord Tenancy Template

This repository is a template for running a multi-tenant application with SvelteKit, leveraging a landlord-tenant architecture where each tenant has its own isolated database. This approach ensures data security and separation for each client.

Getting Started

Warning

This template is still in development, this readme is more so a place holder for later.

Prerequisites

  • Bun installed on your machine.
  • Docker installed for database containerization.

Installation and Setup

  1. Clone the Repository
git clone <repository-url>
cd <repository-folder>
  1. Start the Database Navigate to the ./docker/ folder and run the following command to spin up the database using Docker Compose:
docker-compose up -d
  1. Generate your first migration In order for the database to have the current schema run:
# Generate a initial migration
bun run landlord:migration
# Seed the database with utility functions and stuff
bun run landlord:seed
# Apply all or the current migration
# NOTE: You can pass any of drizzles arguments to migrate (e.g: --name "xyz")
bun run landlord:migrate
  1. Run the Development Server Start the development server with Bun:
bun run dev
  1. Run Database Migrations

    After the database is running, apply migrations for the landlord database:

    bun run landlord:migrate
  2. Seed the Landlord Database

    Seed the landlord database with initial data:

    bun run landlord:seed

Running Migrations for Tenants

After setting up the landlord, you can create tenants, and each tenant will run on its own database. Ensure that tenant migrations are applied appropriately using Drizzle ORM.

Additional Commands

  • Start Tenant-Specific Database: Once a tenant is created, use tenant-specific migration commands similar to the landlord.
  • Run in Production: Use bun run build for building the project and start it with bun run start.

Technologies Used

  • Bun: A modern runtime for running JavaScript and TypeScript applications.
  • SvelteKit: Reactive framework for building web applications.
  • Tailwind CSS: Utility-first CSS for styling.
  • ShadCN UI: UI component library for modern design.
  • Drizzle ORM: Manage database schemas and migrations.

Notes

  • Be sure to run the Docker containers to set up the database correctly before starting the server.
  • Migrations and seeds are essential to configure the landlord's database before onboarding tenants.

Enjoy building your multi-tenant SvelteKit application with this template!