This page explains how you can build your own factories and stations and what's the purpose of each type.
Building stations is very expensive and require that you get hold of a Dock Builder, a specific ship class used to that effect. Dock builders are slow, big and fairly weak ships, so you may want to keep an eye on them, especially when they are building stations.
Each sector can only support a given amount of factories and docks. The exact nature of what can you can build in a sector depends on many factors (colony, solar system, asteroid density, sun). Use the sector info panel [F4] to determine what you can currently build somewhere.
In Unending Galaxy, docks are mostly self sufficient but can still be tuned through their setup menu. In instance, you do not need to micro manage dock traders from your factories, nor you need to replace destroyed ones. The docks will take care of that automatically for you.
Factories are here to make money for you. They produce goods from other resources over time. When you build a new factory, it will automatically come with a cargo ship that will start collecting the needed resources and sell your product.
A lone factory won't make a whole lot of credits, it may even lose some if the resources needed are scarce in the area. What will really make some cash is to setup a production chain. In instance, iron mines often only need energy cells to produce the iron. Sure, you could buy this energy from a 3rd party but it would reduce your benefits. Build a solar power plant nearby, set your iron mine to only buy from your own docks, and you will basically produce it for free. To change such settings, use the scan/setup ([Q]) key to show the setup menu.
Military bases aren't cheap, but they offer many advantages. They are well armed and sturdy, they also house large hangar bays filled with military fighters. They will protect your ships and stations in the vicinity, they also provide a place to repair and rearm your assets.
Another important property of the military bases is that whoever has a military base in a sector become the new owner of this sector, no matter how many docks the previous owner may have there. This feature can be used both defensively and offensively. Be wary, the previous owner may really get pissed off and declare war on you to reclaim lost territory.
When built in a solar system you own, each of your military bases will also maintain a small police patrol wing to further deter pirates from the area.
You can't have more than one military base per sector.
Shipyards can be seen as improved military bases, the same rules apply. But the main point of shipyards is that they allow you to build your own ships out of ship parts. It is way less costly or more reliable to use your shipyard than manually buying ships from third parties.
You can set your shipyard's production with the interact key ([E]).
Shipyards can only be built in capital sectors.
Trade stations are used by trading ships to buy and sell goods. Prices are defined by the how much in in store for each product. They do not offer any kind of military protection.
You can only build one trade station per sector. Their setting menu will show what is exported (in green) and what needs to be imported (in red) from outside of its current solar system (or single sector if built outside of a solar system). As a result building at least one trading station per sector will make things easier for you when building your economy.
Also, colonies require a trade station in the same sector for them to import and export their products.
Let's imagine you've found a decently placed sun where there's still some room for another solar power plant. You will need to
Your dock builder will then start doing its job and a building animation should be shown. Building stations can take a bit of time, the credits will be spent immediately, but you will be reimbursed if you cancel the order.
Be wary of pirates, they may attack your dock builder or your factory is you're not in the best of terms with them.