The Model layer
As we saw when we presented the Model-View-Controller architecture in Chapter 2, API Design, the Model layer is the part that's intimately related with the data and storing and retrieving it.
The Model abstracts all the data handling. This not only includes database access but also the related business logic. This creates a two-layer structure:
- The internal data modeling layer, handling the storage and retrieval of data from the database. This layer needs to understand the way the data is stored in the database and handles it accordingly.
- The next layer creates business logic and uses the internal data modeling layer to support it. This layer is in charge of ensuring that the data to be stored is consistent and enforces any relationships or constraints.
It's very common to deal with the data layer as a pure extension of the database design, removing the business level or storing it as code in the Controller part. While this is...