Directory Structure
In the Quick Start, you should have gained a preliminary impression of the framework. Next, let's briefly understand the directory conventions.
bash
egg-project
├── package.json
├── app.ts (optional)
├── agent.ts (optional)
├── app
│ ├── controller
│ │ ├── http
│ │ │ ├── HomeController.ts
│ │ │ └── UserController.ts
│ │ ├── rpc
│ │ │ └── UserRPCController.ts
│ │ ├── mcp
│ │ │ └── MyMCPController.ts
│ │ └── schedule
│ │ └── MyTaskController.ts
│ ├── service (optional)
│ │ └── UserService.ts
│ ├── middleware (optional)
│ │ └── ResponseTimeMiddleware.ts
│ ├── public (optional)
│ │ └── reset.css
│ ├── view (optional)
│ │ └── home.tpl
│ └── extend (optional)
│ ├── helper.ts (optional)
│ ├── request.ts (optional)
│ ├── response.ts (optional)
│ ├── context.ts (optional)
│ ├── application.ts (optional)
│ └── agent.ts (optional)
├── config
| ├── plugin.ts
| ├── config.default.ts
│ ├── config.prod.ts
| ├── config.test.ts (optional)
| ├── config.local.ts (optional)
| └── config.unittest.ts (optional)
└── test
├── middleware
| └── ResponseTimeMiddleware.test.ts
└── controller
├── http
│ └── HomeController.test.ts
├── mcp
│ └── MyMCPController.test.ts
└── schedule
└── MyTaskController.test.tsAs shown above, directories defined by framework conventions:
app/controller/**- Used to parse user input, process it, and return corresponding results. See Controller for details.app/service/**- Used to write business logic layer. Recommended for use. See Service for details.app/middleware/**- Used to write middleware. See Middleware for details.app/public/**- Used to place static resources. See the built-in plugin @eggjs/static for details.app/extend/**- Used for framework extensions. See Framework Extension for details.config/config.{env}.ts- Used to write configuration files. See Configuration for details.config/plugin.ts- Used to configure plugins to be loaded. See Plugin for details.test/**- Used for unit testing. See Unit Testing for details.app.tsandagent.ts- Used to customize initialization work at startup. See Startup Customization for details. For the role ofagent.ts, see Agent Mechanism.
Directories defined by built-in plugin conventions:
app/public/**- Used to place static resources. See the built-in plugin @eggjs/static for details.
To customize your own directory conventions, see Loader
app/view/**- Used to place template files. See Template Rendering for details.app/model/**- Used to place domain models, such as domain-related plugins likeegg-sequelize.