Search code examples
angularfile-structure

file structure of server-side script on server when using frameworks like angular


I use to build my web projects with CodeIgniter before I learned Angular. The MVC structure of CodeIgniter made organizing my php files easy. I no longer had php scripts scattered all over the place. Now that I've learned Angular, it seems that the whole scattered script thing is coming back because angular is front-end stuff and a lot of http requests (to php) files need to be made . I now usually have files like these

login.php in api/accounts and get-likes.php in api/post-actions

They are just single files that do one thing. The structure that MVC frameworks provide is more scalable, almost everything runs through classes, there is one entry point and controllers a automatcially called from urls. Is this wrong. Is there anything I can do better? (Note not on angular's end now but on organizing my script on server).

I know my question is somewhat disorganized and unclear I can feel it myself but I don't know how else to ask. If any edit needs to be made, I'll gladly make them.


Solution

  • You don't need to go back to the old php ways. Your controllers can just be REST controllers, which return data in JSON format.

    For instance, you can have a Authentication controller, which handles all requests regarding authentication.

    /api/authentication/login (POST)
    /api/authentication/logout (GET)
    

    In that, you can use any framework in your back end (Symfony, Laravel, Codeigniter) which help you keep your code organised