ANN with arbitrary number of layers and outputs

Hi, I am trying to build a multitask learning neural network similar to the following image.

For a small number of tasks, I can easily manually code each layer and task. However, for a large number of tasks, e.g., the number of tasks > 100, I don’t know how to scale my code. Is there any guideline on how to properly build a network with an arbitrary number of layers and outputs?

Thanks