Structure of my project:
├── apps
│ ├── backend <= Micro
│ └── frontend <= Application
├── public
│ ├── css
│ ├── index.php <= Single entry point
│ └── js
└── vendor
├── ...
Note: I dont want use two entry point, something like this:
├── apps
│ ├── ...
├── www
│ ├── css
│ ├── index.php <= Entry point for Frontend
│ └── js
├── api
│ ├── index.php <= <= Entry point for Backend
It is still a spare option.
Question:
In both cases, I would like to get an example code for the following files:
public/index.php // or www/index.php & api/public.php
apps/forntend/Module.php // or something similar
apps/backend/Module.php // or something similar
and how I should organize work with routes, dispatcher, etc.
Why combine them? Just use Phalcon\Mvc\Application alone. Micro doesn't even have dispatcher, modules etc. Phalcon\Mvc\Micro is seperated thing and it shouldn't be used in same application where Phalcon\Mvc\Application.
What exactly you want to achieve?
You can employ different solutions for this. Yes you can do @Juri wrote for sure but if you want your API/Backend to be as slim as possible, then you can use the Micro application.
The trick is to have an abstract bootstrap class which performs all of your initializations (including the application object) and override this with the relevant bootstrap classes for frontend, backend, cli etc.
Have a look at the Phalcon website implementation, in particular the Bootstrap class on how you can achieve this.
The implementation is explained in length in these posts:
https://blog.phalconphp.com/post/building-the-new-phalcon-website-implementation-part-1 https://blog.phalconphp.com/post/building-the-new-phalcon-website-bootstrap-part-2 https://blog.phalconphp.com/post/building-the-new-phalcon-website-middleware-part-3