
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...)
Produtos gratuitos e pagos para transformar ideias em uma base que você consegue executar.
13 produtos disponíveisContinue explorando tópicos similares

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.
Checklist de 47 pontos para encontrar bugs, riscos de segurança e problemas de performance antes do lançamento.
Templates testados em produção, usados por desenvolvedores. Economize semanas de setup no seu próximo projeto.