The Battle of the Foundry represents one of the initial conflicts in the Galactic War, fought between the forces of the Galactic Republic and the newly reformed Sith Empire.
Darth Malgus, serving as the commander of the Imperial Expeditionary Fleet, gathered a specialized team. He then disclosed to them the existence of an ancient space installation referred to as the Foundry, a remnant from an ancient civilization, and also spoke of a powerful Jedi Master who was in command of it.
For a period of three centuries, the Sith Emperor had held the Jedi Master captive within a clandestine prison facility situated in the Maelstrom. He was kept in suspended animation, defying aging, through the use of archaic technology and Sith magic. A Republic assault team, dispatched by Jedi Admiral Oteg, successfully located the prison, eliminated its warden, Grand Moff Rycus Kilran, and liberated the Jedi from the Maelstrom prison. After a brief return to the Republic, the Jedi Master journeyed to the Foundry, a secret he had successfully concealed from the Emperor during their prolonged psychic connection. He then began utilizing it to aid the Republic.
Darth Malgus informed his selected team that the escape was, in reality, a deliberate setup. The intention was for the Jedi to guide the Empire to the Foundry, which would then be used in the impending war against the Republic. To seize control of the Foundry, Malgus and Moff Phennir, who commanded the Harrower-class dreadnought named White Nova, devised a plan to commandeer a Republic transport en route to the Foundry. They would use it to infiltrate the Foundry while Phennir led the fleet to engage the Foundry's defensive systems. The strike team executed this initial objective by launching a sneak attack on the Republic transport ship, the Dorin's Sky, seizing control of the bridge, eliminating the leaders of Storm Squad, and executing Captain Yelto along with her entire crew.
Now in possession of the Dorin's Sky, the strike team was able to set a course for the Foundry. Their mission had two components: to secure the Foundry for Imperial occupation forces and to eliminate the Jedi Master.

Having been delayed by six hours due to the hijacking, the Dorin's Sky successfully docked with the Foundry without any complications. Upon exiting the airlock, they immediately engaged the Foundry's defense forces, which consisted of Jedi, Republic soldiers, and battle droids. As they advanced through the station, they discovered that it was, in fact, a massive droid manufacturing facility, producing specialized "extermination droids" for the Foundry's commander. While navigating through the outer defenses, they were contacted by the Jedi Master, who attempted to persuade them to abandon their mission and surrender.
Concurrently, the Imperial Expeditionary Fleet engaged the Republic fleet above the Foundry. The Republic fleet quickly established a perimeter around the Foundry, preventing the Imperial ships from retreating. The Imperial ships began to sustain significant damage. Despite this, they continued to fight, as it was crucial to hold off the Republic forces while the strike team progressed through the Foundry.
Inside the droid factory's primary generator, they encountered the commander of the droid armies, an assassin droid who identified himself as HK-47, "the master's most loyal ally". HK-47 revealed that the extermination droids were equipped with bioscanners capable of detecting Sith genetic material and eliminating anyone with Sith ancestry, which would account for 97.8% of the Empire's population. Activating his assassination protocols and deploying extermination units to attack the strike team, HK-47 eventually suffered critical damage and was deactivated. Crossing the asteroid's shielded surface and entering the station's inner sanctum, the strike team confronted their target.
The Jedi Master revealed himself as Revan, a Jedi Knight from three centuries prior who had been corrupted by the Sith Emperor and led a Sith invasion of the Republic following the Mandalorian Wars. Having been redeemed by the Jedi, Revan returned to the Empire and confronted the Emperor on Dromund Kaas, but was defeated due to betrayal from within and imprisoned for the subsequent three centuries. During his extended imprisonment, Revan and the Emperor influenced each other's minds; the Emperor sought to transform him back into Darth Revan, while Revan convinced the Emperor that peace was in his best interest. After being freed from the Maelstrom, Revan returned to the Foundry to oversee what he believed would be the ultimate downfall of the Sith and their Empire. He implored the strike team to recognize the truth and abandon the Emperor, but they refused. The strike team also attempted to persuade Revan of the error in his ways, but Revan believed that he needed to destroy the Empire, even if it meant sacrificing its entire population. Revan ignited his lightsaber, and the duel commenced.
Revan proved to be a formidable adversary, skilled with his lightsaber and the powers of the Force, summoning asteroids harvested by the Foundry and unleashing potent bursts of Force lightning. However, ultimately, it was insufficient to defeat the Empire's elite agents, and Revan was defeated. Remarking that he now understood what his former friend Malak had felt when he defeated him three centuries earlier, Revan vanished in a surge of Force energy.
Finally, Imperial reinforcements arrived and eliminated the remaining Republic ships. The space battle concluded by the time Revan was defeated.
The duel concluded with Revan neutralized as a threat to the Empire, and the four agents were commended and awarded significant prestige and honor. They were later debriefed on Revan and his role and were regarded as heroes for saving the Empire and capturing the Foundry. However, their efforts were nearly undermined when Malgus proclaimed his "New Empire" and utilized the Foundry as part of his plans. Malgus' forces, which defended his mobile space station, included reprogrammed extermination droids, commanded by the rebuilt and reprogrammed HK-47. Moff Phennir, a member of the war council tasked with countering the "New Empire" during the Battle of Ilum, was outraged by the betrayal and his unwitting involvement in it.
Revan was presumed to have been killed in the battle, but resurfaced on Rakata Prime in 3637 BBY as the leader of the Order of Revan, which had evolved from a fringe cult within the Empire into a galaxy-spanning force.