为什么你的类似 Rails 的框架没有被广泛使用

Ruby on Rails defined web dev community ethos for years. Many tried replicating in other languages with mixed results. Laravel, ASP.NET and Phoenix are successful rails-like frameworks. Python has Django. Java, Kotlin, Scala, Node.js, Go and Rust lack a widely adopted rails-like experience.
Ruby on Rails was successful as creator had strong opinions as conventions. In 2003, it was different from configuration-heavy frameworks. When evaluating "Ruby on Rails"-like frameworks recently, noticed some creators' responses like "we decided to not decide" or "up to each individual to make a choice". This is counter-productive for creating a modern rails-like framework as Rails means author has strong opinions.
Thoughts on making a modern rails-like framework successful:

  • Auto-increment Keys Should Not Be IDs: Rails-like frameworks use ORMs and ActiveRecord pattern with auto-incrementing primary keys. But now, using uuids is better as they are fast and afford horizontal scaling options. Using other formats like ulid or having internal and external ids is also okay as long as the public API uses a safe id.
  • API First: Rails-like frameworks use MVC pattern. Frontend ecosystem is fragmented. Focus on APIs first and worry about view layer later. Choose a protocol like REST or gRPC. GraphQL has adoption issues and most websites still use HTTP/1.1 but 96% of browsers support HTTP/2.
  • RESTful API Specification: If API first, must have an API specification that can generate good documentation. OpenAPI spec is a good choice as it can be generated from code. Dropshot and FastAPI do a good job in this area.
  • Models From Upstream APIs: Most frameworks tightly couple models to database. Idea is to consume OpenAPI spec to codegen models. This makes it easier to compose applications and internal teams see benefits. Better tooling is needed and progenitor is purpose-built for this.
  • Feature First Structure: Most frameworks use layer-first structure which leads to accidental coupling as the app grows. Feature-first structure groups controllers, models and views by feature. It's not a silver bullet but has upsides like making it harder to create accidental coupling and easier to refactor. It also makes it easier to extract parts into separate services if scaling becomes an issue.
  • Make Decisions for Modern Application Development: A rails-like framework won't be successful by cloning Rails conventions. Framework authors must establish new conventions for modern app development to let developers get started quickly and avoid maintenance pitfalls.
阅读 18
0 条评论