I have a website for which I've written an API using mongoose models and nodejs.
Now, I am creating an app which will use the same API. Whether I create it in Xcode (just iOS) and Android Studio (just Android) or use a combined framework (like Flutter), I find myself creating classes that duplicate the Mongoose models. For example, I have a mongoose model for User, and I have now, in a separate location, a class for User.
My concern here is maintainability. If I update the API or make a change to the underlying models, I have to do this in two places. While I don't have a big application, I still feel as though I am doing this wrong.
Advice requested. :)
Okay, y'all. I think I just need to get my head around it. For the website, I have written an API that relies on the mongoose models, so I don't end up recreating them in that instance (for the front end). Unfortunately, I set up the API such that it returns the front end pages. That means that I cannot use it for mobile. I think that I can write a separate API for my mobile apps that lives on the same server and then will not have the redirects (and potentially then go back and have one pretty unified API that knows if it is serving a mobile app or the website).
I can create dart classes for Flutter (or do it uniquely for iOS and Android), so I can also have local cache of data.









"While I don't have a big application, I still feel as though I am doing this wrong." You're not doing it wrong, it's "normal" to have to re-create some sort of model on the client (android, iOS, web frontend).
What could help you is sharing the data class (eg. Using JS for the apps and the backend) although that gets super tricky quite quickly.
Another way is to share some sort of JSON API spec from which your data models are constructed in the apps, again complicated and is probably more effort than its worth.