For each node , run DFS to compute the depth of each child's subtree. The depth is plus the maximum depth of any child. Track the two deepest child subtrees.
The diameter through node is the sum of the two deepest paths going down. Compare this to the global maximum. After processing all nodes, you have the diameter.
This single DFS computes the diameter in time. It is useful when you also need subtree information or when the problem combines diameter with other DP states.
Space complexity is for the data structures used.