Thursday, 24 September 2020

A library to generate framework agnostic typescript projects

Lately I've been working with a specific typescript project structure that lets me decouple business logic from my web server and database access layers, and after a while, I noticed there's a lot of room for code generation, so the last 3 days I've been working on Haykal, a project scaffolding and crud generation tool.Currently it uses Express and Objection/Knex as the View and Model layers in the MVC pattern, and automatically generates basic templates for your entities. but in the future I'd like to add other framework templates or make it easy to add your own templates.The basic idea is to abstract the Model with an interface, implement it in whatever way you want, then, you write controllers that accept the model interfaces that it needs to implement its business logic. The dependency injection is done manually in a single file, and from that file you expose all the controllers to use in your router functions, and preferably you do not introduce router logic in the controllers, but handle it there (e.g no HTTP request/responses in the controllers, only in routes). following that you're able to switch your application to a website, cli, electron app or whatnot without needing to change your business logic.The cli tool also generates templates for each part, the router, controller, model, interface and migration, altho only express and objection model implementations for now, with very limited field types (string, number, and Date)As I cobbled this together in 3 days, it's more like a proof of concept than a reliable CLI tool, but all the code outputted is left in the project directory, there's no hidden library code you can't easily fix yourself if needed.I'm looking for feedback on the project structure itself more than the tool, but feedback on the tool is also appreciated!

Submitted September 24, 2020 at 08:12AM by belkh

No comments:

Post a Comment