Where Do You Put Your Components?

The Macromedia Web Technology Group, in their most recent ColdFusion MX Coding Guidelines, recommends that you put components which are to be accessed directly either through Flash Remoting or web services in {cfmxroot}/wwwroot/{applicationname}/ and any other components should be stored under {cfmxroot}/extensions/components/{applicationname}/. I sometimes do something similar, although I generally use {cfmxroot}/com/macromedia/apps/{applicationname}/ instead. This works well for applications that you write, install and configure yourself, however I found that when I wanted to distribute an application, I preferred having all the application’s files in a single directory. Therefore, I have started putting all application-specific components — whether or not they are accessed directly through the browser, Flash Remoting or web services — in {cfmxroot}/wwwroot/{applicationname}/components/{subdirectory}. At first, this may not appear to be the most elegant relationship, however I like the idea of having people unzip a single directory in their web root, set up a data source, tweak a few configuration parameters in the Application.cfm file or an external XML file, and be up and running. Now there’s really no reason you can’t do the same thing with your components outside your application directory, however I have found both packaging and unpacking to be more straightforward when everything is contained in a single directory.

So my current thinking is that I try to consider the type of application that I am writing and what it is intended for before deciding where to place my components. Where do you put yours?

Also, one circumstance that the WTG coding guidelines does not address is the location of generic, reusable components. For instance, I have a calc.cfc which performs certain mathematical functions in {cfmxroot}/wwwroot/com/macromedia/util, which has worked out well.

24 Responses to Where Do You Put Your Components?

  1. Geoff Bowers says:

    When we built FarCry CMS we wanted a component library that wasn’t exposed under the webroot. We map that library with an application variable so it can really sit anywhere. But we chose to stick CFC packages into a directory called ../applicationroot/packages/*.*.Were we wrong? Should we have used ../applicationroot/au/com/daemon/farcry/*.*? Generally I don’t think so because the FarCry framework reserves the packages location for FarCry CFCs — there is no fear of competing in the namespace.Incidentally for standard components, for instance the ones I borrowed from Pollster we do the same as you’ve indicated.PS. FarCry v2 just released (http://farcry.daemon.com.au/) — largest CF open source code base in the world 🙂

  2. mark says:

    Personally – I normally build a ‘web-inf’ folder under the root of my application.In there I have stored my XML config files (web.xml etc), and then haveweb-inf/componentsweb-inf/udfsweb-inf/customtagsUsually each of those 3 directories is given a mapping, which is specified in my XML configs.Personally, I feel that components should be application specific. If you have a component that you use on multiple applications, pick it up and move it.If that said component is changed, I would prefer to test it individually on each application before moving it straight to production anyway.But – toss up either way, and also dependent on if you are on a hosted / dedicated server, and what control you have.JMHO.

  3. Andy says:

    Currently, I keep all my components outside the webroot. This works well for me because I have no need to package and deploy, other than moving from the devlopment to production environment.If the circumstances were different, I may place my components under the webroot to ease the package and deploy process.

  4. Matt says:

    I prefer the route of keeping components with the application, be that in either the application folder structure (i.e in Jrun4, {jrun_root}/servers/{server}/cfusion-ear/cfusion-war/WEB-INF).or in the web root ( {web_root}/{application}/cfc/…)trying to follow along with the Java application architecture, you’d want to keep things together to avoid confusion and the need for multiple mappings.JMHO

  5. Martha says:

    Thank you for the wonderful website and information I will be back soon, nice Site

  6. Abel says:

    Congratulations to your fantastic Site. Thanks

  7. Best firm Micromedia this in POLSCE which possesses flasha !I greet !

  8. To admit fly that it is this very interesting thing !I greet polaków in name of everybody!

  9. Sie pleases me very this, damage from so it writes thinly English ; in English because for sure my express former to longer !

  10. Locual says:

    Congratulations to your fantastic Site. Thanks

  11. What ?Currently, I keep all my components outside the webroot. This works well for me because I have no need to package and deploy, other than moving from the devlopment to production environment.If the circumstances were different, I may place my components under the webroot to ease the package and deploy process.Is thys ?

  12. DIVX says:

    Pozdro pezet !

  13. Rubén says:

    Congratulations to your fantastic Site. Thanks

  14. Peter says:

    Outstanding web.!

  15. Congratulations to your fantastic Site. Thanks

  16. NStarer says:

    I’ve never though about that before!

  17. propecia says:

    Wow, very sweet nlog

  18. propecia says:

    Wow, very sweet nlog