This is not a homework or a project question, just me trying to get acquainted to the subject: I am an MSc student who recently came across the Wiles defect numerical criterion (see, for example, Wiles defect of Hecke algebras via local-global arguments and Wiles defect for modules and criteria for freeness). As frequently mentioned, this is closely related to a technique Wiles developed in his proof of FLT, called patching. Following the abstract of the latter paper, the situation is this: We have a deformation ring $R$ associated to a modular representation $ \bar{\rho}:G_\mathbb{Q} \rightarrow GL_2(k)$ of the absolute Galois group $G_\mathbb{Q}$, which arises from a complete, Noetherian, local Hecke algebra $\mathbb{T}$ acting on $H^1 (X_0(N), \mathcal{O})_{\mathfrak{m}}$, the cohomology of a modular curve $X_0(N)$, with coeffs in a DVR $\mathcal{O}$ finite flat over $\mathbb{Z}_p$, localized at the maximal ideal $\mathfrak{m}$, and with $\mathbb{T}/\mathfrak{m} = k$ a finite field. There is an action of the abs. Galois group on the cohomology, and it turns out $\bar{\rho}$ is isomorphic to a representation associated to the maximal ideal, which produces a surjection $R \rightarrow \mathbb{T}$, and the numerical criterion implies in favorable conditions that the cohomology is free as an $R$-module, and that the latter surjection is in fact a bijection of complete intersections.
The numerical invariant itself (as presented in the second paper) is defined as $\delta_A(M) = \operatorname{rank}(M[\mathfrak{p}_A])\operatorname{length}(\Phi_A)-\operatorname{length}(\Psi_A(M))$(as $\mathcal{O}$-modules), where $\mathfrak{p}_A=\operatorname{ker}(\lambda_A:A \rightarrow \mathcal{O}$,a surjection from a Noetherian local ring to a DVR), $M$ a finite $A$-module, $M[\mathfrak{p}_A]$ the $\mathfrak{p}_A$-torsion submodule of $M$, $\Phi_A = \mathfrak{p}_A/\mathfrak{p}^2_A$ and $\Psi_A(M)=\frac{M}{M[\mathfrak{p}_A]+M[A[\mathfrak{p}_A]]}$.
I've had good introductions to most areas needed to try and make sense of this, except modular representations, but I would be grateful if someone could clarify the following facts (Edited to reduce number of questions):
How do the Hecke algebra (generated by Hecke operators and diamond operators) and the Galois group act on the cohomology, and how does the surjection $R \rightarrow \mathbb{T}$ arise in this context, and why is it so important that this is actually a bijection?
I genuinely apologize for the long post, and please do not feel obliged to write long answers. If the post is irrelevant, please delete it.