Skip to content

This repository contains comprehensive guides and implementation strategies for building multi-tenant applications using Phoenix 1.8. The documentation focuses on two different multi-tenancy approaches with role-based authorization.

Notifications You must be signed in to change notification settings

ZenHive/OrgsDocs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Phoenix 1.8 Multi-Tenant Authorization Strategies

This repository contains comprehensive guides and implementation strategies for building multi-tenant applications using Phoenix 1.8. The documentation focuses on two different multi-tenancy approaches with role-based authorization.

Overview

Multi-tenancy allows a single application instance to serve multiple tenants (organizations or teams) while maintaining proper data isolation. This repository documents two distinct approaches to implementing multi-tenancy in Phoenix 1.8 applications:

  1. Single-Organization Model: Each user belongs to exactly one organization at a time
  2. Multi-Organization Model: Users can belong to multiple organizations simultaneously with different roles in each

Both approaches use Phoenix 1.8's new Scopes feature and implement role-based authorization using Bodyguard.

Directory Structure

Tenancy Approaches

Single-Organization Model

The single-organization approach is simpler to implement and suitable for applications where users typically belong to just one organization. Key features:

  • Organization ID is stored directly on the user record
  • Each user has a single role (admin, manager, member) within their organization
  • Simpler data structure and queries
  • Includes system administrator functionality that spans across organizations

See: Single-Organization Guide

Multi-Organization Model

The multi-organization approach offers greater flexibility and is ideal for applications where users need to be members of multiple organizations with different roles in each. Key features:

  • Uses a join table (organization_memberships) to connect users to organizations
  • Users can have different roles in different organizations
  • More complex data structure but offers greater flexibility
  • Includes organization switching functionality

See: Multi-Organization Guide

Implementation Checklists

Both approaches include detailed implementation checklists to guide the development process:

Key Components Covered

Both guides cover:

  • Database schema design and migrations
  • Phoenix authentication integration with phx.gen.auth
  • Using Phoenix 1.8's new Scopes for tenant isolation
  • Role-based authorization with Bodyguard
  • LiveView implementation with Phoenix 1.8's component-based approach
  • Comprehensive testing strategies

How to Use These Documents

  1. Choose the appropriate multi-tenancy model for your application requirements
  2. Follow the detailed implementation guide for your chosen approach
  3. Use the implementation checklist to track progress
  4. Reference the specific guides for specialized features (e.g., system administrator implementation)

License

This documentation is provided for educational purposes. Feel free to use these strategies in your own applications.

About

This repository contains comprehensive guides and implementation strategies for building multi-tenant applications using Phoenix 1.8. The documentation focuses on two different multi-tenancy approaches with role-based authorization.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published