That's a long one! There are so many different cases that one would have to write a leaflet, if not a small book, to cover all of them.
In any case, you use 'the' when the noun it refers to is already known, is specified, or when there's only one such thing: The Earth orbits the sun. The book on the table is mine (there's only a book on the table and it's defined by the relative clause. However, you'd say: There's a book on the table, when you first refer to it.)
On the contrary, when you speak of something in a general manner, without specifying it, you use 'a/an' with a countable noun in the singular or no article at with plural nouns or (necessarily) singular uncountable nouns: I'm thinking of buying a new car (some car, not the specific yellow car in the car dealer's lot). People need to eat in order to stay alive (Each and every person wherever they might be, not the people of the small village next to the river). Water freezes at 0 degrees Centigrade (All water all over the Earth, not just the water in the glass I'm holding).
But there's a lot more...
It would be better if you wrote some sentences and ask whether your use of 'the' is correct or not and why.
By the way, when you say "When i am writing the documents...", what documents do you mean? You haven't told us anything about any documents, so we don't know about your documents yet, they haven't been defined. You should therefore not have used 'the' here - 'a document' would be acceptable.
Student or Learner