The main factor is of course the bean variety.
Up until a few years ago, there were only 3 cocoa varieties:
The farming practices of the cocoa farmer also influence the quality of the bean. So things like the distances between the trees, shadow trees, fertilization, pruning or cutting of branches etc. also play a role.
The fermentation and drying of the beans.
One can even add the storage conditions of the dried beans.
Recently a new classification of the cocoa varieties, based on DNA analysis, shows around 10 varieties.