The assembly of prefabricated components is a critical process in prefabricated building construction, influencing both progress and accuracy. However, the assembly sequence planning and optimization (ASPO) of prefabricated components have yet to receive sufficient attention from researchers, and current research has displayed limited automation and poor generalization capabilities. Therefore, this paper proposes a framework for intelligently generating assembly sequences for prefabricated components based on graph databases and matrices. The framework utilizes an adjacency matrix and interference matrix-based modeling method to comprehensively describe the connections and constraint relationships between components, enabling better evaluation of assembly difficulty during optimization. The graph database serves as the central hub for data exchange, facilitating component information storage, automatic querying, and summarization. The obtained assembly sequence and progress plan are fed back into the graph database. To accomplish assembly sequence optimization, a genetic algorithm based on the double-elite strategy is employed. Furthermore, the effectiveness of the proposed framework is validated through an actual engineering case. The results demonstrate that the framework can effectively find an optimal assembly sequence to mitigate the assembly challenge of a prefabricated building.