Play Framework Recommended project structure

We are now discussing two ways to structure our project.

  • Expand the project into modules, and each module contains the model, exception, controller that it needs. Thus, a user module can contain a user model, all possible cases of user exclusion for a user, and a REST endpoint for working with User

  • It performs the traditional approach when we have top-level models, services, controllers, exceptions. Then there will be subpackages in services 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 in which there are exceptions, services, models?

+7
playframework
source share
1 answer

The recommended Play method for structuring your code is as follows:

 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 is only one module called admin , but you can add more in parallel with admin .

The structure of your code in this way allows you to use the built-in functions of the Play subproject. For example, you can change the context of the program to admin by simply typing:

project admin

+9
source share

All Articles