Onion is an innovative framework designed to simplify the development of large-scale frontend applications without being tied to any specific framework or library. It focuses on the business logic layer, providing a structured and modular approach to application development through the use of Onion Architecture.
A key feature of Onion is its framework-agnostic nature. It is built to work seamlessly across different development environments, ensuring that developers can integrate Onion into their projects regardless of the frontend framework or library they choose. This makes Onion a versatile and flexible choice for application development.
Onion organizes applications into distinct layers, each with a specific responsibility:
Houses the domain entities, representing the business model and its rules.
Responsible for data access logic, abstracting the interaction with data sources.
Contains the core business logic, processing data and executing operations.
Provides technical capabilities like HTTP communication and state management tools.
Manages the application's flow, handling user interactions and responses.
Onion introduces decorators to effortlessly add classes to the IoC (Inversion of Control) container for each layer:
@Entity
@Repository
@Service
@Infrastructure
@Application
Additionally, the @Inject
decorator is available to inject dependencies through constructors, further simplifying dependency management in your application.
import { Service, Repository, Container, Inject } from "onion-core";
@Repository({ name: "UserRepository" })
class UserRepository {}
@Service({ name: "UserService" })
class UserService {
constructor(@Inject({ name: "UserRepository" }) private readonly userRepository: UserRepository) {}
}
const userService = Container.get<UserService>('UserService');
To start using Onion in your project, install it via npm:
npm install onion-core
Contributions to Onion are welcome! Whether it's feature enhancements, bug fixes, or documentation improvements, your input is valued. Please refer to our contributing guidelines for more details.
Onion is licensed under the MIT License, allowing its use in both open-source and commercial projects with minimal restrictions.