We get a lot of questions about the distinction between client and server code in Anvil. To help make it clearer why we often need to write code in two different places, I’ve written a short introduction to the client-server architecture of web apps.
If you have any further questions, feel free to ask them on this thread!
Thanks for the clear explanation. A small addition: you didn’t mention performance. Performance may also be a reason to process certain code on the server side. My CalcuDoku (special kind of sudoku) solver code was running remarkebly faster at the server side.
Also, a “client-side” module (as opposed to a form) can be imported and used in a server module as well as client-side. But it’s important to understand that it’s being loaded and run in two separate Python environments if you use it both client- and server-side. So you can’t use such a module to have a global variable that is accessible both client- and server-side, for instance.