Sinatra Project MVC and CRUD

MVC

The structure of this project is an MVC structure. MVC stands for Model, View, Controller and each of these are it’s own folder inside of the app folder.

The best way to explain this structure is the the restaurant example. The customers are the users and their food would be the view file. They see the end product of all the work going on between the chef and the waitress/waiter. The customer orders food (makes a request) the waiter/waitress is the controller, they take the information to the chef who is the model. The model carries out the logic, pulls from a database and sends back a consistent response based on the controller’s instructions. So the chef gets together all the ingredients and combines them and sends the information back to the controller (the waiter/waitress). The controller then take the food to proper customer. The proper is important because as you can imagine the waitress/waiter has many customers, so the controller has to make sure the data goes to the proper view file.

This way of structuring your applications allows for more organized files and functions of the application and it allows for easier collaboration and communication on projects. When everything has a place it’s easier to find and it’s easier to teach someone who is new to the project. This framework is something almost all software engineers follow.

CRUD

CRUD stands for: Create, Read, Update and Delete. These are the four basic functions that a model should be able to preform. Create should be when something new is requested. Say someone orders food at the restaurant, they just created a new object order. It is then stored with a unique id or table number. The read would be like the chef reading all the order and sending out the correct food that was requested. Update is used to modify data already in the database. For example say the chef wants to change the ingredients on a particular item, he would change the item then let the database know aka the menu. Delete is pretty self explanatory imagine if an item isn’t selling well at the restaurant and it must be taken off. Well the chef would take it off the menu aka taking it out of the database.

Here are some CRUD actions from my application for the sinatra project. The actions will include routes and if you’d like to learn more about routes you can just follow this link here.

Most applications have both MVC and CRUD happening on their project it allows for a smoothing workflow and easier teaching layout. I hope this blog helped someone out who is struggling with understanding these two concepts. Here is the link to my project in case any of you would like to have a look.

Full stack software engineer