Diagrammatic method for many-body non-Markovian dynamics: Memory effects and entanglement transitions