In addition to what everyone has said about riding safely in traffic I would like to add hold your line and stay calm. Train yourself to not react to a sudde honk by jerking the handlebars. Learn to look back signal and brake without changing your line of travel, Slow down and leave lots of safety distance ahead of you and to your side whenever possible, can't do much about behind you except be aware and look back when its safe to let them know you know they are there. Hold a steady speed and ride as evenly. Concentrate on being aware of what is going on around you by not wearing ear pods or blue tooth and finally I swear by my rear view mirror but always look back and double check before doing anything. Also continual experience helps. Like anything else, practice in baby steps by learning when the traffic periods and places are and avoiding them whenever possible.
Trek Madone 6.5- "Red"
Trek Pilot 5.2- " Bebe"
"easily outrun by a chihuahua."