There's a field called "industrial engineering":
https://en.wikipedia.org/wiki/Industrial_engineering
"Industrial engineering is an engineering profession that is concerned with the optimization of complex processes, systems, or organizations by developing, improving and implementing integrated systems of people, money, knowledge, information and equipment. Industrial engineering is central to manufacturing operations."
In the university I attended, the engineering school had a degree program for it.
Also, I'd presume that depending on what the factory produces, you'd have electrical, chemical, mechanical, aerospace, etc. engineers involved in designing and building the factory.