In the early 90s, I took a class from Victor Kac and in it, he explained a very beautiful way of generating all the primitive solutions for the Pythagorean equation for a sum of $n-1$ perfect squares is equal to a perfect square where $n$ can be 3, 4, 5, ..., 10. Unfortunately, I do not know where in the literature this is described in detail. It might be in his Infinite Dimensional Lie Algebras book, but I don't know.
The idea is to realize the solutions as the isotropic roots for a certain root system.
Consider the lattice ${\Bbb Z}^n$ with bilinear form $-x_0y_0 + x_1y_1 + \cdots + x_{n-1}y_{n-1}$ and standard basis $v_0$, $v_1$, $v_2, v_2$, \dots, v_{n-1}$.$v_{n-1}$.
Change basis to:
$\alpha_1 = v_1 - v_2$, $\alpha_2 = v_2 - v_3$, \dots, $\alpha_{n-2} = v_{n-2} - v_{n-1}$, and $\alpha_{n-1} = v_{n-1}$.
If $n \geq 4$, let $\alpha_n = -v_0 - v_1 - v_2 - v_3$.
If $n=3$, let $\alpha_n = -v_0 - v_1 - v_2$.
The corresponding Cartan matrix $a_{ij} = \frac{2(\alpha_i, \alpha_j)}{(\alpha_i, \alpha_i)}$ is represented by the diagram:

Then the set of primitive solutions to the equation $x_0^2 = x_1^2 + x_2^2 + \cdots + x_{n-1}^2$ is the orbit under the corresponding Coxeter group of $(1, 1, 0, \dots, 0)$ if $n < 10$. If $n=10$, then you have to add the orbit $(3, 1, 1, 1, \dots, 1)$ to get them all.
One doesn't need the theoretical machinery to prove the result. One can just construct the matrices and use a descent argument to show that it works.
For the Pythagorean triple case, for instance, you take the orbit of the vector $(1, 1, 0)$ under the action of the group generated by the matrices:
$$
\begin{pmatrix}
1 & 0 & 0 \\
0 & 0 & 1\\
0 & 1 & 0
\end{pmatrix}
end{pmatrix},
$$
$$
\begin{pmatrix}
\pm 1 & 0 & 0 \\
0 & \pm 1 & 0 \\
0 & 0 & \pm 1
\end{pmatrix}
end{pmatrix},
$$ and
$$
\begin{pmatrix}
3 & 2 & 2 \\
2 & 1 & 2 \\
2 & 2 & 1
\end{pmatrix}
end{pmatrix}.
$$.
For $n=4$, you can use the matrices that permute the appropriate variables, change the sign of any variable, and the following:
$$
\begin{pmatrix}
2 & 1 & 1 & 1 \\
1 & 0 & 1 & 1 \\
1 & 1 & 0 & 1 \\
1 & 1 & 1 & 0
\end{pmatrix}
end{pmatrix}.
$$.
I'm sorry I cannot give a reference to the literature...I hope someone else is able to.

