Skip to content

Conversation

@mjunaidca
Copy link
Owner

Implement #20

After review, multi-tenancy is much simpler than originally scoped:

Changes Required (API only - 4 files)

File Change
models/project.py Add tenant_id: str = Field(index=True)
schemas/project.py Add tenant_id to create/read schemas
auth.py Extract tenant_id from JWT OR use default "taskflow"
routers/projects.py Add .where(Project.tenant_id == tenant_id) to all queries

Why Other Components Don't Need Changes

  • MCP Server: Calls API via HTTP → gets filtered results → no code changes
  • Frontend: Sends JWT to API → gets filtered results → no code changes
  • Tasks/Workers: Already scoped by project_id → inherit tenant boundary

Simplified Strategy

Use a default tenant ("taskflow") for all users initially. This avoids SSO changes and org-switching complexity.

Estimated Time: 30-45 minutes

mjunaidca and others added 5 commits December 10, 2025 15:35
Implement multi-tenancy support to scope projects by organization:

- Add tenant_id field to Project model (default: "taskflow")
- Create get_tenant_id() function with JWT → header → default priority
- Update all 5 project endpoints with tenant filtering
- Per-tenant slug uniqueness (same slug allowed across tenants)
- Return 404 for cross-tenant access (prevents enumeration)
- Include tenant_id in all audit log entries

Tests: 5 new tests, 61 total passing

Files modified:
- models/project.py: Added tenant_id field
- auth.py: Added get_tenant_id(), updated CurrentUser
- schemas/project.py: Added tenant_id to ProjectRead
- routers/projects.py: Tenant filtering on all endpoints
- tests/test_multitenancy.py: New comprehensive test suite

Specs: specs/009-multi-tenancy/ (spec.md, plan.md, tasks.md)
PHRs: history/prompts/multi-tenancy/ (4 records)

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive documentation explaining:
- Tenant = namespace (which projects exist)
- Membership = access (which projects you can use)
- Principle of least privilege: same-org users don't auto-see all projects
- User workflow: create own projects, get invited to others
- Access matrix for all scenarios

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Changes:
- Rename default tenant from "taskflow" to "taskflow-default-org-id"
- Fix ensure_default_project to explicitly set tenant_id from user context
- Fix slug collision check to be per-tenant (not global)
- Pass request to ensure_user_setup for proper tenant extraction
- Update spec and tests for new default tenant name

Bug fixes:
- Default project was not setting tenant_id explicitly (relied on model default)
- Slug collision check was global, should be per-tenant

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@mjunaidca mjunaidca merged commit 51845df into main Dec 10, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant