Dani Alves celebrates with his teammate Munir el Haddadhi after scoring against Villanovense in the Copa del Rey on December 2, 2015.
CNN  — 

Barcelona legend Dani Alves is set to be reunited with his former teammate and now manager of the Spanish giants, Xavi, after the club “reached an agreement in principle” for him to return.

In a statement released by Barcelona, the club announced that Alves will join the first team for the remainder of the current season.

“The Brazilian will be joining training from next week but will not be able to play until January,” Barcelona said, also calling him the “greatest right back in Barca history.”

The 38-year-old returns to the Nou Camp five years after he left for Juventus.

Alves celebrates with the Champions League trophy at Wembley stadium on May 28, 2011.

The flying right back spent eight trophy-laden years at Barcelona, after joining from Sevilla in 2008.

He quickly became the regular first-team starter, proving a vital attacking role in Pep Guardiola’s team which became so dominant.

Over his eight years at Barcelona, Alves made 391 appearances, scoring 23 goals.

He won 23 titles while he was at the club, including six Spanish league titles, four Copa del Rey and three Champions League titles.

In 2016, the Brazil international left for Juventus and has also played for Paris Saint-Germain and Sao Paulo.

He rejoins the Catalan club as the most decorated footballer of all time, having won 46 trophies at senior level.

In the caption of an Instagram post Alves posted with him kissing the Barcelona logo in the Nou Camp, he said: “Almost 5 years fighting like crazy to get to this moment.

“I didn’t know it would last this long, I didn’t know it would this difficult, but I knew within my heart and within my soul that this day would come.”

He added: “See you soon from where it fascinates me the most, with the same enthusiasm as the first time and with the same desire to help rebuild the best club in the world!”

In a funny coincidence, Alves was Guardiola’s first signing when he became manager in 2008. And now he is Xavi’s first signing.

Visit CNN.com/sport for more news, features, and videos

Xavi celebrates with Alves after scoring Barcelona's first goal in the La Liga match between Valladolid and Barcelona on January 23, 2010.

The club will be hoping Xavi can have a similar impact to Guardiola, who transformed the club into one of the greatest side’s that football has ever seen.

It means Alves is reunited with Xavi, a teammate of his from 2008 until 2015 when Xavi left for Qatar. During their time together, they won 19 major trophies together, including five La Liga titles and three Champions Leagues.

Now Xavi is the Barcelona manager, and will be hoping the return of Alves can help propel his side up the La Liga table once he takes the field in January.