Algebraic means are proposed to rigorously describe and eventually automate the design of cyber-physical systems based on digital twins, as Industry 4.0 demands. Following recent trends, we employ category theory as a mathematical framework. It allows rigorously composing and verifying system models using the universal construction of colimit. For example, we show how to compose a discrete-event simulation of the robotic production line by a suitable colimit. Further, the paper introduces a novel construction of multicomma category, the objects of which describe possible system architectures with a fixed structural hierarchy represented from a certain viewpoint, and morphisms denote actions associated with the parts selection and replacement during the system design. The multicomma category can be built using the universal constructions of product, exponent, and pullback. We present applications of the multicomma in solving direct and inverse problems of heterogeneous cyber-physical systems design. In particular, suitable subcategories of the multicomma apply as generative design spaces for automatic search for (sub-, Pareto-) optimal system architectures.