A Mathematical Theory of Architecture