Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Recommended application structure

Hi there,

first: awesome work done! I played around a while with the framework and now planning to replace 2 ruby on rails applications with versions based on phalcon.

As I searched around I found several ways to structure my application. Well, this is one point I like on phalcon, I can choose my own application structure.

Then I found several example project setups at https://github.com/phalcon/mvc . Now I'm a bit confused.

Is there any recommended structure I really should use or is it possible to use my own structure as well? For example, I don't like the config folder inside of "app". I also know there is version 2 in progress, which will change some things. Will this also change the application structure or is it planned to publish an "the-one-and-only-application-structure"?

If you plan to force us to use a specific layout, I rather will use this layout from the beginning. Otherwise I really would like my own structure inspired by some of the examples mentioned above.

Thanks a lot!

Martin

public/
- js/
- css/
- img/
- index.php
app/
- controllers/
- models/
- views/
tests/

That's how a simple structue should look like. You also can add a backend folders like plugins and library into app folder.

Hi,

thanks! Is it a convention to put the library folder into the app directory? Otherwise I would place it into the top level of the application. What about other folders like config, logs, etc. pp.? Is there any convention for this?

In other words: do I get a problem if my application contains for example the config folder in application root and not inside of app in further versions or will this be ok?

You divide all application by structural things:

  1. App - all backend off application, here all folders config, logs, library and MVC folders
  2. Public - all thing that available to public use (e.g. JS scripts, CSS and so on)
  3. Tests - folder for testing (if necessary)

On top level is good practice to have a vendor folder, that contains a vendor libraries that could be used in app and in tests. You are free to modify a application boilerplate, just try to divide public and not public parts of application. All other things is less matter.

Thanks again for your answer. I really don't want to start a discussion about where to place the folders, but I think I am misunderstanding some things. For your information, I come from frameworks like Rails or Smyfony, where the directory structure really matters. As far as I understand, Phalcon is there "free", which means I possible could place the folders where I like.

For example: I don't like the config folder in the app directory. In my opinion, the config folder contains mostly configuration about the framework and not the application itself. Therefore I would place it in top level.

Another thing is, that we want to use environments (dev, staging, production) for our applications. Where would you place these things?

Other questions: say, I am naming the app folder application. Does this break the application? As I have to register the directories myself, I could also name it "application".

Sorry for my stupid questions ;)



1.7k
Accepted
answer

No renaming folders into some other will not break your application. Here all are belongs and lay on yourself.

In phalcon config for a framework will be your bootstrap file, where you register your services. If it short in can be just in public/index.php in some of my projects i have a app/config with three files: service.php, config.php and loader.php. They contains information about DI services, configuration of application and loader of whole project.

Feel free to make structure simple to yourself. You always can move, if you make a mistake :)

> Feel free to make structure simple to yourself. You always can move, if you make a mistake :)

Great! Made me laughing ;)

Well, thanks a lot for your patience and answers. I should do some work and stop philosophisng about directories ;)



47.6k
edited Jan '15

Here are some official patterns to check out: https://github.com/phalcon/mvc

Also check out my Webird framework. Its likely far more complicated than what you need but you can see what the potential is for you to grow into. Modules might be too much to start with but you will probably end up using them someday. Something to think about is what to put in the modules and what to put in common code. You might want to consider looking at Vokuro as well, which is what I ended up basing my project on. I didn't like it at all when I first looked at it but then after trying to start many things myself I realized that there was really a hell of a lot there.