In distributed apps such as the client-server pattern, you often want to work with the same model classes on both ends. Why? Because client input needs to be validated at the client side and for this, we need the model in the client app. Data has to pass through the model before being stored so that if we want to store the data in a client database (indexed_db
) as well as in a server data store, we need the model on both the sides.
You can see how common classes are created for client and server apps in the client_server_db
app. This is a to-do application; the client is started from web/app.html
and the server is started from bin/server.dart
. The client stores the to-do data in indexed_db
, while the server stores the data in memory. Both client and server need the model classes.
The project structure is shown in the following screenshot: