The Visconti family is one of the oldest European dynasties documented since the end of the 10th century in the territory of northern Italy, where the Visconti Duchy with the capital Milan was enfeoffed.
The Visconti ruled Milan during the Middle Ages and early Renaissance, from 1277 to 1447.

The family fortunes were amassed as of 1262, when Ottone Visconti was appointed archbishop of Milan.
Ottone Visconti entered the city and took up residence only after the Battle of Desio, in which Ottone’s troops (Ghibellines) defeated those of Napoleon Della Torre (Guelphs), putting an end to the Della Torre domination and the independence of the municipality of Milan.
The Visconti ruled Bergamo from 1331 to 1428, until the Venetians arrived. The Milanese imposed control over the Bergamasque families by settling their disputes with an iron fist and without being too subtle about it.

With the help of the Ghibelline faction, in 1332 Azzone Visconti (1302–1339) became the first Visconti Seigniory of Bergamo. Exercising tyrannical and fiscal power, he persecuted and confiscated the possessions of the Guelph families in an overt manner. In this way, the city was the scene of further clashes between the two fractions.
The legislative autonomy that Bergamo had enjoyed in the past was revoked with the advent of the single Milanese law imposed by Luchino Visconti (1292–1349), establishing to all intents and purposes the Seigniory in the city.

Archbishop Giovanni Visconti (1349–1354) further reduced the Council of Elders, taking additional step towards the state of dictatorship that Alberico had theorised.
Documents show that the Podestà of Bergamo were almost entirely composed of Milanese citizens and members of the Visconti family.
The Guelph spirit that animated the countryside and the valleys surrounding the city thus contrasted with the Ghibelline foundations of the Seigniory regime that dominated the city, causing strong oppositions within the territory.

Under Bernabò Visconti (1323–1385) came a radical military fortification. The Cittadella (Firma Fides), walls and defensive towers were built whilst detachments of soldiers were also established and stationed in each district.
Further watchtowers and outposts were built by individual families who, considering the violent and dangerous nature that the Bergamasque territory had assumed, saw in these constructions easier places to defend in the event of an attack by any enemy.
This already extremely tense period was exacerbated by Bernabò’s excessively exorbitant tax policy and overbearing warlike attitude.
He had to face widespread rebellions in the valleys (including the revolt led by Merino Lolmo in Val Brembana) and found in the total blockade of the main communication routes, the only strategy to suppress insurrections.
But it was only with the death of his son Ambrogio (which occurred near Pontida at the hands of the vengeful Guelph faction) that Bernabò’s cruelty and tyranny became manifest.

He had the ancient monastery of Pontida (which two centuries earlier, was the site of the oath of the Comuni della Lega) destroyed and all villagers massacred.
The years of his dictatorship ended in 1385, when he was captured by his nephew Gian Galeazzo (1351–1402) and imprisoned in the castle of Trezzo sull’Adda.
Galeazzo replaced him as lord and, after being elected Duke of Milan by Wenceslaus IV of Bohemia (1361–1419), with the aim of extending his power over the whole of Italy, he oversaw the economic revival of his possessions.
After the death of Gian Galeazzo, the Visconti dynasty continued with Giovanni Maria (1388–1412) who, in an attempt to improve the situation in the territory and resolve the bloody civil strife between the factions, chose to remain ambiguous about the two sides, favouring both fractions whilst leading conflicts between Guelphs and Ghibellines.
It was only in 1402 that peace between the two parties was formally sanctioned, only to be abruptly interrupted by new Guelph uprisings in the valleys.
The mercenary leader Pandolfo Malatesta (?–1427), after conquering Brescia and becoming governor of Milan, succeeded in having the title of Seigniory of Bergamo recognised by Giovanni Maria, one of his first objectives being to set up a government programme capable of restoring peace within.
His Guelph origins and his outlook succeeded in creating a certain balance in the city thanks to his ability to govern impartially. In 1410, one of his measures attempted to encourage a population increase, in response to the decimation of wars and epidemics.
Pandolfo Malatesta first lost the Orobia territory in 1419 and his Lombard possessions in 1421, when he was defeated by Filippo Maria Visconti (1392–1447).
Under Filippo Maria, the conflict with the Serenissima Republic of Venice began for Bergamo.
https://www.pianuradascoprire.com/destinations/i-visconti-storia-e-letteratura/
http://historiadibergamo.blogspot.com/2013/06/bergamo-viscontea.html