Let $H_k = \text{span }\left\{ e_1, ..., e_k \right\}$ and $H_k$ is a closed subspace of Hilbert Space H.
We define the projection: $$P_{H_k} x = \sum_{j=1}^k \langle x, e_j \rangle e_j$$
But why exactly? Is there maybe a geometrical proof (with the help of Pythagorean Theorem)? I especially don't understand from where $\langle x, e_j \rangle$ is coming from
Suppose $\sum_{i=1}^k a_i e_i$ is the projection of some $x$ onto $H_k$. Then, $x - \sum_{i=1}^k a_i e_i$ is perpendicular to $H_k$, and in particular, each $e_i$. We can write: $$x = \left(x - \sum_{i=1}^k a_i e_i\right) + \sum_{i=1}^ka_i e_i. \tag{$\star$}$$ Now, take the inner product of each side of $(\star)$ with respect to $e_j$. Then, \begin{align*} \langle x, e_j \rangle &= \left\langle x - \sum_{i=1}^k a_i e_i, e_j\right\rangle + \sum_{i=1}^k\langle a_i e_i, e_j\rangle \\ &= 0 + \sum_{i=1}^k a_i \langle e_i, e_j \rangle = a_j. \end{align*} If we replace this formula for $a_j$ into the sum $\sum_{i=1}^k a_i e_i$, we obtain precisely the projection formula from the question.
Note also that, if we have a finite-dimensional Hilbert space with orthonormal basis $(e_1, \ldots, e_n)$, and we "project" a vector $x$ onto the entire space, then we should get $x$ back, leading to the helpful formula: $$x = \sum_{i=1}^n \langle x, e_i \rangle e_i.$$