The basis of astrology is related to Solar system. Our ancient saints have developed their inner consciousness to a great extent through meditation and yogic sciences. Due to the development of inner consciousness they could receive the divine knowledge. After meditating and deep thinking on this divine knowledge they could visualize the solar system in their minds.
With their understanding of solar system they were able to form relation of other planets with Earth. They could also feel the impact of Sun and Moon on earth and human beings. On the basis of this relation the nine planets, the twelve months, the time system, etc. were formed. This knowledge got more systematic and deeper.
Sun is taken as a centre of this universe. Other than Sun six other planets that are Moon, Mars, Mercury, Jupiter, Venus and Saturn were taken into account. Rahu and ketu are two points were considered to be shadow planets. The relation of these planets with Earth and people living on Earth were formed and it became a deep study. Since Sun is not planet but a start and Earth is a planet but for convenience Sun is taken to be a planet for easy calculation and Earth is not taken into this equation. This made all astrological calculations easier. Thus, nine planets were formed. It is believed that when a native is born then the effect of these planets is bestowed on that native based on the position of planets in the sky at the time of birth of the native.
Solar system or the whole cosmos is taken to be a circle. As you already know that each circle has 360°. It is also called as Bha-Chakra. All the planets, constellations, stars and all heavenly bodies are situated in this Bha-chakra. It will be very difficult to identify a particular place in such a big area. So this circle is divided into twelve parts. Since the circle has 360° so dividing it into twelve parts will make each part equal to 30°. This part which measures to 30° is called as houses in astrology. Thus there are twelve houses in each horoscope.