In music, what is beautiful is not always right and vice versa, but while beauty cannot be taught (up to a certain point...), correctness can.
In my opinion, a good starting point is the STRUCTURE of a piece. Start with a simple structure, for example, the exposition of a romance, and try to stay within a fixed number of measures. For example, if your initial idea in G minor is 4 measures long, construct a response to this idea that is also 4 measures long. Do not think in terms of duration—2 minutes, 3 minutes, no—think in terms of measures, of structure. If in the initial idea you say something, for example: "Hi, how are you?", in the response you will say: "Fine thanks, and you?", so that the response moves onto chords that the proposal does not touch; it is a simple way to avoid being repetitive while remaining in the same key.
After the first back-and-forth, re-propose the initial idea slightly varied, in the sense that you can add some flourishes to the melody, a few extra notes in the accompaniment, but with the same number of measures, and then a second response, of the same number of measures, which is also different from both the main theme and the first response.
In practice, it is the scheme: 4 bars T (theme) - 4 bars R1 (response 1) - 4 bars T' (slightly varied theme) - 4 bars R2 (second response).
This should already work. Make sure that the last chord of each section connects well to the first chord of the next section.
To this basic scheme, you can add variations before and after: a small introduction or a small coda; often pedals work well as an introduction and coda—that is, staying on the same bass note while changing the harmonies above; the most used pedals are the tonic (I degree) and the dominant (V degree).
You could have a short piece of 16 measures, which with an intro and coda could become 24-26-28... then perhaps the theme will start to be 6 instead of 4 measures; in short, there will be ways to increase the proportions.
This is just one of many schemes that can be followed.
I often have students who have ideas but do not know how to develop them and literally limit themselves to "jamming" them together: this happens because they do not think in terms of structure; it is like wanting to build a palace without a project, but simply starting to mix some bricks with lime and seeing what happens.
Over time, you might discover that sometimes "to sink in this sea is sweet" and letting fantasy lead you wherever it wants is not bad, but to avoid drowning in the early days (and even the second and third...) it is better to follow a structure.
One last thing: even when you have learned to master compositional technique, orchestration, and so on, you will continue to feel like a microbe compared to the great composers, because that is where a completely uncontrollable factor comes into play, personal and outside of any dynamic related to teaching: the sacred fire of GENIUS.
You can write the most "correct" fugue there is, with the most "accurate" counterpoints, then you listen to the counterpoint in Bach's The Art of Fugue and you say: "Well, we were just joking", close everything, and laugh and cry at the same time.....