  We define a notion of Koszul dual of a monoid object in a monoidal biclosed
model category. Our construction generalizes the classic Yoneda algebra
$Ext_A(k,k)$. We apply this general construction to define the Koszul dual of a
category enriched over spectra or chain complexes. This example relies on the
classical observation that enriched categories are monoid objects in a category
of enriched graphs. We observe that the category of enriched graphs is
biclosed, meaning that it comes with both left and right internal hom objects.
Given a category $R$ (which plays the role of the ground field $k$ in classical
algebra), and an augmented $R$-algebra $C$, we define the Koszul dual of $C$,
denoted $K(C)$, as the $R$-algebra of derived endomorphisms of $R$ in the
category of right $C$-modules.
  We establish the expected adjunctions between the categories of modules over
$C$ and modules over $K(C)$. We investigate the question of when the map from
$C$ to its double dual $K(K(C))$ is an equivalence. We also show that Koszul
duality of operads can be understood as a special case of Koszul duality of
categories. In this way we incorporate Koszul duality of operads in a wider
context, and possibly clarify some aspects of it.
