Hardness comes from metal ions like Ca, Mg, Na, Fe which react with phosphates in the mash to release protons, thus counteracting the pH raising effect of alkalinity.
Alkalinity (the measure of resistance to change in pH) comes from carbonates/bicarbonates/hydroxide...