title: Structure

In the Quick Start, we should have a preliminary impression on the framework, next let us simply understand the directory convention specification.

  1. egg-project
  2. ├── package.json
  3. ├── app.js (optional)
  4. ├── agent.js (optional)
  5. ├── app
  6. | ├── router.js
  7. ├── controller
  8. | └── home.js
  9. ├── service (optional)
  10. | └── user.js
  11. ├── middleware (optional)
  12. | └── response_time.js
  13. ├── schedule (optional)
  14. | └── my_task.js
  15. ├── public (optional)
  16. | └── reset.css
  17. ├── view (optional)
  18. | └── home.tpl
  19. └── extend (optional)
  20. ├── helper.js (optional)
  21. ├── request.js (optional)
  22. ├── response.js (optional)
  23. ├── context.js (optional)
  24. ├── application.js (optional)
  25. └── agent.js (optional)
  26. ├── config
  27. | ├── plugin.js
  28. | ├── config.default.js
  29. ├── config.prod.js
  30. | ├── config.test.js (optional)
  31. | ├── config.local.js (optional)
  32. | └── config.unittest.js (optional)
  33. └── test
  34. ├── middleware
  35. | └── response_time.test.js
  36. └── controller
  37. └── home.test.js

As above, directories by conventions of framework:

  • app/router.js used to configure URL routing rules, see Router for details.
  • app/controller/** used to parse the input from user, return the corresponding results after processing, see Controller for details.
  • app/service/** used for business logic layer, optional, recommend to use,see Service for details.
  • app/middleware/** uesd for middleware, optional, see Middleware for details.
  • app/public/** used to place static resources, optional, see built-in plugin egg-static for details.
  • app/extend/** used for extensions of the framework, optional, see Extend EGG for details.
  • config/config.{env}.js used to write configuration files, see Configuration for details.
  • config/plugin.js used to configure the plugins that need to be loaded, see Plugin for details.
  • test/** used for unit test, see Unit Test for details.
  • app.js and agent.js are used to customize the initialization works at startup, see Application Startup Configuration for details. For the role of agent.js see Agent Mechanism.

Directories by conventions of built-in plugins:

  • app/public/** used to place static resources, optional, see built-in plugin egg-static for details.
  • app/schedule/** used for scheduled tasks, optional, see Scheduled Task for details.

To customize your own directory specification, see Loader API

  • app/view/** used to place view files, optional, by view plugins conventions, see View Rendering for details.
  • app/model/** used to place the domain model, optional, by the domain related plugins conventions, such as egg-sequelize.