When I want to write chords to fit a melody, I look at the key the melody is in. I need a key chart to do that. If it has no sharps and flats I know it is in C key. If it has one sharp, I know it is in G key...and so on. These charts are simple and easy to find.
I know there are 3 main chords in each key. I have to fit a chord to each melody note. There are usually several melody notes with only one chord. I have drawn a chart with these on it. It is the 1st, [the root chord]. The 4th note e.g. in key C, CDEF...the 4th note is F, so the chord is F chord. The next main chord is the 5th, and it is G, but it a 7th, so it is G7. Then I have C, F G7, the 1st, 4th and 5th notes of the key are the root note of each chord. This works in every key. So key D is D, G, A7.
If there is a minor sound, I try the minor after the root, so in C, I try Dm. In D, I try Em. I listen to see if it sounds right. If that does not sound right I try the seventh, and instead of a seventh I play a minor, e.g. A7 becomes Am.
I write the chord for each melody note which is one of those main chords which contains the note, Sometimes the note is in 2 chords so I have to listen to them and choose the best sound.