The authors construct Heegaard Floer theory for 3-manifolds with connected boundary. The theory associates to an oriented, parametrized two-manifold a differential graded algebra. For a three-manifold with parametrized boundary, the invariant comes in two different versions, one of which (type $D$) is a module over the algebra and the other of which (type $A$) is an $mathcal A_infty$ module. Both are well-defined up to chain homotopy equivalence. For a decomposition of a 3-manifold into two pieces, the $mathcal A_infty$ tensor product of the type $D$ module of one piece and the type $A$ module from the other piece is $widehat{HF}$ of the glued manifold. As a special case of the construction, the authors specialize to the case of three-manifolds with torus boundary. This case can be used to give another proof of the surgery exact triangle for $widehat{HF}$. The authors relate the bordered Floer homology of a three-manifold with torus boundary with the knot Floer homology of a filling.