elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
10.15k stars 217 forks source link

Revolutionizing ElysiaJS: Proposing a Scalability Boost by Emulating Spring Boot or NestJS Structure #595

Open ouarrho opened 6 months ago

ouarrho commented 6 months ago

What is the problem this feature would solve?

ElysiaJS, while a promising framework, currently lacks the structured organization and conveniences provided by frameworks like Spring Boot or NestJS. This proposal aims to address this gap by suggesting enhancements to ElysiaJS to make it more closely resemble the architecture and features of these well-established frameworks.

What is the problem this feature would solve? The proposed feature aims to streamline the development process by introducing a more organized and standardized project structure similar to that of Spring Boot or NestJS. By doing so, developers using ElysiaJS would benefit from:

Improved Maintainability: A structured project layout makes it easier to locate and understand code, reducing the time and effort required for maintenance and debugging.

Enhanced Scalability: With a modularized architecture including DTOs (Data Transfer Objects), validators, modules, controllers, and services, developers can easily scale their applications as they grow without sacrificing code maintainability or readability.

Faster Development: The standardized structure provided by this feature accelerates the development process by eliminating the need for developers to reinvent the wheel when organizing their projects. This allows them to focus more on implementing business logic rather than worrying about project structure.

Code Consistency: Enforcing a consistent project structure encourages adherence to best practices and coding standards across the development team, leading to more uniform and maintainable codebases.

What is the feature you are proposing to solve the problem?

The feature proposed aims to overhaul the architecture of ElysiaJS to introduce a structured framework that closely mirrors the organizational principles of Spring Boot or NestJS. This comprehensive enhancement encompasses several key components:

Modularization: Implementing a modular architecture to compartmentalize functionalities into distinct modules, fostering better organization and separation of concerns.

DTOs (Data Transfer Objects) and Validators: Introducing a mechanism for defining DTOs and validators to ensure robust data consistency and validation throughout the application.

Controller and Service Abstraction: Implementing controllers to handle incoming requests and services to encapsulate business logic, facilitating better code organization and promoting scalability.

Configuration and Dependency Injection: Providing features for centralized configuration and dependency injection to promote loose coupling and facilitate easier testing, enhancing the maintainability and extensibility of ElysiaJS applications.

Comprehensive Documentation and Examples: Accompanying the implementation with thorough documentation and practical examples to guide developers in effectively utilizing the new features and adopting best practices.

By incorporating these features, ElysiaJS aims to revolutionize the development experience, empowering developers to build scalable and maintainable applications with greater ease and efficiency.

What alternatives have you considered?

No response

nxy7 commented 2 months ago

I would love to see something like that - coming from using NestJS in my daily job I think that while NestJS is a bit heavy, it has the right ideas for organizing code and some DI around services in Elysia (like services depending on each other - if I'm not mistaken ElysiaJS doesn't really support that rn) would be lovely. The biggest advantage of Elysia to me is not speed - it's AMAZING E2E type safety and OpenAPI docs out of the box implemented in much cleaner way than NestJS decorators.

So while I totally agree with the sentiment, it's weird to create Revolutionizing ElysiaJS issue without more concrete proposal. I imagine that the main problem is that Elysia has many limitations due to concessions made to satisfy TS magic that allows E2E safety and it's other features.

I think that even if ElysiaJS is unopinionated framework it would be nice to have official example of ElysiaJS app with logging/authentication and couple services that would follow currently recommended best practices. Right now I have to browse discord to get that and I'm still not sure how to derive auth globally and override it for some routes that need to have user logged in so I don't have to do null checks on derived auth object :P

SnowMarble commented 2 weeks ago

I think implementing AbstractHttpAdapter would be better than building it from scratch. There is an adapter for Hono, but I can't find one for Elysia. If you're interested, I'm willing to help you out.

ouarrho commented 2 weeks ago

I think implementing AbstractHttpAdapter would be better than building it from scratch. There is an adapter for Hono, but I can't find one for Elysia. If you're interested, I'm willing to help you out.

We can definitely discuss this in more detail privately. You can find my contact information in my profile, and feel free to reach out via email. Looking forward to hearing from you!

SnowMarble commented 2 weeks ago

@ouarrho I'm glad to hear that. But, I don't think that there's anything to discuss. You can just start the project and let me know the repository url after some work on it. Then, I can review the code or contribute to it.