Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework Project recommended structure

Right now we're debating on two ways to structure our project

  1. Decompose the project into modules and each modules contain the models, exception, controller it needs. So a user module might contain the User Model, all possible user exception cases for User, and the REST end point for dealing with User

  2. Follows the traditional approach where we have top level models, services, controllers, exceptions. Then in services there will be sub packages and similarly in Exceptions.

Structure 1:

app/
   /serviceA
       /models
          Foo.scala
       /controllers
       /exceptions
       serviceA.scala
   /serviceB
       /models
          Bar.scala
       /controllers
       /exceptions
       serviceB.scala

Structure 2:

app/
   /controllers
   /models
       Foo.scala
       Bar.scala
   /exceptions
       /serviceA
       /serviceB
   /services
       /serviceA
       /serviceB

Is there a recommended project structure that features Exceptions, Services, Models?

like image 221
James Cowhen Avatar asked Aug 07 '13 21:08

James Cowhen


1 Answers

The recommended "Play" way to structure your code is like this:

app
  └ controllers
  └ models
  └ views
conf
  └ application.conf
  └ routes
modules
  └ admin
    └ conf/admin.routes
    └ app/controllers
    └ app/models
    └ app/views     
project
 └ build.properties
 └ Build.scala
 └ plugins.sbt

See here: http://www.playframework.com/documentation/2.1.1/SBTSubProjects

In the above example, there's only one module called admin, but you could add more in parallel with admin.

Structure your code this way allows you to take advantage of built-in Play subproject features. For example, you could change the program context to admin by simply typing:

project admin

like image 71
Mingyu Avatar answered Nov 11 '22 23:11

Mingyu