📎 Webclip
Phoenix: The difference between web and lib
Phoenix has two distinct places for code, the web directory and the lib directory. The post says the main difference is hot reloading: code in web is recompiled on the next request after a change, while lib is not treated that way.
That difference maps to state management. web is the right place for code that only needs to manage state during one request, and lib is the right place for code that manages state outside a request lifecycle, such as Supervisors, Agents, or GenServers. This fits the idea that Phoenix is just an OTP application, with web components as one part of the application.
Reading notes#
webandlibare the two code locations Phoenix distinguishes.webis hot reloaded, so a file change is picked up on the next web request.- The code layout should follow state management needs.
websuits state that lasts only for a request.libsuits state that lasts beyond a request, including Supervisors, Agents, and GenServers.- Phoenix is presented as an OTP application, not as a framework bound to a strict request/response cycle.
