This codebase highlights three different approaches you can use to organize your AdonisJS business logic operations.
- Fat Controllers
- Controllers contain all tasks needed to complete an operation
- Repetitive tasks may be extracted into a service for reusability as needed
- Services
- Controllers are in charge of validating the request & returning the response
- The core operational tasks of the request is done within a service method
- The service method may call additional service methods as sub-tasks to complete the operation
- Multiple actions are grouped within a single service class, often by resource
- Actions
- Controllers are in charge of validating the request & returning the response
- The core operational tasks of the request is done within an action class
- The action class may contain several methods, as needed, to complete the single action it's meant to handle
- Unlike services, each action has it's own class. Each action class may be housed within nested folders, as needed, and usually at least nested within a resource folder
Want to learn more? Check out our lesson where we discuss each of these three approaches