How to organize your files on your Meteor projects


#1

I just write a small post on how I organise files on a Meteor project based on my 2 years of programming in Meteor. Hope It’ll help!


#2

Let’s holywar begins
I have tryed all structures that you described. And found that Everything is Package is the best


#3

We are moving more and more code into packages. for smaller projects we find this approach (below) much more effective than what Josh Owens prefers.

[client]
|–[views]
|----[postsList]
|------events.js
|------helpers.js
|------templates.html
|------onRendered.js
|------styles.less
|------routers.js

Sharing helpers and event code in the same files encourages file level scoped variables. we feel splitting them up makes things easier to find and also encourages better discipline. we use template level reactivedicts when events and helpers need them.

Download and explore this repo to see how well-organized and clean the code is.
http://git.libreboard.com/libreboard/libreboard/tree/newui/client/views/cards

also see
http://meteor.redandivory.com/


#4

Hi Max ( @maxhodges ) , thanx for sharing that presentation. Some really good advises!

Cheers,
Tom


#5

I started out with the pure-app approach without any packages but eventually refactored to packages-only where all major concerns of my application are neatly separated and communicate via a clean api. This makes testing (and stubbing) your stuff much easier although it certainly reduces the convenience of Meteor auto-include-and-update-everything-in-the-main-app.

Another pattern that I am beginning to find very useful is splitting up bigger packages into sub-folders that are related to individual features of that package.

So I have an accounts package that included everything related to user accounts like so:

[packages]
|–[accounts]
|----[registration]
|----[login]
|----[password_recovery]
|------[client]
|-------- // templates and views
|------[server]
|-------- // API and controllers
|----[account_screen]

This really simplifies the structure and makes it crystal clear what you can expect when clicking around the folders. It’s also great when explaining to someone how your application works, because it is so straight-forward.