source: Dev/branches/play-2.0.1/documentation/manual/gettingStarted/Anatomy.md @ 322

Last change on this file since 322 was 322, checked in by hendrikvanantwerpen, 13 years ago

Added Play! framework and application with Jena dependency. Working on
the basic things now (login/register), after that start implementing
our data model.

File size: 4.9 KB
Line 
1# Anatomy of a Play 2.0 application
2
3## The standard application layout
4
5The layout of a Play application is standardized to keep things as simple as possible. A standard Play application looks like this:
6
7```
8app                      → Application sources
9 â”” assets                → Compiled asset sources
10    └ stylesheets        → Typically LESS CSS sources
11    └ javascripts        → Typically CoffeeScript sources
12 â”” controllers           â†’ Application controllers
13 â”” models                → Application business layer
14 â”” views                 â†’ Templates
15conf                     â†’ Configurations files and other non-compiled resources (on classpath)
16 â”” application.conf      → Main configuration file
17 â”” routes                → Routes definition
18public                   â†’ Public assets
19 â”” stylesheets           â†’ CSS files
20 â”” javascripts           â†’ Javascript files
21 â”” images                → Image files
22project                  → sbt configuration files
23 â”” build.properties      → Marker for sbt project
24 â”” Build.scala           â†’ Application build script
25 â”” plugins.sbt           â†’ sbt plugins
26lib                      → Unmanaged libraries dependencies
27logs                     â†’ Standard logs folder
28 â”” application.log       â†’ Default log file
29target                   â†’ Generated stuff
30 â”” scala-2.9.1             
31    └ cache             
32    └ classes            → Compiled class files
33    └ classes_managed    → Managed class files (templates, ...)
34    └ resource_managed   â†’ Managed resources (less, ...)
35    └ src_managed        → Generated sources (templates, ...)
36test                     â†’ source folder for unit or functional tests
37```
38
39## The app/ directory
40
41The `app` directory contains all executable artifacts: Java and Scala source code, templates and compiled assets’ sources.
42
43There are three standard packages in the `app` directory, one for each component of the MVC architectural pattern:
44
45- `app/controllers`
46- `app/models`
47- `app/views`
48
49You can of course add your own packages, for example an `app/utils` package.
50
51> Note that in Play 2.0, the controllers, models and views package name conventions are now just that and can be changed if needed (such as prefixing everything with `com.yourcompany`).
52
53There is also an optional directory called `app/assets` for compiled assets such as [[LESS sources | http://lesscss.org/]] and [[CoffeeScript sources | http://jashkenas.github.com/coffee-script/]].
54
55## The public/ directory
56
57Resources stored in the `public` directory are static assets that are served directly by the Web server.
58
59This directory is split into three standard sub-directories for images, CSS stylesheets and JavaScript files. You should organize your static assets like this to keep all Play applications consistent.
60
61> In a newly-created application, the `/public` directory is mapped to the `/assets` URL path, but you can easily change that, or even use several directories for your static assets.
62
63## The conf/ directory
64
65The `conf` directory contains the application’s configuration files. There are two main configuration files:
66
67- `application.conf`, the main configuration file for the application, which contains standard configuration parameters
68- `routes`, the routes definition file.
69
70If you need to add configuration options that are specific to your application, it’s a good idea to add more options to the `application.conf` file.
71
72If a library needs a specific configuration file, try to file it under the `conf` directory.
73
74## The lib/ directory
75
76The `lib` directory is optional and contains unmanaged library dependencies, ie. all JAR files you want to manually manage outside the build system. Just drop any JAR files here and they will be added to your application classpath.
77
78## The project/ directory
79
80The `project` directory contains the sbt build definitions:
81
82- `plugins.sbt` defines sbt plugins used by this project
83- `Build.scala` defines your application build script.
84
85## The target/ directory
86
87The `target` directory contains everything generated by the build system. It can be useful to know what is generated here.
88
89- `classes/` contains all compiled classes (from both Java and Scala sources).
90- `classes_managed/` contains only the classes that are managed by the framework (such as the classes generated by the router or the template system). It can be useful to add this class folder as an external class folder in your IDE project.
91- `resource_managed/` contains generated resources, typically compiled assets such as LESS CSS and CoffeeScript compilation results.
92- `src_managed/` contains generated sources, such as the Scala sources generated by the template system.
93
94## Typical .gitignore file
95
96Generated folders should be ignored by your version control system. Here is the typical `.gitignore` file for a Play application:
97
98```txt
99logs
100project/project
101project/target
102target
103tmp
104```
105
106> **Next:** [[Using the Play 2.0 console | PlayConsole ]]
Note: See TracBrowser for help on using the repository browser.