Purpose: Refactor your Flask server into the Model-View-Controller (MVC) design pattern. Web code can get messy very quickly when you mix data, display, and logic. A popular and successful way of separating the code is to visualize your server-side code as three components interacting: Model, View, and Controller.
Model files (function definitions for accessing and interpreting the data; in this case, please call them get_professionals(), get_services(), and get_navlinks() and put them in "model.py"). Separating this code enables us to see the data as an independent repository with its own protocol (functions) for accessing it. We try to design the functions so that we could change the data storage into something completely different without changing any of the other code (for example, in Project Part 3, we will change JSON data files for a SQLite database, but the functions remain the same).
View files (HTML/CSS/JS content and static content; in this case, your templates/ and static/ directories are both view directories). Separating this code makes it so the server logic is independent of the display logic. It also enables us to have multiple views without changing the rest of the code (for example, one set of files to display on a mobile phone and one set of files to display on a web browser).
Controller files (route handling logic; in this case, your app.py file is the controller and should only ever use model functions from model.py to load the JSON files). Separating this code allows us to change the big-picture server logic (routing, URL handling, decision-making) without making it dependent on the way the data is stored or the view is delivered. The controller is always the first code to deal with the incoming request and organizes how the others are used.
Ensure that your code is organized into the MVC design pattern by separating the data functions into model.py and ensuring that all the HTML remains in the templates.
By the end of this step, your project should work on localhost, delivering the same content as Project Part 1, and should be ready to deploy to the webhost using the Project Deployment Instructions in Canvas. Students often run into deployment issues, so don't assume you are done until your project works properly on the webhost as well as localhost.