This paper describes the optimal power flow (OPF) architecture implemented in MATPOWER, an open-source Matlab power system simulation package. It utilizes an extensible architecture that allows the user to easily add new variables, constraints and costs to the standard OPF problem formulation while preserving the structure needed to use pre-compiled solvers. A software object is used to encapsulate the definition of the problem formulation, manage the corresponding named sets of variables, constraints and costs, and handle all of the tedious index maintenance tasks. The software design has the advantage of minimizing the coupling between variables, constraints and costs, making it possible, for example, to add variables to an existing model without having to explicitly modify existing constraints or costs to accommodate them. The example of adding joint co-optimization of reserves to the OPF, based on fixed zonal reserve requirements, is used to illustrate the capabilities of MATPOWER's extensible OPF architecture.