Ask HN: Best way to structure/architect an API with ExpressJS/TypeScript?
I've got major maintainability problems with my kind of amateurish webapp. I spent a bit of time the other day writing a bunch code that I just found out I had already written awhile back. I see a bunch of guides on Google but it's hard to judge how good they are without references/reviews. Are there some in depth guides on separation of concerns, service-oriented architecture, MVC, file structure, etc using Express? Or perhaps a really good reference project or two?
7 comments
I honestly recommend TSOA (https://github.com/lukeautry/tsoa)
For me it provides enough structure without being a super opinionated framework. It handles route and doc generation based off your models and controllers, but everything else is up to you, which is perfect for me.
For me it provides enough structure without being a super opinionated framework. It handles route and doc generation based off your models and controllers, but everything else is up to you, which is perfect for me.
Thank you! I'll take a look.
There's no best way to architect anything. It's always a trade-off and depends tightly on your situation.
Here's some practical advice. I would just look at loads of starter projects by googling "express typescript starter github" then explore each project. Things to remember when searching:
- Most starter projects have too many use cases, so you can actually delete parts you don't need.
- You don't need to use a single architecture, it may be better to combine things you like about a few different types
Here's some practical advice. I would just look at loads of starter projects by googling "express typescript starter github" then explore each project. Things to remember when searching:
- Most starter projects have too many use cases, so you can actually delete parts you don't need.
- You don't need to use a single architecture, it may be better to combine things you like about a few different types
Frameworks can help in this situation to some extent, but if going frameworkless is okay for you, Francesco Strazzullo's book "Frameworkless Front-End Development" did an excellent job of explaining what, why, and how to organize a js codebase without using external codebase, at least it did for me.
NestJS was the promising one a year ago...
Is it not so anymore? Just started learning the framework last week and have been enjoying it so far