Soaring inflation, rising interest rates, corporate layoffs, falling consumer confidence, and recent banking troubles are -- unsurprisingly -- worrying investors. To boot, economists are forecasting a recession later this year.

Amid the turmoil, two retail stocks stand out as shining stars. AutoZone (AZO 0.82%) and O'Reilly Automotive (ORLY 1.44%) have seen their shares rise 20% and 23%, respectively, over the past 12 months -- fantastic gains compared to the 6% decline that the S&P 500 posted. This continues a long-running trend of crushing the market by the two auto parts retailers. 

Although AutoZone and O'Reilly are near all-time highs, here's why they still might be magnificent no-brainer additions to your portfolio right now. 

Still going strong 

Many companies saw drastic slowdowns toward the end of 2022, but these two are still registering healthy gains. AutoZone's revenue increased 9.5% in its most recent fiscal quarter (the second quarter of 2023, ended Feb. 11), while O'Reilly's sales rose 11% in the last three months of 2022. Same-store sales growth averaged mid- to high single digits between the two. 

"As we look forward to the back half of fiscal year 2023, we are bullish on our growth prospects behind a resilient DIY business and fast growing commercial and international businesses that are growing considerable share," AutoZone CFO Jamere Jackson said on the recent earnings call. 

O'Reilly's management provided more concrete guidance. It expects comparable sales to be up 4% to 6% in 2023. Nonetheless, it appears like the momentum will continue in the near term. 

That's because both of these business models thrive in highly uncertain economic times like the one the U.S. has been in. Inflation is still running at elevated levels, and interest rates haven't been this high since before the Great Recession. As a result, buying new vehicles is less affordable for consumers, pushing them to extend the useful lives of their existing cars.

This is where AutoZone and O'Reilly come in, providing the necessary parts, supplies, and expertise. Combined, these businesses have 12,155 stores across the country, with a small international presence as well. The physical footprint continues to expand with each passing year. 

Demand for AutoZone and O'Reilly should remain robust for many years. The average age of a vehicle on the road has trended up, now at over 12 years. This extends the time that a car is outside of its original warranty, which is the sweet spot for these retailers. That's why these businesses have long been able to register impressive sales increases year in and year out.  

The valuations aren't the best 

Owning all-weather stocks is incredibly appealing right now, but investors have to also consider valuations. As of this writing, AutoZone's stock trades at a price-to-earnings (P/E) ratio of 21, with O'Reilly selling for a P/E of 26. These metrics don't really tell you much in isolation. However, it's worth mentioning that they are both significantly higher than each stock's trailing five- and 10-year P/E multiples. Therefore, it's safe to say that they might be overvalued today. 

While both stocks are trading near their all-time highs, investors should still consider adding them to their portfolios now. They typically generate strong gross margins in excess of 50% each year, while operating margins are around 20%. It would be very hard to find brick-and-mortar retailers with this kind of outsize profitability, especially margins that have held up quite nicely in the inflationary environment. 

Moreover, both AutoZone and O'Reilly are free-cash-flow machines. This is such a pronounced feature of their business models that the former has been able to undergo massive stock buybacks to decrease its outstanding share count 31% in the past five years, and the latter by 27%. This helps to boost earnings per share, a positive trend for their share prices. 

Taken together, these favorable characteristics make it difficult not to like these two stocks right now.