[{"data":1,"prerenderedAt":118},["ShallowReactive",2],{"docs-\u002Fdocs\u002Fmain\u002Fmodules":3},{"id":4,"title":5,"body":6,"description":105,"extension":106,"group":107,"meta":108,"navigation":109,"order":110,"path":111,"section":112,"seo":113,"source":114,"stem":115,"version":116,"__hash__":117},"docs\u002Fdocs\u002Fmain\u002Fmodules.md","Modules and lifecycle",{"type":7,"value":8,"toc":96},"minimark",[9,14,23,27,34,38,45,49,72,76],[10,11,13],"h2",{"id":12},"register-a-module","Register a module",[15,16,17,18,22],"p",{},"A module implements ",[19,20,21],"code",{},"Register(*app.Registrar) error",". Registration declares routes, managed resources and named readiness checks; it should not open listeners or databases. Register related modules together when their declarations must succeed atomically. Registration seals before startup, and retained registrars cannot mutate a running app.",[10,24,26],{"id":25},"keep-business-logic-independent","Keep business logic independent",[15,28,29,30,33],{},"Keep business services in ",[19,31,32],{},"modules\u002FNAME\u002Fservice.go",". They accept context and domain values and depend on small interfaces owned by their consumer. HTTP schemas\u002Fhandlers, Protobuf mappers and GORM adapters translate at the boundary. Avoid a shared repository that exposes another service's database.",[10,35,37],{"id":36},"share-services-across-adapters","Share services across adapters",[15,39,40,41,44],{},"Generated modules expose an injectable service and ",[19,42,43],{},"NewModuleService","; generated registries create one service for all its adapters. Change business logic in handwritten files. Tool-owned registries are hash-checked and must be reconciled explicitly if manually edited.",[10,46,48],{"id":47},"manage-resources","Manage resources",[15,50,51,52,55,56,59,60,63,64,67,68,71],{},"Use ",[19,53,54],{},"Registrar.Manage"," for resources implementing ",[19,57,58],{},"Start(context.Context) error"," and ",[19,61,62],{},"Close(context.Context) error",". Dependencies register before their consumers: database, client pool, then server. Startup failure closes resources already started; shutdown drains HTTP and closes resources in reverse order. Resources can expose an ",[19,65,66],{},"Errors() \u003C-chan error"," channel for asynchronous failure; ",[19,69,70],{},"App.Run"," then stops the application and returns an error. Resources must honor their lifecycle contexts.",[10,73,75],{"id":74},"own-background-work","Own background work",[15,77,78,81,82,85,86,89,90,95],{},[19,79,80],{},"Start"," is explicit, ",[19,83,84],{},"Run"," waits for cancellation\u002Ffailure, and ",[19,87,88],{},"Shutdown"," is idempotent. A stopped application cannot restart. Do not start unmanaged goroutines from registration: own their cancellation and join them from a resource's Close method. See ",[91,92,94],"a",{"href":93},"\u002Fdocs\u002Fmain\u002Foperations\u002F","operations"," for health checks and shutdown behavior.",{"title":97,"searchDepth":98,"depth":98,"links":99},"",2,[100,101,102,103,104],{"id":12,"depth":98,"text":13},{"id":25,"depth":98,"text":26},{"id":36,"depth":98,"text":37},{"id":47,"depth":98,"text":48},{"id":74,"depth":98,"text":75},"Register explicit Go modules, share business services, and manage resources through startup and graceful shutdown.","md","APPLICATION DESIGN",{},true,60,"\u002Fdocs\u002Fmain\u002Fmodules","build",{"title":5,"description":105},"modules.md","docs\u002Fmain\u002Fmodules","main","4G9c2smIj_RtLmv3EhXci4krDjVIrTd3jlHkzjCYaRk",1792521640371]