The Kingdom Hearts series is sprawling, with a mainline story plus plenty of prequels and side games. For the smoothest, most spoiler-light experience, most fans recommend playing in release order so the story unfolds the way it was originally told.
Here's the traditional release sequence:
Kingdom Hearts (PS2)
Kingdom Hearts: Chain of Memories / Re: Chain of Memories (GBA/PS2)
Kingdom Hearts II (PS2)
Kingdom Hearts 358/2 Days (DS)
Kingdom Hearts Birth by Sleep (PSP)
Kingdom Hearts Coded / Re:coded
Playing this way keeps the emotional beats and reveals landing as intended.