For the SDK documentation itself, go to v3.0 SDK online docs, which, for this purpose is the same of v3.1. That docs explain the different template mechanisms, and some basic concepts to getting into special code, plugins, etc.
When you are writing code using the SDK it's very useful to have the Core Assemblies Reference Manual, you can download it from the CustomerArea -> v3.1 Downloads - Documentation. The exact link is this (yo need to be logged in as a customer).
When you say "source code for code generation" I think you mean "the command line generator". To get that you must download the SourceCode package at v3.1 Downloads - > Extras, this is the link. Into that package is all source code (plugins, runtime libraries, importers, typeConverters and command line tools). The command line generator is in the "\CLIGenerator" folder.