Best practices for structuring files


#1

Hi! I am a beginner to meteor, but I’ve enjoyed rails for two years. I think I’m going to stick with meteor :grinning:

Is there a comprehensive guide on setting up file structure? The guide I am reading (http://meteortips.com/first-meteor-tutorial/) is super laissez faire on the issue, and I don’t want to adopt wrong conventions.

Thanks for the help!


Dir structure (specifically schemas, collections, helpers)
#2

Hi @jackr ,

The cool thing about Meteor is that it really allows you to structure your app which ever way works for you.
Throughout the past year I have seen people use old MVC structure, and I have seen people just load everything in the root directory. Either way Meteor really let’s you have freedom in the structure.

Meteor Tips Your First Meteor App is a great book. I have read that book as well as the Discover Meteor book, and for a first timer the Meteor Tips book is best to get a grasp on Meteor as a whole.

There are however a few folder’s that are special to Meteor.
Meteor’s Docs provide a great example on the special folders here http://docs.meteor.com/#/full/structuringyourapp .

Basically the folder structure that is unique to Meteor goes like this :
Client - Code that is loaded on the client only , such as templates, js files, stylesheets , etc.
Server - Code that is loaded on the server only such as publications
Public - Code that is loaded on the client but can be accessed in the url. Such as favicons , images for your app, etc.
Lib - Code for the client that is loaded first.

Meteor also has helpers that allow you to explicitly run the code on the client or the server.

 and
 if(Meteor.isServer){}`

There are a lot of great links and ideologies out there that talk about structuring of your app. In fact I am currently writing a [book](https://leanpub.com/meteorforyoungdevelopers) that will have a chapter in great detail about app structure, and building plugins to modularize your app. 

Once you start getting used to Meteor you will probably start developing packages. and Manuel has a great article on structuring your app utilizing packages.
 http://www.manuel-schoebel.com/blog/meteorjs-package-only-app-structure-with-mediator-pattern

Since I contribute to a few open source projects and build packages myself a lot of times I will adapt a similar structure as Manuel described in his article.

Let me know if you have any other questions. Meteor is a great community and there are a lot of people that would love to help and answer any questions you may have.

#3

Thank you for the advice. This was really informative.

I am going to attempt both MVC and the way you suggest, I’ll use whichever I enjoy more. I am going to read the Discover Meteor book this weekend, I hope your book is released soon.

Again, thanks for the help!


#4

Thank you , I am pushing to have a sample of the book released by the end of the summer. You can join the mailing list by following the link I pasted above.

Good luck I am here if you ever need help.

Ryan


#5

Have a look at this and specifically this presentation. That is the method I am using for development. Gives you much more control over file load and global namespace sanity :slight_smile:


#6

@jackr have a look at this thread. Something worth keeping note of at the back of your mind with regards to keeping in touch with advancements and prepping for 1.2 as @Sanjo advised.