Sinatra + Rack directory/project layout conventions/best practices?

52 views
Skip to first unread message

gsw

unread,
Jun 10, 2009, 12:28:03 PM6/10/09
to sinatrarb
I looked at various projects that use Sinatra + Rack and the directory
layout appears to vary depending on the project that uses them.

Even though it doesn't really matter functionally, do you have any
suggestions for best practices for directory/project layout for
Sinatra + Rack projects?

For example, as a good convention (even though it isn't necessary)
should there be a directory structure under the lib directory that
matches the module hierarchy? Is organization of code into different
files just common sense organization type of stuff, or are there any
generally recommended practices documented somewhere?

It would seem that one of the things that Rails has going for it that
makes it easy for others to look at a Rails project and know what is
going on is convention. Sinatra makes things so simple that at first
convention seems unnecessary, however I'd still like to organize
things in such a way that others agree makes sense and helps them find
what they are looking for easily.

Thanks in advance,
Gary

Tanner Burson

unread,
Jun 10, 2009, 12:42:12 PM6/10/09
to sina...@googlegroups.com
Personally I don't care for a standard convention for Sinatra apps.  This isn't Rails, and we shouldn't try to make it more like Rails.  Sinatra is great because YOU can have whatever convention fits YOUR development style, and I can have mine.  If you write good code, that's at least self-consistent then you're fine.  But that's just my opinion...

--Tanner
--
===Tanner Burson===
tanner...@gmail.com
http://www.tannerburson.com

Bob Aman

unread,
Jun 10, 2009, 1:08:12 PM6/10/09
to sina...@googlegroups.com
> Personally I don't care for a standard convention for Sinatra apps.  This
> isn't Rails, and we shouldn't try to make it more like Rails.  Sinatra is
> great because YOU can have whatever convention fits YOUR development style,
> and I can have mine.  If you write good code, that's at least
> self-consistent then you're fine.  But that's just my opinion...

As a general rule of thumb, I think applications should avoid the use
of both /app and /lib directories (the Rails setup), and should
instead put all application code into well-organized /lib directories.
Always be sure your files require their direct dependencies, rather
than relying on other files doing it for them. Don't require RubyGems
unless you're sure you need to. I personally think that any code that
runs as part of your app should be under /lib, regardless of whether
it actually runs within the sinatra process or not, but a case could
likely be made that related daemons shouldn't live within the same
/lib directory as your sinatra app. Config stuff makes sense being
in a /config directory. Logs should go into /log. PIDs and the like
should NOT go in the /log directory. Logs and only logs should be in
/log. PIDs should probably live somewhere under /tmp. I personally
prefer /tmp/pids, but that's open to taste. I strongly dislike
/lib/tasks and personally prefer /Rakefile + /tasks, but again, open
to taste. I like my templates to live in /templates but here too,
open to taste. Others may prefer /views or similar.

I would probably lightly discourage any attempts to formalize any of
this though, either explicitly or implicitly with the use of skeletons
or generators. I'm of the opinion that people should make their own
skeletons and find something that works for them. Everyone has
different needs for their projects, and widely distributing a
structure leads inevitably to inappropriate usage of that structure.

Bob Aman

Reply all
Reply to author
Forward
0 new messages