Targets, refId and attributes


I hope someone can help me to understand some features of Grafana dashboards.

I the JSON template, targets have refId and type attributes. What do they do? which kinds of use can they have? do they follow some rules in their definition? for example refId is always A-Z?

Thank you for the clarification