HACKER Q&A
📣 throwthere

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?


  👤 bacbilla Accepted Answer ✓
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.


👤 gitgud
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


👤 riemann
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.

👤 swah
NestJS was the promising one a year ago...