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

Multi models structure

Hi community,

I'm thinking about project file structure with multi modules and division to frontend and backend. The idea is very easy: before you create some project you can choose what caind of modules do you want to use (some checkbox list)

What do you think what's better:

variant1:

 ├── apps
 │   ├── backend
 │   │   ├── config
 │   │   ├── controllers
 │   │   ├── Module.php
 │   │   └── views
 │   └── frontend
 │       ├── config
 │       ├── controllers
 │       ├── forms
 │       ├── models
 │       ├── Module.php
 │       └── views
 ├── config
 ├── libs
 ├── public_html
 └── var
     ├── cache
     ├── languages
     └── log

disadvantages:

  • the same code for models, which are used also in frontend and backend application. (Models of each module should be shareable)

OR:

variant2:

 ├── apps
 │   ├── general
 │   │   ├── backend
 │   │   │   ├── config
 │   │   │   ├── controllers
 │   │   │   ├── Module.php
 │   │   │   └── views
 │   │   ├── frontend
 │   │   │   ├── config
 │   │   │   ├── controllers
 │   │   │   ├── forms
 │   │   │   ├── models
 │   │   │   ├── Module.php
 │   │   │   └── views
 │   │   └── models
 │   └── user
 │       ├── backend
 │       │   ├── config
 │       │   ├── controllers
 │       │   ├── Module.php
 │       │   └── views
 │       ├── frontend
 │       │   ├── config
 │       │   ├── controllers
 │       │   ├── forms
 │       │   ├── Module.php
 │       │   └── views
 │       └── models
 ├── config
 ├── libs
 ├── public_html
 └── var
     ├── cache
     ├── languages
     └── log

It will be awesome to create one phalcon modules structure with division each module to frontend and backend parts.



11.9k
edited Aug '14

Well, I manage to run phalcon multi module module approach. I generate some preroute thing. And generate module structure for each sub dir.

so ?

when user request /blah

my preroute thing was configure $id variables to to blah dir as single phalcon multi module setup.



12.8k

I don't know what youe mean, any example?



12.8k
edited Aug '14

I think that this structure will be good and it using DDD

 ├── apps
 │   ├── general
 │   │   ├── backend
 │   │   │   ├── controllers
 │   │   │   └── views
 │   │   ├── config
 │   │   ├── entity
 │   │   ├── frontend
 │   │   │   ├── controllers
 │   │   │   └── views
 │   │   ├── Module.php
 │   │   ├── repository
 │   │   └── service
 │   └── user
 │       ├── backend
 │       │   ├── controllers
 │       │   └── views
 │       ├── config
 │       ├── entity
 │       ├── frontend
 │       │   ├── controllers
 │       │   └── views
 │       ├── Module.php
 │       ├── repository
 │       └── service
 ├── config
 ├── libs
 ├── public_html
 └── var
 │   ├── cache
 │   ├── languages
 │   └── log


26.3k
edited Sep '14

@Michal-St

Hi! I am thinking about my project structure too, but I am kind of begginer. I have seen that you structure is "domain driven". I have reading some materials recently about DDD but have problems how should it be implemented in Phalcon. I have also looked at MVC repo in Phalcon (there is a repo "service layer") but is very simple and there is any practical examples. I would like to ask you, mayby:

a) Do you know any interesing articles about DDD? I am especially interested to see how real code looks like, not theory. b) Do you know any repos about DDD implemented in Phalcon, that I can look into? I have look at your repos on GitHub but unfortunetly they are not about DDD.

TIA!



8.1k

Phalcon has no limitations when you use PSR-0. For example :

.
├── Forum
│   ├── Apps
│   │   ├── Backend
│   │   │   ├── Controllers
│   │   │   └── Views
│   │   │       └── Index
│   │   ├── Config
│   │   ├── Forms
│   │   ├── Frontend
│   │   │   ├── Controllers
│   │   │   └── Views
│   │   │       ├── Category
│   │   │       ├── Discussion
│   │   │       ├── Index
│   │   │       └── partials
│   │   ├── Library
│   │   ├── Models
│   │   ├── Schema
│   │   └── Var
│   │       ├── Compiledviews
│   │       └── Log
│   ├── cache
│   ├── migrations
│   │   ├── 1.0.0
│   │   └── 1.0.1
│   ├── public
│   │   ├── assets
│   │   │   ├── css
│   │   │   ├── img
│   │   │   ├── js
│   │   │   └── _static
│   │   └── cache
│   │       └── assets [error opening dir]
│   ├── schema
│   └── sql
└── vendor
    ├── composer
    └── phalcon
        └── devtools

Сlasses are registered easy :

$loader = new \Phalcon\Loader();

$loader->registerNamespaces([
    'Forum' => \dirname(__DIR__) . DS,
]);

$loader->registerDirs([
    \dirname(__DIR__) . '/Apps/Config/'
]);

$loader->register();

That's all of need. :) This implies that you can use any directory structure that you like. Synfony2 style included. For example, I have other structure of models on other project with noSQL DB :

...
├── Models
│   ├── Post
│   │   ├── Entities
│   │   └── Supplier
│   ├── Replay
│   │   ├── Entities
│   │   └── Supplier
│   ├── Tags
│   │   ├── Entities
│   │   └── Supplier
│   └── User
│       ├── Entities
│       └── Supplier
├── Schema
├── Segments
...

Just stick to the PSR-0 hierarchy.



12.8k
edited Sep '14

@Conradaek

For my project one of the most important thing is shareable models between each apps. This is my file structure:

├── apps

│ ├── admin

│ │ ├── config

│ │ ├── controllers

│ │ ├── forms

│ │ └── views

│ ├── cli

│ └── frontend

│ ├── config

│ ├── controllers

│ ├── forms

│ └── views

├── config

├── domain

│ ├── entities

│ ├── repositories

│ ├── services

│ └── values

├── libs

│ ├── Less

│ ├── Phalcon

│ └── Swift

├── public

└── var

| ├── cache

| ├── data

| ├── languages

| ├── log

| └── sessions

Also I implement repositoryManager and ServiceManager with lazy loading. Each of this managers is included in DI. This solution and Phalcon ORM makes my life easier:) In the near future I will also write AutoFormGenerator. After this all CRUD methods for Entity will be easy and fast to use.



12.8k

Where is in this editor tag for code styling?



26.3k
edited Sep '14

https://forum.phalcon.io/help/markdown and go to "Code Blocks" part.

I am trying to learn how DDD should be implemented in practice. Could you please provide some sample of your repository, service and value classes? This would be awesome, very valuable for me.