It is known that the number of ways to express $n \in \mathbb{Z}_{\geq 0}$ as a sum of three squares (let's denote it as $r_3(n)$) can be expressed as Hurwitz-Kronecker class number (certain weighted sum of class numbers). Such a number is closely related to a modular form of weight $3/2$, namely $$ \theta(z)^3 = \left(\sum_{n\in \mathbb{Z}} q^{n^2}\right)^3 = \sum_{n\geq 0} r_3(n)q^n, \quad q = e^{2\pi i z}. $$ Since the case of even number of squares (like $r_2(n)$ and $r_4(n)$ becomes integral weight modular forms, one can obtain formula for $r_{\mathrm{even}}(n)$ in terms of coefficients of integral weight modular forms by writing $\theta(z)^{\mathrm{even}}$ as a linear combination of such forms. However, the nature of half-integral weight modular forms is much different, and this is why $r_{\mathrm{odd}}(n)$ cases are harder. But I think there should be a way to deduce formula for $r_3(n)$ using the theory of modular forms, since it is obviously related to half-integral weight modular forms. My first thought was to use Shimura correspondence and Waldspurger's formula, which attaches weight $2$ modular forms to a given weight $3/2$ cusp forms, and relate the coefficients with special $L$-values of attached modular forms, and I guess that the latter might be related to class numbers via class number formula (there are some explicit versions of Waldspurgers formula, e.g. due to Kohnen). However, the first issue is that $\theta(z)^3$ is not a cusp form and we can't apply Shimura correspondence directly.
But I think there might be a way to mitigate such an issue by decomposing $\theta(z)^3$ as a sum of cusp form and non-cusp form, where the latter one is somewhat easy to handle (for example, I may expect that it is easy to compute Fourier coefficients of it). Such an idea came out while I was reading Chao Li's article on Moonshine and BSD conjecture, especially Remark 5 of it. Since I even don't know the "well-known" proof for the formula for $r_3(n)$, I wonder if there's any work in this direction. Thanks in advance.