Coinfections pose serious threats to health and exacerbate parasite burden. If coinfection is detrimental, then what within-host factors facilitate it? Equally importantly, what hinders it, say via exclusion or priority effects? Such interactions ought to stem from their within-host environment (‘niche’), that is, resources that parasites steal from hosts and immune cells that kill them. Yet, despite two decades of empirical focus on within-host infection dynamics, we lack a mechanistic framework to understand why coinfection arises and the diverse range of its' consequences. By applying ecological niche theory, our within-host competition models lay the foundational theoretical framework for pathogen coinfection. Here, we outline various within-host competition models. Then, we emphasise general principles arising from an example of a trait-based niche model of joint resource and apparent competition for immune cells. In this model, coinfection requires a competition-resistance trade-off, that each parasite most impacts the factor to which its fitness is most sensitive, and intermediate resource supply. These predictions then provide mechanistic interpretations for questions about the outcomes of various experiments: Why does nutrient supplementation shift relative frequencies of coinfecting parasites? When and how does the sequence of parasite invasion allow only early invading parasites to win? How does intrinsic variation in immune response shape coinfection burden? Together, this mechanistic framework of parasite competition offers new perspectives to better predict within-host coinfection dynamics through an ecological lens.