All detergent has the same basic structure. Their molecules have a hydrocarbon chain which is covalently bonded and will not attract water molecules (the chain is said to be hydrophobic or water hating), and a small ionic group which ready attracts, and dissolves in, water molecules (a hydrophilic part).
In case of ordinary soap, which may contain a large proportions of sodium stearate, the hydrophobic part is the long hydrocarbon chain of -CH2- unit (the tail) and the hydrophilic part is the ionic -COOH- group (the head) at the end. Soapless detergents have similar structures although the ionic group is then usually sulphate or sulphonate.
When a detergent is added to water the hydrophilic group attract water molecules but the hydrophobic group repel them. The effect is to reduce the intermolecular forces, and consequently the surface tension, so that the molecules of water are spread more evenly.