The problem Composite solves
You're building the monthly cloud bill. A service costs money — an EC2 fleet, an S3 bucket, an RDS instance. A project is a bag of services. An account is a bag of projects. And a sub-account is a bag of accounts, because someone acquired a company.
So totalFor(thing) starts as one if, and grows: is it a service? Return its cost. Is it a project? Loop its services. An account? Loop its projects, and inside each, loop its services. Every function that touches the tree — cost, tagging, the CSV export, the "which team owns this" report — grows its own copy of that same nested walk.
Then the sub-account arrives and every one of those functions is wrong by one level of nesting. The bug isn't that the code is complicated. It's that the caller is being asked to know the shape of the tree in order to ask a simple question.
