Rather than me poorly trying to explain this, you'd do well to research this on your own. I will just point you in the right direction.
There's considerable research indicating that there is a bidirectional communication going on between your gut and your brain—this is termed the gut-brain axis. In a healthy individual the gut and the brain work together smoothly, but in an individual with gut dysbiosis this communication is disrupted and all sorts of chronic diseases appear, including irritable bowel syndrome, depression, autism spectrum disorder, irritable bowel syndrome, Alzheimer's disease, other neuropsychiatric disorders, and chronic inflammation in general.
Inside your gut, your intestines, live trillions of bacteria (microbiota). Some of these have a parasitic relationship with you—hijacking your system for their own gain at your expense—while others function symbiotically.
What you want to do is to stop introducting and feeding parasitic microbiota, and start introducting and feeding symbiotic microbiota. This can be done in a number of ways but the simplest one is via diet. In order to starve the former I suggest following a diet similar to the one I have outlined on my nutrition page, and in order to introduce the latter I suggest regularly eating probiotic food, such as sauerkraut or kefir (more here). Just beware of pasteurized fermented foods; pasteurization kills most bacteria! But assert the quality of the food and its preparation, don't get sick.
Do your own research and draw your own conclusions. Visit PubMed or PubMed Central (the latter has full text articles) and search for e.g. "gut microbiota", "gut-brain axis", or any of those two plus your subject of interest e.g. "gut microbiota depression".
I'll link a few interesting articles here below.
Reviews, ordered by most recent first
Randomized control trials