Foundations of Resilient Systems