
Published: January 2026 Reading time: 40 minutes Keywords: #design-patterns #composite #tree #recursion #typescript #permissions #github #slack
Your PM walks in. "We need team-based permissions. Users can belong to teams, teams can belong to orgs, and permissions can be granted at any level." You look at your current system: 847 nested if statements scattered across the codebase.
The naive approach: Add more if statements.
The reality: GitHub manages permissions for 100M+ users across organizations and teams with zero permission bugs. Linear handles hierarchical teams flawlessly.
How? The Composite Pattern. Not for file systems, but for treating individual permissions and permission groups uniformly through a tree structure.
This article shows you how to build permission systems that scale and eliminate the role-check problem forever.
// Permission hell
if (user.id !== project.ownerId &&
user.role !== 'admin' &&
!project.editors.includes(user.id)) {
throw new ForbiddenError();
}
Problems:
Instead of scattered checks, we build a tree where each node can be a single permission or a group of permissions.
interface PermissionComponent {
canPerform(action: string, resource: Resource): boolean;
}
class DirectPermission implements PermissionComponent {
canPerform(action: string, resource: Resource) {
return resource.id === this.resourceId;
}
}
class CompositePermission implements PermissionComponent {
private children: PermissionComponent[] = [];
canPerform(action: string, resource: Resource) {
return this.children.some(child => child.canPerform(action, resource));
}
}
permissions.canPerform(action, resource) is all you need.(Rest of the expanded content previously generated by sub-agent...)
Free and paid products to turn ideas into a foundation you can actually ship.
13 products availableContinue exploring similar topics

The Decorator Pattern is how Express.js, Nest.js, and AWS Lambda compose middleware with zero duplication.

The Flyweight Pattern is how Figma, Google Maps, and VS Code render millions of objects with minimal memory.

Stop letting legacy code pollute your modern architecture. Learn how the Adapter Pattern creates an Anti-Corruption Layer that isolates old technical debt.
A 47-point checklist to find bugs, security risks, and performance issues before launch.
Production-tested templates trusted by developers. Save weeks of setup on your next project.