We define and study a bigraded knot invariant whose Euler characteristic is the Alexander polynomial, closely connected to knot Floer homology. The invariant is the homology of a chain complex whose generators correspond to Kauffman states for a knot diagram. The definition uses decompositions of knot diagrams: to a collection of points on the line, we associate a differential graded algebra; to a partial knot diagram, we associate modules over the algebra. The knot invariant is obtained from these modules by an appropriate tensor product.