A Slow Sand Filter (SSF) consists of biofilm attached to saturated packed sand with supernatant water on top, through which water flows by gravity. SSFs are used in the production of drinking water to improve water quality and remove pathogens, and, as they use biological filtration via the microbes present in the biofilm, they are simple and cheap to construct. A drawback of SSFs is that the difficult sampling and the complex dynamics associated with biofilm growth of microbes pose an obstacle for analysis and predictions. In order to overcome this issue, a mathematical model consisting of a non-linear convection-diffusion-reaction system with discontinuous flux is developed from first principles as a unified framework for the dynamics in time and depth of the biofilm and microbial community, where a variety of ecological models can be included in the reaction terms, which also contain attachment, detachment and transfer processes. The multi-phase approach considers three main physical volumes: a biofilm matrix, the water volume enclosed by it and the flowing suspension through the SSF surrounding the biofilm. The only input data needed are the inflow concentrations and rate, light irradiation and temperature. The model includes a Cahn–Hilliard-type equation for the biofilm velocity in the supernatant water. A numerical scheme that preserves physical properties of the solution is also presented. This is achieved with a time-splitting scheme using an upwind scheme with an adaptive time-step size that ensures positivity of the solution under a CFL condition and a reasonable assumption on the separate numerical solution of the Cahn–Hilliard-type equation. The latter is solved numerically with a semi-implicit finite-difference scheme using a mixed form of the equation. The flexible model framework with its numerical scheme allows for including a variety of ecological models, making the investigation and development of increasingly complex simulations possible. Simulations with different model parameters are shown to be qualitatively consistent with the literature.