I saw a comment that was quickly deleted by the moderators for obvious reasons that just said "boats," which isn't wrong at all but does deserve elaboration.
Venice became rich and powerful through naval trade, as their geographical position allowed them to be the critical middleman between the Middle East and destinations throughout Europe. (Much like how the Mali Empire in West Africa became extraordinarily wealthy around the same time by controlling the gold trade in that region, even if the actual production mostly happened elsewhere). Northern Italy in the medieval period included some of the largest artisanal manufacturing centers in Europe, which dominated the textile business for centuries (until the early modern rise of English and Dutch manufacturing), as well as producing finely crafted weapons, armor, and other goods. Venice also bordered the Holy Roman Empire, which otherwise had little access to Mediterranean ports after northern Italy had become largely independent of the HRE by the 13th century.
Wealth flooded into medieval Venice through trade, and much of that income was put back to work making the maritime city-state more capable of controlling future trade (this is not to say that none of it went to funding privileged lifestyles of the elites, of course!). The incomes of medieval and early modern states were often wasted in pursuit of dynastic ambitions or extravagant courts that did little for economic growth, but the equally extravagant sums spent by Venice went towards creating a powerful navy and building bases all along the eastern Adriatic coast and in Greece. No one could outpace the Venetian Arsenal in shipbuilding prowess- galleys could be constructed from scratch in as little as a week. Venice slipped into the power vacuum left by the decline of the Byzantine Empire (and through their actions in the Fourth Crusade also played a crucial role in this decline).
All this gave Venice substantial protection against piracy, and made them a true rival on the seas of the Ottoman Empire. While Venice does have a long history of warfare with Muslim states in the eastern Mediterranean, whenever they were not actively at war, Venetian traders were fully willing to trade with their neighbors in the East, and had the strength to protect their commercial assets. Yay pre-modern capitalism! But of course Venice would eventually decline by the 16th-17th centuries as the production centers of Europe were largely relocated to the north, and the focus of naval commerce transitioned from the Mediterranean to the Atlantic.
Well, for starters, lets look at Venice's geography. Venice became a semi-independent polity after Byzantine influence in Northern Italy waned. The trade connections with the Byzantine Empire had already brought some amount of wealth to the city, but the Empire could no longer project enough force into Northern Italy to protect the city.
The Lombards threatened the area, which is a series of islands inside a lagoon, which helps to protect from incursions from the mainland and gave birth to Venice's famous canals. You can see it here. In an unstable region where the formerly dominant power is receding, security is invaluable, and this helped to increase significantly Venice's trading wealth. Of course, a new power, the Carolingians, entered into this region, but after a Carolingian attempt to assert their power was repelled, the city was formally recognized as Byzantine territory, and their trading rights along the Adriatic were assured. While nominally Byzantine, in truth the city was at this point independent, and began to assert political and military power in the region. After fights against Slav and Saracen pirates, many Istrian city-states submitted themselves to Venetian economic domination, and Venetian control over the Dalmatian coast would be expanded, bringing peace and security to the Adriatic Sea. At the same time, Venice was given increased trading rights within the Byzantine Empire, including freedom from various forms of taxation. The specific goods the Venetians traded varied, but the most lucrative were spices and silk, which were bought in the Levant and Egypt and were traded all throughout Europe.
Furthermore, Venice profited heavily from the Crusades, often supplying the ships, particularly after the construction of the Arsenal which significantly increased Venetian shipbuilding capacity. After the Fourth Crusade's sacking of Constantinople, which the Venetians helped bring about and one might argue engineered, the Byzantine Empire's territories were sloughed off, and Venice gained a number of trading territories, with the most notable being Crete. Eventually, Venice even began to expand inland, conquering rich territories including Verona and Padua. The fall of Constantinople did not harm their trading privileges either. As you can see, Venice's wealth was greatly increased by foreign conquest and the domination of trading routes.
Eventually, due to competition in the spice trade from the Cape of Good Hope route, along with the Italian proxy wars between France and Spain, led to the decline of Venice from its peak, although it continued to be a rich city even after its incorporation into the Austrian Empire.
TL;DR: Geography, playing off Great Powers well, and Empire.
Follow on- would love a history of rise of Venice source