A concept for the automatic generation of optimization code for a class of non-linear optimization problems is described and realized at the example of an electric power system optimal power flow problem. The equations are structured based on a node and edge structure given from a network. The goal of this domain engineering approach is the high-level symbolic formulation of this structured optimization problem and the subsequent complete automatic code generation of the solution algorithm in Matlab. The main algorithmic step is the iterative solution of a sparse linear system of equations applied to the Karush-Kuhn-Tucker optimality conditions of the optimization problem. The matrix elements of this linear system to be solved during the solution process consist of sums of first and second order derivative terms of the original, high-level entered function parts. Applying this concept leads to a high quality domain software which seems to form a good compromise both for the developer and the software end-user organisation: High quality requirements can be satisfied with respect to speed, algorithmic robustness, easy core code (model) enhancement and maintenance capabilities for the developer and easy enduser model software parametrization.