Concepts
This section focuses on the core concepts of the Sodacore framework, these are the building blocks that make up the framework, and understanding these concepts will help you understand how to use the framework effectively.
Controllers
Controllers are classes that handle incoming requests and return responses. They are the entry point for your application, and they are responsible for handling the business logic of your application. Controllers can be used in various plugins, such as HTTP, WebSockets, and more.
Providers
Providers are classes that provide reusable logic that can be used across multiple controllers or even just normal classes. They are a great way to keep your code DRY (Don't Repeat Yourself) and maintainable. Providers can also be injected into other providers, controllers, and services.
Services
Services are classes that manage long-running processes, such as HTTP servers, WebSocket servers, and more. They have lifecycle hooks that are called at specific times during the application's lifecycle, such as init
, start
, and stop
. Services can also be injected into other services, providers, and controllers.
Tasks
Tasks are essentially in-application cron jobs, that can be scheduled, executed programmatically, or executed manually via the CLI, and represent usually a single unit of work. Tasks can be used for various purposes, such as sending emails, cleaning up databases, and more.
Hooks
Hooks are a way to tap into the lifecycle of a class and perform actions at specific points in time. They are implemented as decorators and can be used on any class that is managed by the Sodacore framework, such as controllers, services, providers, etc. Hooks allow you to execute code before or after certain events, such as when an HTTP request is received or when a WebSocket connection is opened.
Scripts
Scripts are classes that can be executed via the CLI, and can be used for various purposes, such as database migrations, data seeding, and more. Scripts can also be injected with providers, services, and other scripts.
Workers
Workers are classes that run in separate threads, allowing you to offload CPU-intensive tasks from the main thread. They can be used for various purposes, such as image processing, data analysis, and more. Workers can also be injected with providers, services, and other workers.
Middlewares
Middlewares are functions that have access to the request and response objects, and can be used to modify them or perform actions before or after the request is handled by a controller. Middlewares can be used for various purposes, such as authentication, logging, and more.
Transformers
Transformers are classes that can be used to transform data before it is sent to the client or after it is received from the client. They can be used for various purposes, such as formatting data, filtering data, and more. Transformers can also be injected with providers, services, and other transformers.