The model layer Vs database structure
There have been a few discussions recently about the model and the database structure, and which one to start with. I thought I would throw my thoughts out and see what people think. To me the database structure is, as the name suggests, just about the database. When developing a system you should start with the model, rather than the database structure. Now to me, the model is where your back end business logic resides. Lets take a MVC application example.
Imaging that you have a user logging into your system. You have a request
(form post) which is handled by your controller.
The controller then makes a request to your model layer. Your
model layer does the back-end logic some of which may be
making calling to you database structure.
Taking a close look at the model layer.
Lets say you have a service layer.
To pre validate the password your service layer makes a call to a utils.cfc
to check that the password submitted contains a number. If it does it then
the service calls your DAO which
makes a call to your database and returns your query result. This result is
then passed back to your service layer which then carrys out futher logic
i.e. return an inValid login message, log a successful login, makes a call
to a user object etc.
The point being that it's in your model layer* where your business logic goes, and it's why this is more important to start with this rather than your database structure.
Here is a diagram which I hope helps:
What is your take on it?
* Be it the 'M' in MVC or the service layer object.





When the system is View - Controller - Model - Database, the customer will only ever see the View and ultimately the results of the product are in the Database, so the rest is just logistics.
I tend to think more in controller, markup, processing, model and presentation layers. I don't feel the need to redefine things in an MVC package. I feel the need to have a functional system that can encapsulate, refactor and perform seperation of layered function.
With that said, the data is a seperate layer that is commonly handled in what is packaged inside a model. It is a data model function. If that helps you or another provide the data layer in a clean encapsulated layer to interface with the actual data store then that is good. If the need to follow some philosophy of what a model is abstracts reason rather than code then it is a bad thing. Bottom line is clean abstraction, encapsulation and layering through consistent interface and modulatirty are the goal. Wearing the uniform won't make us good soldiers or prove we are loyal in the long range. :)
Often the client has no clue what they want, and you have to design the database just to get a feel for what the model and view will actually be like.
I would also say that the VIEW would come before the model, as you surely want to create a wireframe for the client to approve before creating the model.