Mods allow you to change your weapons to fit your play style.
A weapon can have, besides a vanity slot called skin, 4 slots for mods. These are magazine, optics muzzle and underbarrel.
Optics, Muzzle and Underbarrel have each two different versions.
Optics come in short and long, muzzle in small and large, and underbarrel in short and long.
You can find these by looting enemies and chests or by Crafting.
Once a mod is installed, you can always remove it again. You can also remove all mods from a weapon quickly to strip the weapon. When attaching mods you can see all mods you have, including the ones on weapons, showing you with a link symbol which ones are already attached to somewhere else and with an arrow down which is the one on your current weapon.