Both fanfiction and doujinshi are forms of fan created works, but they differ mainly in format, culture of origin, and typical distribution
Fan fiction is usually written prose shared online for free, created by fans who use characters or settings from an existing series.
Doujinshi, are typically self-published booklets most often mangastyle comics produced within Japanese fan culture and often sold at events or specialty shops. While fan fiction is almost always derivative, doujinshi can be either fanbased or entirely original, making it a broader category of self published creative work.

can somebody explain to me the difference between fanfiction and doujinshi