how can i 'add a new module' by code?

i want to add a module, write some text to it and then save the project with the new module added? how can i do this?