How can I document depression for later reference in grad school applications? I am currently a third year undergraduate at a good university studying computer science. I am planning to apply to top graduate schools when I finish my undergrad and I need a bit of advice.  

In the first two and half (5 semesters) of my studies, I took the most challenging CS/Math courses in my university and did very well in them (GPA 4.11/4.30). I also joined two research groups and have 2 publications where I am the first author, published in reputable journals. I also have a very good relationship with my 2 research advisors. 

Now in my sixth semester, I decided to go on an exchange semester and things just started crumbling. First of all, I couldn't integrate well in the culture and I was left very lonely with no new friends in the area. My Girlfriend of 5 years broke up with me, my mother got into a car accident which affected her health, and I started taking depression medication due to that. I also gained a lot of weight which lead to some health problems. Needless to say, this term is coming to an end and I can't wait to leave this place. I am going to probably fail 2/4 courses, and in the remaining ones, I will barely pass. I am expecting a 2.0 GPA at best. 

Now I know this won't go unnoticed by graduate school admissions. I am just wondering what steps can I take as of now to document all of this so that I can justify the poor performance in the exchange semester during my graduate application?
Your transcript should be all you need. Presumably, your transcript shows that you studied at a foreign university, and that things did not go well. If you are back to 100% next semester, it will be pretty obvious that the problems were related to studying abroad. You may then want to write something in your statement of purpose when you apply to assure them that attending grad school won't cause problems similar to what happened when you were studying abroad. This should be an easy sell, especially if the exchange program was in a very far away country and the grad program is in your home country/region.

At any rate, graduate school admissions people certainly do not want to see documentation about your health or personal relationships. They just need a believable reason for why that one semester doesn't indicate you are unfit for grad school, and the transcript showing you studied abroad far away and had some problems should address that. The only place you may run into problems is if your application is automatically filtered out before it reaches the committee -- but no way to avoid that. 

The question posed in the title is a bit more challenging. You are able to attribute your difficulties to having studied abroad. For students who suffer mental health challenges at their home universities, graduate school admission is more challenging. Even in this case, however, I do not think they are interested in seeing medical or other documentation.