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.