Creating fields programmatically / with PlugIn
You can look at Craft's own InstallController and InstallService to see how Craft programmatically creates the default content you see during a fresh install.