We identify a canonical structure J associated to any first-order theory, the {it space of definability patterns}. It generalizes the imaginary algebraic closure in a stable theory, and the hyperimaginary bounded closure in simple theories. J admits a compact topology, not necessarily Hausdorff, but the Hausdorff part can already be bigger than the Kim-Pillay space. Using it, we obtain simple proofs of a number of results previously obtained using topological dynamics, but working one power set level lower. The Lascar neighbour relation is represented by a canonical relation on the compact Hausdorff part J; the general Lascar group can be read off this compact structure. This gives concrete form to results of Krupinski, Newelski, Pillay, Rzepecki and Simon, who used topological dynamics applied to large models to show the existence of compact groups mapping onto the Lascar group. In an appendix, we show that a construction analogous to the above but using infinitary patterns recovers the Ellis group of cite{kns}, and use this to sharpen the cardinality bound for their Ellis group from $beth_5$ to $beth_3$, showing the latter is optimal. There is also a close connection to another school of topological dynamics, set theory and model theory, centered around the Kechris-Pestov-Todorv cevic correspondence. We define the Ramsey property for a first order theory, and show - as a simple application of the construction applied to an auxiliary theory - that any theory admits a canonical minimal Ramsey expansion. This was envisaged and proved for certain Fraisse classes, first by Kechris-Pestov-Todorv cevic for expansions by orderings, then by Melleray, Nguyen Van The, Tsankov and Zucker for more general expansions.