FrontEnd si BackEnd - as different apps



  • Is there a way to have the fronent and the backeend as different apps? How do I include my models in my front end app?


  • Global Moderator

    @TheLionKing

    Hey, sure you can do that.
    You would have to setup API routes and controllers in your backend then communicate with your frontend trough that way.

    It all depends on what's your vision.



  • so in my project I would have: two folders

    cms - asgardcms project
    www - a different laravel project.

    How do I import the models and repositories in my www project?


  • Global Moderator

    @TheLionKing

    I would not import anything, i would setup 2 domains or 1 domain and 1 subdomain and then do requests from www to cms API routes for data.

    It all depends again on whats in www project and why you need seperation and what exactly do you want to achieve?
    Why you can't do it in 1 project etc.



  • Ussualy CMS and WEBSITE ar different project. They might be installed on different servers having a common database. The cms might be scaled on some servers with write permission (to MySQL and file repository) . Also authentification might be different on website than the cms.

    How would you make this requests "o requests from www to cms API routes for data."?


  • admin

    Look up JWT authentication for you api. And just generally how to build APIs.



  • @nWidart I know JWT auth, I used it for rest api.

    So your advice is that my php app should connect to database throught REST API over HTTP?


  • admin

    No. As @armababy suggested, the asgard app is the api. So you other app calls the API. This is how apis work. :P


  • Global Moderator

    Basically you have 1 core CMS application located anywhere accessible trough network that your WWW app can see.
    This way you have separation and you can scale any of the sides, also you potentially could have multiple WWW applications using same CMS api.

    In your case on both sides you configure applications to use same database. All you have to do now is to develop your API be it soap or rest.
    Asgard already have some groundwork laid down to structure for API controllers.

    Requesting from WWW using something like Guzzle or straight up CURL or any other REST client(lets assume you go with rest api) while authenticating using JW Auth would work very nicely.



  • I know how a HTTP API works. I do no see why a php APP should conect to mysql through HTTP calls. Why can't we use PHP models that already the framework has?


  • admin

    You don't seem to know since you're asking this.

    Apis: You have ONE api app that connects to the DB. Other apps call that ONE api app. that's it.

    Please read up on how APIs work, thank you.



  • @nWidart I have no idea what are you talking about. So you are not talking about api over HTTP ? Because I saw writing about JWT auth. Those tokens are not for wiring over http? Sorry for miss interpreting your message


  • admin

    I am talking about calls over http yes.



  • @nWidart OK. So why do say I do not know how HTTP API works? For me it looks to be a little overhead as you you have two php apps that can read MySQL directly


  • admin

    That's how apis work.

    If you duplicate the models of app1 in app2, you will be able to access the same data, yes. But you have a ton of duplicate business logic moving around.

    That is why the API approach is much better in the long run. If you don't want or need the jwt overhead that's a very valid point too. You can just have an api that doesn't require authentication, and secure the server for outside connections instead.



  • @nWidart So know I know for sure that the CMS wasn't build in the way I was asking. You are right about the code duplicationm, usually read models should be different than write models (like a CQRS flavor).

    Tx for all the patiance


  • Global Moderator

    @TheLionKing you shouldn't really have two separate apps that use code (i.e. Models) from one of the two apps, this is why @nWidart is suggesting you use an API, so that one of your app is the central source of all of your data, and the other app simply consumes it.


Log in to reply