In a large pot, heat the olive oil over medium heat.
Add the diced onion and sauté for about 5 minutes until translucent.
Stir in the minced garlic, carrots, and celery, cooking for an additional 5 minutes until the vegetables are tender.
Add the dried thyme, black pepper, and cayenne pepper (if using) to the pot, stirring well.
Pour in the diced tomatoes and chicken broth, bringing the mixture to a boil.
Once boiling, reduce the heat to a simmer and add the white beans and diced ham.
Let the soup simmer for 20-25 minutes, allowing the flavors to meld.
If using spinach, stir it in during the last 5 minutes of cooking.
Taste the soup and add salt as needed.
Serve hot with crusty bread or crackers.