Is the target the source of the difficulty? After every 2016 blocks, the target moves up or down to try and create an average of 10 minutes between blocks.

Up until now, I've believed that it's the difficulty that drives this change, as though the difficulty is stored on disk somewhere, and the target is calculated from this key metric.

However, the only changes I see being stored on disk and shared between nodes is the target (via the bits field in the block header). This leads me to believe that the difficulty is merely a representation of the changing targets, and it's not the actual source of the target values.

So basically, am I right in saying that the difficulty is calculated from the target, and not the other way around?

e.g: bits -> target -> difficulty?
So basically, am I right in saying that the difficulty is calculated from the target, and not the other way around?


That is correct. Difficulty is just a concept introduced to make the target value easy to represent for humans.  It has no meaning internally.