Usually, the generator control panel takes care of, at least, provisioning the transfer and usually integrates the transfer switch.
Return to utility power doesn't happen immediately. There are some stability/time checks before that happens.
I just picked one just to look at for features:
http://www.transferswitch4less.com/ascose.htm
The controllers also do generator exercising. Some incorporate monitoring of utility and generator power. Soem even interface to Ethernet.
Some may have the ability to do load sheding. An example, would be to run the whole house, but not the air conditioning.
Generally, you have to have an approved transfer switch, so it's not something that you build. The creiteria of a "transfer switch" is that they have mechanically interlocked contacts so it's impossibe for both sides to engage simultaneously.
--
Manual transfer can be done with an interlocked breaker on some load centers. Load centers can be professionaly modified for that as well. A "back-feed" breaker is mechanically interlocked with the main breaker. The generator is connected to the "back feed" breaker. Both breakers cannot be on at the same time.