Smart factory adopts cyber-physical technologies integrating independent discrete systems into a context-sensitive manufacturing environment to optimize manufacturing processes using decentralized information and real-time communication. This paper presents our work in the realization of a smart factory, which comprises of a four-layer hierarchical architecture, i.e. connection infrastructure, data acquisition, data processing and smart applications. In the connection infrastructure layer, all shopfloor machines are connected through diverse protocols, IoT sensors, PLC interfaces and DNC connectors. A centralized IoT gateway supports such a scalable and adaptable connection and ensures a reliable communication among all heterogeneous manufacturing systems. In the data acquisition layer, the real-time machine and job data are acquired from shopfloor systems. Machine data indicates machines’ working condition and job data reveals the production information. The data processing layer comprises of three modules, i.e. shopfloor monitoring, data visualization and data analytics, which monitor and visualize shopfloor activities and analyze the semantics of various data using AI-based TPM engines providing the scientific indicators for next-step decisions. The smart application layer provides with several decision-making and remote control functions for shopfloor productivity and efficiency, such as predictive maintenance, shopfloor management, machine & job optimization and digital twin. The smart factory system has been implemented in the manufacturing shopfloor at Nanyang Polytechnic. The results and validation show that the system can simultaneously collect and analyze the manufacturing data from shopfloor systems, and further communicate with and control the shopfloor systems with decision-support functions. The overall shopfloor efficiency and flexibility can be significantly improved towards a smart factory of Industry 4.0.