meteor project structure how to prevent spaghetti code and chaos peter ilfrich – software engineer...
TRANSCRIPT
Meteor Project Structure
How to prevent spaghetti code and chaos
Peter Ilfrich – Software Engineer @ IBM Research Australia
WARNING!!!
This presentation may contain a personal opinion
Boilerplate / Template
git clone https://github.com/ilfrich/meteor-project-template.git
- Folder Structure - Fixtures- Useful Packages - Data Migration- Global Template Helpers- CSS Helpers- Example Code- Router- Collections + Schema- Views
Core Folder Structure
client
server
public
private
tests
compatibility
Shared Folder
client
server
public
private
tests
compatibility
shared model routes
Server Folder
client
server
public
private
tests
compatibility
shared model routes
init methods publications
Client Folder
client
server
public
private
tests
compatibility
shared model routes
init methods publications
init views
Init / Compatibilityclient compatibility init views
Common functionality- Function declaration- 3rd party libraries (excl. NPM, Atmosphere)
Compatibility
Client initialization- Environment- Global Subscriptions
Init
Viewsclient compatibility init views
common.lessvariables.less
globalhelpers.jsglobalevents.js
layout.html
Files
login/login.htmllogin/login.lesslogin/login.js
header/header.htmlheader/header.lessheader/header.js
dashboard/dashboard.htmldashboard/dashboard.lessdashboard/dashboard.js
Folders
Server Folder
dbinit.jsdbmigrate.js
Init
- 1 file per business object (user, category, entry, post, …)- Too many business objects? Group them into sub-folders
Methods
server init methods publications
- 1 file per collection- Each file contains all publications for a collection
Publications
Shared Folder
- 1 file per collection- Attach schema to collection- Specify access privileges and hooks
Model
shared model routes
Routes
Small Applications- 1 file
/server/routes.js
Larger Applications- Group routes into separate files
/server/routes/mainroutes.js/server/routes/adminroutes.js/server/routes/apiroutes.js
Packages
• Core– less – jquery– mizzao:bootstrap-3– iron:router
• Database– aldeed:collections2– matb33:collection-hooks– tmeasday:publish-counts– meteorhacks:aggregate
• Utility– reactive-var– http– momentjs:moment
• Authentication / Security- accounts-password- browser-policy
• Optional- tsega:bootstrap3-datetimepicker- mrt:bootstrap3-typeahead- mrt:filesaver- johdirr:meteor-git-rev- juliancwirko:s-alert- fortawesome:fontawesome- peernohell:c3- matteodem:gridster- dburles:google-maps