[proofplan]
The proof has two directions. First, an idempotent endomorphism $e$ decomposes each element $m \in M$ as its $e$-fixed part $e(m)$ plus the error term $m-e(m)$, and idempotence shows that the error term is killed by $e$. The intersection of these two pieces is zero because an element in the image of $e$ is fixed by $e$, while an element in the kernel is killed by $e$. Conversely, a direct sum decomposition gives a well-defined projection onto the first summand, and direct verification shows that this projection is $R$-linear, idempotent, and has the required image and kernel.
[/proofplan]
[step:Decompose every element into an image part and a kernel part]
Let $m \in M$. Define
\begin{align*}
u &:= e(m), &
v &:= m-e(m).
\end{align*}
Then $u \in \operatorname{im}(e)$ by definition of image. Since $e$ is $R$-linear and $e \circ e = e$, we have
\begin{align*}
e(v)
&= e(m-e(m)) \\
&= e(m)-e(e(m)) \\
&= e(m)-e(m) \\
&= 0.
\end{align*}
Thus $v \in \ker(e)$. The equality
\begin{align*}
m = e(m) + (m-e(m)) = u+v
\end{align*}
therefore shows that every element of $M$ lies in $\operatorname{im}(e)+\ker(e)$.
[/step]
[step:Show the image and kernel have zero intersection]
Let $x \in \operatorname{im}(e) \cap \ker(e)$. Since $x \in \operatorname{im}(e)$, there exists $m \in M$ such that $x=e(m)$. Since $x \in \ker(e)$, we also have $e(x)=0$. Using $e \circ e=e$, we compute
\begin{align*}
x
&= e(m) \\
&= e(e(m)) \\
&= e(x) \\
&= 0.
\end{align*}
Hence $\operatorname{im}(e) \cap \ker(e)=\{0\}$. Together with the previous step, this proves
\begin{align*}
M = \operatorname{im}(e) \oplus \ker(e).
\end{align*}
[/step]
[step:Construct the projection associated to a direct sum decomposition]
Assume conversely that $A,B \le M$ and $M=A \oplus B$. By the definition of internal direct sum, each $m \in M$ has a unique expression
\begin{align*}
m = a+b
\end{align*}
with $a \in A$ and $b \in B$. Define the map
\begin{align*}
p: M &\to M \\
a+b &\mapsto a,
\end{align*}
where $a \in A$ and $b \in B$ are the unique summands of the given element.
We verify that $p$ is $R$-linear. Let $m_1,m_2 \in M$, and write
\begin{align*}
m_1 &= a_1+b_1, &
m_2 &= a_2+b_2
\end{align*}
with $a_1,a_2 \in A$ and $b_1,b_2 \in B$. Since $A$ and $B$ are submodules, $a_1+a_2 \in A$ and $b_1+b_2 \in B$, so the uniqueness of the direct sum decomposition gives
\begin{align*}
p(m_1+m_2)
&= p((a_1+a_2)+(b_1+b_2)) \\
&= a_1+a_2 \\
&= p(m_1)+p(m_2).
\end{align*}
For $r \in R$, since $A$ and $B$ are submodules, $ra_1 \in A$ and $rb_1 \in B$, and hence
\begin{align*}
p(rm_1)
&= p(ra_1+rb_1) \\
&= ra_1 \\
&= r p(m_1).
\end{align*}
Therefore $p \in \operatorname{End}_R(M)$.
[/step]
[step:Verify the projection is idempotent with image $A$ and kernel $B$]
Let $m \in M$, and write $m=a+b$ with $a \in A$ and $b \in B$. Then $p(m)=a$. Since $a=a+0$ with $a \in A$ and $0 \in B$, we have $p(a)=a$. Therefore
\begin{align*}
(p \circ p)(m)
&= p(p(m)) \\
&= p(a) \\
&= a \\
&= p(m).
\end{align*}
Since this holds for every $m \in M$, we have $p \circ p=p$.
The image of $p$ is $A$: for every $m=a+b \in M$, $p(m)=a \in A$, so $\operatorname{im}(p) \subset A$; conversely, if $a \in A$, then $a=a+0$ and $p(a)=a$, so $A \subset \operatorname{im}(p)$. Hence $\operatorname{im}(p)=A$.
The kernel of $p$ is $B$: if $m=a+b \in \ker(p)$, then
\begin{align*}
0 = p(m)=a,
\end{align*}
so $m=b \in B$, and therefore $\ker(p) \subset B$. Conversely, if $b \in B$, then $b=0+b$ with $0 \in A$, so
\begin{align*}
p(b)=0,
\end{align*}
and thus $b \in \ker(p)$. Hence $\ker(p)=B$. This proves the converse and completes the proof.
[/step]