Skip to content

feat: add tenant isolation middleware#9

Open
aabrius wants to merge 2 commits into
masterfrom
feature/tenant-isolation-docs
Open

feat: add tenant isolation middleware#9
aabrius wants to merge 2 commits into
masterfrom
feature/tenant-isolation-docs

Conversation

@aabrius

@aabrius aabrius commented Dec 7, 2025

Copy link
Copy Markdown
Contributor

Summary

  • Implements subdomain-based tenant resolution middleware
  • Adds tenant configuration with multiple strategies (header, subdomain, path)
  • Handles localhost, IP addresses, and reserved subdomains (www, api)
  • Sets tenant context in CLS for downstream services
  • Adds 40 unit tests for middleware and configuration

Test plan

  • Run npm test -- --testPathPattern="subdomain-tenant.middleware|tenant.config" to verify all tests pass
  • Test with different subdomains in browser

🤖 Generated with Claude Code

aabrius and others added 2 commits December 6, 2025 22:23
- Add comprehensive multi-tenancy documentation covering:
  - Header-based tenancy (current implementation)
  - Subdomain-based tenancy (new option)
  - Path-based tenancy
  - Row-level security (PostgreSQL)
  - Separate schemas/databases

- Add SubdomainTenantMiddleware for subdomain-based tenant resolution
- Add TenantConfig types and configuration utilities

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add subdomain-tenant.middleware.spec.ts with 16 tests covering:
  - Subdomain extraction from various hostname formats
  - Skip subdomains (www, api, localhost)
  - Case-insensitive subdomain matching
  - Custom resolveAccountBySubdomain implementation
  - CLS context setting
  - 404 error for unknown tenants
- Add tenant.config.spec.ts with 24 tests covering:
  - TenantStrategy enum values
  - defaultTenantConfig defaults
  - getTenantConfig environment parsing
  - TENANT_STRATEGY, TENANT_HEADER_NAME, APP_DOMAIN
  - SKIP_SUBDOMAINS parsing with whitespace trimming
  - ALLOW_NO_TENANT boolean parsing
- Add Jest moduleNameMapper for src/* path resolution

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 7, 2025

Copy link
Copy Markdown

Warning

Rate limit exceeded

@aabrius has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 27 minutes and 29 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 793cb77 and 21a7d44.

📒 Files selected for processing (6)
  • apps/backend/docs/multi-tenancy.md (1 hunks)
  • apps/backend/package.json (1 hunks)
  • apps/backend/src/config/tenant.config.spec.ts (1 hunks)
  • apps/backend/src/config/tenant.config.ts (1 hunks)
  • apps/backend/src/middlewares/subdomain-tenant.middleware.spec.ts (1 hunks)
  • apps/backend/src/middlewares/subdomain-tenant.middleware.ts (1 hunks)
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/tenant-isolation-docs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant