Homebrew installs the stuff you need that Apple (or your Linux system) didn’t. Homebrew installs packages to their own directory and then symlinks their files into /usr/local.
Homebrew won’t install files outside its prefix and you can place a Homebrew installation wherever you like. Trivially create your own Homebrew packages. It’s all Git and Ruby underneath, so hack away with the knowledge that you can easily revert your modifications and merge upstream updates.
Homebrew formulas are simple Ruby scripts.