Repository navigation
Opinionated Project Layout -- Do we have such thing in Huma? #1167
|
Hey guys, I am quite happy to see we have this library. Coming from Django/NestJS background I am used to have a well-established project schema. At least NestJS dictates one. I wonder if Huma comes with such thing too. Thanks in advance, and if you wonder what I mean by project layout I mean something like this: I am asking this question since I started to work on this: Ponos-OS/piper-tts-rest-api#4 |
Replies: 2 comments 2 replies
|
No. Huma has no generator and does not prescribe a layout. It describes itself as a micro-framework (Why Huma), the docs have no page on project structure, and the tutorial keeps the whole service in package It does give you three pieces for splitting an app by feature the way Nest modules do:
For the directories, the Go team's Organizing a Go module is the usual reference for a server: // internal/voices/handler.go
type Handler struct{ Store Store }
func (h *Handler) RegisterRoutes(api huma.API) {
huma.Get(api, "/voices", h.list)
}
// cmd/api/main.go
huma.AutoRegister(api, &voices.Handler{Store: store}) |
|
Hey @kasir-barati! Nope, there's no enforced project structure. I personally love layered architectured, as is defined in Ben Johnson's WTF Dial repo. Huma fits very easily into this, and I use it in a number of very high traffic projects for work :) |
No. Huma has no generator and does not prescribe a layout. It describes itself as a micro-framework (Why Huma), the docs have no page on project structure, and the tutorial keeps the whole service in package
main.It does give you three pieces for splitting an app by feature the way Nest modules do:
huma.Register,huma.Getand the rest take anyhuma.API, so a feature package can export one function that mounts its routes. The testing tutorial uses that shape (addRoutes(api)) so tests mount the same routes on ahumatestAPI.huma.AutoRegister(api, handler)calls every method onhandlerwhose name starts withRegister. A struct that holds its dependencies and hasRegister...methods is the…