Well what you asking is a little bit tricky that even people with more than 2 years experience with piano and guitar have difficult to do but here is something you may want to try and see
Try to make the chords first and melodies second, because on that way you know where your chords and scale, are and you can easier build melodies on top of that scale
But if you already have a melody there, like a vocal hook or whatsoever : than try to identify what notes that melody is playing and write the notes on your daw
Here i got one melody notes are like
F, d, f, d, f, f, f, g, e, c, e, c, e, c, e, f, e, d, c, d
So as we can see on these notes we have the f+d chant at beggining, which makes it a d minor chord
If you play like f, d, f, d than a d minor chord you see that it works together
And we also have c + e chant wich makes it a c major, if you play c + e few times than c major chord after you see that it works together
We also have that g note, wich is a little tricky, because we can add a g chord there to suit to that but that is not a must do , we can , we can stick with only d minor and c major chords on this situation
So chords of these song i would only let them d minor, and c major, because that g and the f its not like chanting too much to add a g minor chord, and we dont want our chords to jump up and down just because one note there
But when the c and the e is chanting there like three times you sure need to add a c major chord there
And when that last note d sure is expecting you to get back to d minor
I hope this gives you an idea of how chords work, all the best from me, Laureat Ramadani