Unlike normal items, Legendary Items don't become vendor trash when a replacement comes along. When the time comes to part ways with one of your Legendary Items, you can deconstruct it to generate Relics, heritage runes, and Legendary shards/fragments. A Relic-master will be able to assist you in recovering what you can. In order to deconstruct a Legendary Item it must be un-equipped and you will need to unlock it.
Once you have deconstructed a few Legendary Items, you can combine Settings, Gems or Runes to a higher tier. This is found under the Relic Forging tab. You should have a decent number of them to work with. Combining is very simple. Take up to five relics of the same tier (they don't all have to be settings/gems/runes; they can be a mix-n-match) and combine them. You should get one random relic of the next tier above. Occasionally you’ll have a critical success which provides you with shards or extra relics. Combining costs either money or shards.
If you are not satisfied with the result of your combining, you can meld relics into a relic of your choice of the same tier. This costs shards instead of money. Note that tier 9 relics cannot be combined (as there is no tier 10, but they can be melded. Moreover, there are several 'special' relics that cannot be acquired by combining, but only by melding multiple relics. You are also able to acquire legendary scrolls, stat legacies and legendary items by melding. These only require shards, not relics.
Shards are acquired by refining relics. This destroys the relic. The higher the tier of the relic, the more shards you receive. There is additionally a chance to receive shards when deconstructing Legendary Items. You have a higher chance when an item is of a higher level. There is also a higher chance of a larger amount of shards. You can also acquire shards as a result of a critical success while combining relics.
See Relics for prices and results of melding and refining, and for more information about relics.