We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Large project example

Hi all! I searching for large (>1000 files, >50 database tables) project. Currently i do growing application and i have problem with too many controllers / forms / others in one folder. Multimodule application helped but not as good as SF bundles. Module isolation is too strong for me. Can you show / link yours large projects?



3.4k

I have problem with too many controllers / forms / others in one folder.

  • Why is it causing you issues?
  • Is this because of your naming convention or just there's too many files?
  • Are there multiple controllers that can be combined into 1 controller? Have you gone too granular?

Main problem is too many files in one folder and too many children of one parent. I have diffrent functionality in diffrent controllers, but they are still in one folder. The same problem occurs with forms / repositories / models / etc. If i work with one functionality others reducre readability. Usually one controller have 4 - 6 methods and about 200 lines. I trying be compatible with PHPMD but NumberOfChildren Rule kill me.

I guess there is no really possbility to change it, you could try somehow to make more abstract classes, move some same functionallity to some service etc things, i guess ong bigger project there will always be some big amount of files or code.

But is this a performance issue, or a code management one?

If you use opcache then code managment only.

But is this a performance issue, or a code management one?

I have problem with code management and architecture quality. Performance is ok

I guess there is no really possbility to change it, you could try somehow to make more abstract classes, move some same functionallity to some service etc things, i guess ong bigger project there will always be some big amount of files or code.

I have good experience with "modules" from SF1 and "bundles" from SF2/3. They are good way to separate functionality. I searching for some equivalent.

I guess there is no really possbility to change it, you could try somehow to make more abstract classes, move some same functionallity to some service etc things, i guess ong bigger project there will always be some big amount of files or code.

I have good experience with "modules" from SF1 and "bundles" from SF2/3. They are good way to separate functionality. I searching for some equivalent.

In my understanding, the bundles of SF introduce an extra overhead, thus impacting performance. Phalcon is streamlined for performance first, and only then concerns itself with dev-convenience.

As suggested, try refactoring your shared code into abstract classes or services. For example, when using vendor APIs, we use global services for them. Another thing I found useful is to have common DB models and autoload them into every module.

Then modules in phalcon can be exactly like bundles from SF 2/3

Then modules in phalcon can be exactly like bundles from SF 2/3

There are similarities, but as @pwoszczyk stated, SF has more interoperability between bundles, and is also more versatile (public assets, inheritance, parallel bundles). All at the cost of performance ofc.

edited Mar '17

I guess there is no really possbility to change it, you could try somehow to make more abstract classes, move some same functionallity to some service etc things, i guess ong bigger project there will always be some big amount of files or code.

I have good experience with "modules" from SF1 and "bundles" from SF2/3. They are good way to separate functionality. I searching for some equivalent.

In my understanding, the bundles of SF introduce an extra overhead, thus impacting performance. Phalcon is streamlined for performance first, and only then concerns itself with dev-convenience.

As suggested, try refactoring your shared code into abstract classes or services. For example, when using vendor APIs, we use global services for them. Another thing I found useful is to have common DB models and autoload them into every module.

Thanks for good advices. I done many things what you describes. I have common model and common services (and per module). Still i have to many code in one module. I divide functionality into tree modules (api, backend, frontend). I can not make smaller modules for the reasons you specify. In need to share assets, dispath betwen controllers, etc. I dont whant globalize all things.

Maybe exist good example of large project and somebody solve scalability problem in Phalcon.



58.3k

You can take look a project phanbook at https://github.com/phanbook/phanbook

You can take look a project phanbook at https://github.com/phanbook/phanbook

Thank for example!

I found also Yona CMS: https://github.com/oleksandr-torosh/yona-cms

edited Apr '17

In my humble opinion, the default approach for directory structure in Phalcon is not too good for large projects. But it's a good thing, because probably most of the projects are small, and not need overcomplicated folder structure and other rules that apply to big projects.

It happens im creating mostly large systems like consiting 100+ tables in DB, with thousands of uploaded files, tens of admins concurrently working in the system + houndred of other sessions crawling the front-end.

Fortunately Phalcon allows you to create your own place for every model or view, it not need to be all in one folder, and that's what i did.

You just getting dispatcher out of dependency injector and then you have methods to manage those things like setDefaultController, setDefaultAction, setControllerName, setActionName, setParams. The same thing goes with Router and other components - just experiment with that.

I personally created somethig like boilerplate/backend admin panel generator together with components like jquery, bootstrap to accelerate my work, where all folder structure and few other things are different than default Phalcon settings.

This is a quite old thread, but I feel the need to answer. First of all, using groups to define your routes, you can specify a different controller for every group and you can then organize your controllers in different directories (and namespaces). The class to use is: Phalcon\Mvc\Router\Group.

A group is defined like this:

<?php

namespace MyApp\Route;

use Phalcon\Mvc\Router\Group;
use Phalcon\Di;

/**
 * @brief Group of Authentication routes.
 * @nosubgrouping
 */
class AuthGroup extends Group {

  public function initialize() {
    // Sets the default controller for the following routes.
    $this->setPaths(
      [
        'namespace' => 'MatchPint\Controller',
        'controller' => 'auth'
      ]);

    $this->setPrefix('/auth');

    $this->addPost('/signin/', ['action' => 'signIn']);
    $this->addPost('/signup/', ['action' => 'signUp']);
    $this->addGet('/signout/', ['action' => 'signOut']);
  }

}

Group instances can be added using:

$router->mount(new Route\AuthGroup());

This answer your question about organization and solve the issues with too many file per directory.

I suggest, anyway, to refactor your monolithic application in microservices, so you can have a separate project for every domain.