You can find Tor's source code on Github. Most of the cool stuff is in the src folder. Some parts of the code are accompanied by comments that tell you what it does. This is a sample code snippet from src/feature/relay/dns.h
/** How long do we cache/tell clients to cache DNS records when no TTL is
* known? */
#define DEFAULT_DNS_TTL (30*60)
int dns_init(void);
int has_dns_init_failed(void);
Alternatively, check out this paper which analyses Tor's code step by step. Here, you can see functions and explanations of what they do. To see the code under each function, simply search it in Tor's Github repo. Here's an example screenshot from the paper:
To make edits to the code, you can either fork or download Tor's repo from Github.