While I’m no expert on this, I can give you some tips from my personal experience.
It really pays of to study cadences, that is, endings of musical phrases. For a start, look for example here: http://openmusictheory.com/cadenceTypes.html
Or here: http://bassus-generalis.org/muffat/muffat_regulae.html (Only the chapter on cadences)
Now, these are examples of classical music, the second link even of baroque music, but the same principles apply as for modern tonal music. And they are a good way to start on cadences before you dive e.g. into Jazz cadences, which are more complicated, but are built on the same basic principles. Even the Wikipedia article https://en.wikipedia.org/wiki/Cadence_(music) says so, so it must be true ;-)
I have written many different cadences and so after some practice, it has become much easier to write a cadence. And this is something one can learn alone, as one hears if a cadence works or not.
One neat trick in composing is to reduce your composition to a harmonic / melodic „background level“ and plan your composition this way with a broad brush, and then fill in your basic motives where they belong. It now becomes much easier to envision which rhythms and pitches to use to fill the gaps. Important: Don’t feel compelled to strictly adhere to your plan, as new ideas will come up when fleshing out the composition.
Another trick is that many compositions can be analysed as a series of weak and strong cadences. So, if you have learnt to write cadences of varying degree, you are able to write a small composition as well. Probably nothing groundbreaking, but it is a good start.