Basically, it is affected by two sets of things: wealth producers, and wealth consumers.
Planetary populations are your greatest source of wealth (assuming you aren't playing with a version where moneyships are possible). You also generate wealth from the activities of civilian vessels (taxes on cargo pickup, dropoff, and carrying cargo-each is a seperate, taxable activity), from civilian mining colonies, from financial centers, and from scrapping operations.
Your wealth is "used" for pretty much everything you do: installation operation, shipbuilding, shipyard expansion, supporting ground troops and ships, etc.
It can be difficult to balance wealth without cheating with moneyships, so your best bet for staying in the black is to cycle operations. In other words, don't be building factories, missiles, ships, ground troops, and fighters, while also expanding your shipyards and conducting research. Stick to two-three activities at a time, and you'll usually be able to balance things out. The Expand Civilian Economy research projects give a big boost, but have increasingly absurd RP requirements. IIRC, the later ones can get into hundreds of millions of RP required to complete. One or two is usually enough. I tend to avoid financial centers because they drain population away from important workforces for little return.
The best non-cheating way to have plenty of wealth is to do a conventional start with a high population (1-2 billion), as you will be building up massive amounts of population and wealth for decades while you slowly build up your T/N industry. Typically when I do this, I have in the neighborhood of 600,000-750,000 racial wealth by the time I start going negative on my income.