[noun] + の + 代わりに [verb (plain)] + 代わりに [i-adj] + 代わりに [na-adj] + な + 代わりに
代わりに means "instead of": one thing takes the place of another. A noun takes の before it, and a verb comes before it in the plain form.
After something done for you or given to you, 代わりに means "in return": the second half is what evens things up.
After an adjective, 代わりに weighs one quality against another: the good side makes up for the bad, or the other way round. A な-adjective keeps な.
These go beyond 代わりに after a word.
At the start of a sentence, そのかわり代わり or そのかわり代わりに means "in return", "but then".
Straight after a noun, with no の, 代わりに means "serving as": one thing is used as another.