Optimizing colonies
I don't quite get how this would be specific per planet type. Overpopulation leads to crime, which leads to instability. That is true of any planet.
The math to avoid overpopulation is very simple:
1 pop needs 1 housing and 1 job
If your planet has 25 housing and 20 jobs, you can therefore safely have 20 pops on the planet. The next 5 would still have housing, but no job, which leads to unhappiness and/or crime.
The same logic applies if you have 20 housing and 25 jobs. The first 20 are golden, but the next 5 will have a job and no house, which also leads to unhappiness and/or crime.
The formula is basically figuring out the max housing and max jobs you can have, take the lower of the two numbers, and using that as your goal population limit. Anything over that limit will result in homeless or unemployed pops.
But of course, you can tweak this based on the districts and buildings you choose. You can usually trade some housing for jobs (or vice versa) to ensure that the lowest of the two maximums is as high as you can possibly get it.
Food/mineral/energy districts add jobs and housing in equal measure, but housing districts significantly add housing (and a single job).
Buildings add jobs, with the exception of the luxury residences, which add housing instead.
Usually, when the population is low you begin with resource districts because you don't yet have the building slots to support a specialist/ruler population. When your population grows and you start filling in the job-buildings, you'll be required to add housing districts that supply housing for whoever works on a building tile (the ones working in the resource districts have their own housing in that district).
When low on housing
- Convert resource districts to housing districts
- Convert job-buildings to luxury residences
When low on jobs
- Convert housing districts to resource districts
- Conver luxury residences to job-buildings
Which buildings/districts you build or convert fully depends on the specialization of the planet, but the housing/job numbers game always stays the same.
Some sidenotes
- I've ignored modifiers such as housing pop usage, which can leads to e.g. 10 pops only needing 9 housing.
- Once your pop starts growing, amenities need to be managed as well. It's usually just a matter of plopping down an entertainment building when amenities run low, thus taking up a building slot.
- Unless upkeep cost is an issue, it's generally better to add buildings rather than convert existing ones. Only start converting when you don't have open slots anymore (or are trying to keep upkeep costs low).
The only buildings I would consider completely mandatory are the feature-related buildings.
Core buildings would include upgrading your capital and building population growth buildings to grow your colonies faster. Unity buildings are usually a good idea as well.
The rest depends on your overall strategy and the planet's specialization. Usually you want to max out the most numerous resource district (generator district for example) and have that resource's matching building (energy hub in this case). But even that may not be optimal depending on your game and buildings available.
Managing housing, amenities, and unemployment is an ongoing struggle throughout the game and you have a few tools to deal with this. Besides buildings, you can research tech that provides amenities/housing or reduces your need for them. You may also have the ability to resettle pops and allow them to migrate on their own.
Most of your planet management will depend on your big-picture strategy though. Once you meet all your minimum requirements, you'll be able to choose what to produce to help you conquer the galaxy. This is the fun part, play around with it!
There is no formula that's true for all situations. But there are some rule of thumbs, at least for me, when I manage my planets:
Always get ALL the building slots unlocked on any planet. Even a measely 10-size planet can have 16 building slots, which cause no empire sprawl and can be filled with research, consumer goods, etc. You need 75 pops for that, so plan your housing accordingly, e.g. 14 housing disctricts (with some research, they add more housing, which means, you need less)
Think about what you wanna build on the planet and how many jobs the highest tier building of that provides. Wanna go research? Then you get 8 jobs per building, so you want to plan your housing according to that.
Any districts that don't need to be housing disctricts are going to be energy, mineral or food. Most of the time, in the early game, I build more of the ressource districts, as I need the ressources and can't provide enough jobs with buildings yet. Later I switch some of these districts to housing, so I can fill the planet with juicy research or alloys.
Don't think tooo mouch about what you want to build where in advance. Just build what you need right now, with these rules of thumb in mind, but not calculating everything. Then, later, when the planet has grown, it's much easier to switch some buildings and districts and balance according to that.
On a sidenote: I usually value pop-housing-usage reduction traits pretty high, because they really add up with other boni, which means you need far less housing districts and can build ressource districts instead, which also provide some extra housing with the reduction to pop-housing-usage.
As for mandatory buildings on planets: It really depends on your situation, your civics, ethics etc. If you have lots of unhappy slaves, you need more enforcer jobs. If you are low an ameneties, you need more entertainer jobs. I usually go for 1 enforcer building if the planet has problems with crime and 1-2 holo theatres depending on amount of slaves and general ameneties. For specialisation it should be easy: Want the planet to produce research? Get the research institute and fill the rest with research centers. Want alloys? Build factories. Want trade? Build commerce.
I hope my answer can help you!