PWeb Module Structure

Let’s assume that we have module called boot and try to understand the module structure.

boot
├── boot
|  ├── boot_module.py
|  ├── common
|  ├── controller
|  |  ├── boot_static_controller.py
|  |  └── home_controller.py
|  ├── data
|  ├── dto
|  ├── model
|  ├── service
|  └── template-assets
|     ├── assets
|     └── templates
├── README.md
└── setup.py
  • boot : Directory name of the module, it always Hyphen seperated if the directory is multiple world. Example: boot-module

    • boot : Package name of the module.

      • boot_module.py : Hart of the module, here register all the controllers, configuration and others

      • common : Store common implementation.

      • controller : Store all the controllers

        • boot_static_controller.py : Controller comes with default, mapped for static resource.

        • home_controller.py : Default home controller

      • data : Store various data class, enum etc.

      • dto : Here store Data transform object or form. Responsible for Validation, Serialize and Deserialize

      • model : All models or Entity definition.

      • service : Business logics are stored here

      • template-assets : Directory for SSR view and various static resource.

        • assets : Store CSS, JS, Image, Font etc.

        • templates : All jinja files with HTML content.

    • README.md : Overview of the project

    • setup.py : Listed Dependencies and module information


boot_module.py

This is the hart of a module.

from boot.controller.boot_static_controller import boot_static_controller
from pweb import PWebComponentRegister, PWebModuleDetails
from boot.controller.home_controller import home_controller


class BootModule(PWebComponentRegister):

    def app_details(self) -> PWebModuleDetails:
        return PWebModuleDetails(system_name="boot", display_name="Python Web Boot")

    def run_on_cli_init(self, pweb_app, config):
        pass

    def run_on_start(self, pweb_app, config):
        pass

    def register_model(self, pweb_db):
        pass

    def register_controller(self, pweb_app):
        pweb_app.register_blueprint(home_controller)
        pweb_app.register_blueprint(boot_static_controller)
  • app_details(self) : Send module name and display name for register

  • run_on_cli_init(self, pweb_app, config) : Run from CLI command

  • run_on_start(self, pweb_app, config) : Called each time when the project run

  • register_model(self, pweb_db) : Register model if need to add during the schema creation.

  • register_controller(self, pweb_app) : Register all the controller here of the module.


This is the file which is responsible for register module in to the application