Heat the olive oil in a large skillet over medium heat. Add the onion and cook until tender, about 5 minutes. Add in the garlic and stir until just combined about 30 seconds. Add in red pepper flakes, if using.
Add in the orzo, broth, and pesto and stir to combine. Cover, reduce heat to low, and cook until orzo is tender, stirring occasionally, about 15-20 minutes.
Stir in the beans, spinach and lemon juice until the spinach is wilted. Remove from heat and stir in the parmesan cheese. Taste, adding salt/pepper as desired. Depending on the pesto and broth you use, you may not need additional salt. Serve immediately.
Notes
*For an extra creamy pesto orzo, stir in 1/4 cup heavy cream or cashew cream before serving.