<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>brucetimberlake.com &#187; subversion</title>
	<atom:link href="http://brucetimberlake.com/blog/tag/subversion/feed/" rel="self" type="application/rss+xml" />
	<link>http://brucetimberlake.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 30 Jul 2010 16:07:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Subversion repository structure for web applications</title>
		<link>http://brucetimberlake.com/blog/2009/01/28/subversion-repository-structure-for-web-applications/</link>
		<comments>http://brucetimberlake.com/blog/2009/01/28/subversion-repository-structure-for-web-applications/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 20:27:39 +0000</pubDate>
		<dc:creator>Bruce</dc:creator>
				<category><![CDATA[Web app development]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://brucetimberlake.com/blog/?p=4</guid>
		<description><![CDATA[If you are coding a lot of web applications, it helps to have a standard directory structure that you start with. That you always know where files should go, etc. This page contains my (current) take on the topic. These steps assume you already have Subversion set up and working. If it&#8217;s on a remote machine, use [...]]]></description>
			<content:encoded><![CDATA[<p>If you are coding a lot of web applications, it helps to have a standard directory structure that you start with. That you always know where files should go, etc. This page contains my (current) take on the topic.</p>
<p>These steps assume you already have <a href="http://subversion.tigris.org/">Subversion</a> set up and working. If it&#8217;s on a remote machine, use the appropriate protocol designator (<code>http://</code>, <code>svn://</code>, etc.) below where you see <code>file://</code>.</p>
<p>Alternatively, you could just put the directory creation commands into a script and run that script every time you needed to set up a new project. But we should all be using some sort of <a href="http://en.wikipedia.org/wiki/Version_control">version control</a> system, now shouldn&#8217;t we?</p>
<p>Just copy and paste the commands into a terminal session on your workstation or server, and that should be all you need to do to set this up. You will need to make some changes for your actual repository path and project names, of course. I&#8217;m just putting sample stuff in my examples.</p>
<p>Set up your desired directory &#8220;skeleton&#8221; in a temporary directory. Note that this uses a &#8220;shortcut&#8221; feature of &lt;code&gt;mkdir&lt;/code&gt; that allows you to specify multiple subdirectories at once. The format is important &#8211; no spaces after the , etc.</p>
<pre>cd ~
mkdir -p skeleton/{branches,tags,trunk/{data,db,doc,util,www/{include/{css,js},media/img}}}</pre>
<p>You now have a directory system that looks like this:</p>
<pre>/home/user
          /skeleton
                   /data
                   /db
                   /doc
                   /util
                   /www
                       /include
                               /css
                               /js
                       /media
                             /img</pre>
<p>This will yield a website structure like this:</p>
<pre>[web_root]
          /include
                  /css
                  /js
          /media
                /img</pre>
<p>Of course you can add other directories as needed to further organize the website, but this will give you a good beginning, and help keep things organized. You will always know the path to CSS and Javascript files, regardless of where on the site you reference them in your HTML.</p>
<ul>
<li><code>/data</code> is where any &#8220;test&#8221; data goes that you need to prepopulate the project. This may not be relevant for the app you are building, so you could leave this one out.</li>
<li><code>/db</code> contains SQL scripts used to create and populate any needed databases and tables. Be sure to add migration or update/upgrade scripts if the schemas change at some point during the project&#8217;s lifecycle.</li>
<li><code>/doc</code> is for any and all project documentation. Be sure to paste important emails into text files and stash them in here!</li>
<li><code>/util</code> is where any supporting scripts (Perl, shell, etc.) would go.</li>
<li><code>/www</code> is the root dir for the website content.</li>
<li><code>/www/include</code> is where any included files would go (think PHP&#8217;s <a href="http://www.php.net/require/"><code>require</code></a> and <a href="http://www.php.net/include/"><code>include</code></a> commands).</li>
<li><code>/www/include/css</code> is where all your CSS files go. You are using CSS, right?</li>
<li><code>/www/include/js</code> is where all Javascript goes. Javascript should be included in your HTML and PHP files via the <code>&lt;script src="..."&gt;</code>, not inline.</li>
<li><code>/www/media</code> should be pretty obvious. I like to use subdirectories for each media type to help keep things organized. Almost every project uses at least one image someplace, so I default to creating the <code>/www/media/img</code> directory in the skeleton. Later, if I need video, audio, flash, etc., I would make new subdirectories for them as well.</li>
</ul>
<p>Once the directories are set up, I put some &#8220;marker&#8221; files in certain directories as well, which get filled in for the specific project once I start working on it:</p>
<pre>cd ~/skeleton/trunk
touch FAQ HISTORY LICENSE README RELEASE-NOTES UPGRADE
touch doc/ABOUT</pre>
<p>I also put empty <code>index.html</code> files into the various web directories, to prevent direct access to them when the project is deployed on a live server:</p>
<pre>touch www/include/index.html
touch www/include/css/index.html
touch www/include/js/index.html
touch www/media/index.html
touch www/media/img/index.html</pre>
<p>Set up a default CSS file (customize per your own experiences, needs, etc.) and stick it in the <tt>/include/css</tt> directory. See <a href="http://www.pingmag.jp/2006/05/18/5-steps-to-css-heaven/">Five Steps to CSS Heaven</a> for more ideas.</p>
<pre>cd include/css
touch style.css

echo "/* Design and Code (c) Company Name, Inc. */" &gt;&gt; style.css
echo "html, body { padding: 0; margin: 0; }" &gt;&gt; style.css
echo &gt;&gt; style.css
echo "body {" &gt;&gt; style.css
echo "	font: normal 12px/1.5em sans-serif;" &gt;&gt; style.css
echo "	background: #fff; }" &gt;&gt; style.css
echo &gt;&gt; style.css
echo "/* Headings H1-H6 */" &gt;&gt; style.css
echo "h1 { }" &gt;&gt; style.css
echo &gt;&gt; style.css
echo "h2 { }" &gt;&gt; style.css
echo &gt;&gt; style.css
echo "h3 { }" &gt;&gt; style.css
echo &gt;&gt; style.css
echo "h4 { }" &gt;&gt; style.css
echo &gt;&gt; style.css
echo "h5 { }" &gt;&gt; style.css
echo &gt;&gt; style.css
echo "h6 { }" &gt;&gt; style.css
echo &gt;&gt; style.css
echo "/* Paragraph and Link Styles */" &gt;&gt; style.css
echo "p { }" &gt;&gt; style.css

cd ../..</pre>
<p>Note that I use the &#8220;echo >>&#8221; mechanism rather than an actual file so that you can copy/paste all these commands and it will &#8220;just work&#8221; &#8211; no file editor needed at this stage.</p>
<p>Next, create a new project repository:</p>
<pre>svnadmin create --fs-type fsfs /path/to/repos/projectname</pre>
<p>Finally, import the directory structure into the project:</p>
<pre>svn import ~/skeleton file:///path/to/repos/projectname -m "Initial project 'projectname' setup"</pre>
<p>Gives this result:</p>
<pre>Adding /home/user/skeleton/trunk
Adding /home/user/skeleton/trunk/HISTORY
Adding /home/user/skeleton/trunk/LICENSE
Adding /home/user/skeleton/trunk/www
Adding /home/user/skeleton/trunk/www/media
Adding /home/user/skeleton/trunk/www/media/index.html
Adding /home/user/skeleton/trunk/www/media/img
Adding /home/user/skeleton/trunk/www/media/img/index.html
Adding /home/user/skeleton/trunk/www/include
Adding /home/user/skeleton/trunk/www/include/css
Adding /home/user/skeleton/trunk/www/include/css/index.html
Adding /home/user/skeleton/trunk/www/include/css/style.css
Adding /home/user/skeleton/trunk/www/include/index.html
Adding /home/user/skeleton/trunk/www/include/js
Adding /home/user/skeleton/trunk/www/include/js/index.html
Adding /home/user/skeleton/trunk/www/index.html
Adding /home/user/skeleton/trunk/db
Adding /home/user/skeleton/trunk/doc
Adding /home/user/skeleton/trunk/doc/ABOUT
Adding /home/user/skeleton/trunk/RELEASE-NOTES
Adding /home/user/skeleton/trunk/UPGRADE
Adding /home/user/skeleton/trunk/FAQ
Adding /home/user/skeleton/trunk/data
Adding /home/user/skeleton/trunk/README
Adding /home/user/skeleton/trunk/util
Adding /home/user/skeleton/branches
Adding /home/user/skeleton/tags

Committed revision 1.</pre>
<p>Your project is now ready to check back out and start working on:</p>
<pre>cd ~
svn co file:///path/to/repos/projectname/trunk work</pre>
<p>Gives this result:</p>
<pre>A work/HISTORY
A work/LICENSE
A work/www
A work/www/media
A work/www/media/index.html
A work/www/media/img
A work/www/media/img/index.html
A work/www/include
A work/www/include/css
A work/www/include/css/index.html
A work/www/include/css/style.css
A work/www/include/index.html
A work/www/include/js
A work/www/include/js/index.html
A work/www/index.html
A work/db
A work/doc
A work/doc/ABOUT
A work/RELEASE-NOTES
A work/FAQ
A work/UPGRADE
A work/data
A work/README
A work/util
Checked out revision 1.</pre>
<p>A final note &#8212; if you are using Subversion, <strong>DO NOT</strong> mess with the <code>.svn</code> directories anyplace within your project! When you are deploying the project to a web server (testing, production, etc.), you can just exclude them (use the <code>-C</code> switch for <code>rsync</code>, for example).</p>
<p>Keywords for the search engines: subversion repository directory structure template layout example sample recommended web app webapp application</p>
]]></content:encoded>
			<wfw:commentRss>http://brucetimberlake.com/blog/2009/01/28/subversion-repository-structure-for-web-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
