Categorical and semigroup-theoretic descriptions of Bass-Serre theory