A novel framework for modelling of electrolysers and fuel cells is presented. The framework features a modular and flexible structure, which enables wide applicability for a variety of fuel cell and electrolyser technologies. The framework is multi-threaded for shared memory architectures. The generic approach for discretisation allows efficient distribution of tasks between processing cores. The physical model is clearly separated from discretisation and the linear solver. This simplifies the model development and provides high flexibility with respect to the discretisation methods, linear solvers, as well as the dimensionality of the application. Irregular grids and complex geometries can be realised through generic mapping of coordinate systems. Single cell models can be easily scaled to short stacks. The framework features are demonstrated with realistic PEMFC and SOEC models. Whilst the PEMFC example focuses on the differences between different model dimensions and different boundary conditions, the SOEC example demonstrates the extension of a transient single cell model to a transient short stack model. The performance scalability with the number of CPUs is demonstrated.