Should API, Webpage and Admin panel be separate apps?

What is the proper way to handle App splitting into:

  • API
  • Webpage
  • Admin panel

Should i keep Controllers, Middlewares, dependencies, settings and etc. specific for each part in apps catalog like:

  • apps/api/Controllers/AuthenticateController.php
  • apps/api/Controllers/TicketsController.php
  • apps/api/routes.php
  • apps/api/dependencies.php
    etc. and same for /webpage and /admin with addition of twig templates

Then define 3 entry points in public/

  • public/index.php
  • public/api.php
  • public/admin.php

And rest of common classes in:

  • src/Models
  • src/Mappers

Or should it be kept all together in one namespace and one catalog like in slim3-skeleton, and just split specific controllers in namespaces like that:

  • src/Controllers/ControllerAbstract.php
  • src/Controllers/Api/AuthenticateController.php
  • src/Controllers/Webpage/HomeController.php

And keep one dependencies and settings file wich one entry point in public/index.php with routing handled by routing groups?

Personally I think the first option is cleaner and more intuitive. When you’re working on the code you’re going to working on one of those areas at a time (probably), and having all the resources together makes it easier to locate assets and to know which parts go together.


1 Like

Sure thats what i though as well. Thanks for your opinion.

Won’t it be bothersome though to have three settings.php, depencendy.php files which can be actually quite similar? Basic dependencies like Redis, DB etc. will occur in all 3 apps, some will be unique for each of them. Same with settings which on the beggining will be propably the same, but in time they can grow different.

I agree with your first solution also. I’ve set most of my apps up that way. As far as sharing dependencies throughout apps, I lean pretty heavy on containers. I usually create a global container file and include that file for each app and then just inject the dependencies needed.

As far as routing goes, I’ve created my own router to handle the initial request and use slim routing after that. Groups are good for small clusters but can get a bit unwieldy with time.

1 Like

Sorry for long delay in replying, so i have implemented first solution after seeing yours and Nycrans answer.

Right now i have separate index.php file in public for api, webpage and admin panel. Each includes its own settings.php, middleware.php, routes.php and dependencies.php.

Each dependencies.php, settings.php and middleware.php requires global dependencies.php, settings.php and middleware.php sitting in app directory, those global files contain settings, dependencies and middlewares common for all my apps. Then each app files add its own required dependencies, settings and middlewares specific for sub-app.

Each index.php also have new instance of App which i run. So far it works fine since i can freely manage each sub-app, while maintaining same global dependencies like DB and Redis.

App directory also contains Controllers, Middlewares and templates (if needed) specific for each app. Rest of application logic sits in src/ directory (Models, Mappers, Utilities, etc.).

Would be glad to hear if you find this a proper solution.