To understand why James B. Comey, a Republican for most of his life who served as President Trump's first FBI director, has morphed into the president's most vocal critic, we have to look back at the very beginning of their relationship.

Trump's beef with Comey, which transformed into Comey's beef with Trump, stretches back nearly two years, to the height of the 2016 election drama.

The way Comey has described it, he took heat from Trump for every decision the FBI made that didn't benefit the president. The criticism became so outrageous that Comey felt he was forced to tell his side of the story. Trump counters that Comey is making all this up to protect his image after getting fired.

Either way, Comey is talking about how much he dislikes Trump. A lot. Here are key moments in his account that, in hindsight, Comey has indicated or outright said motivated him to become the president's chief antagonist.

July 5, 2016: Comey announces he doesn't think the Justice Department should prosecute Hillary Clinton for her use of a private email server while secretary of state.

Trump, then the presumptive Republican presidential nominee, seizes on the news to push a common refrain for him: that D.C. is rigged to make him lose.

Trump would spend the rest of the campaign using Comey as a useful symbol of everything that's wrong with “the swamp.” (With the exception, of course, of 11 days before Election Day, when Comey made moves to reopen the Clinton email investigation, which Trump praised.)

Jan. 6, 2017: Comey briefs President-elect Trump on the dossier. It doesn't go well, he says.

Comey was forced to start his relationship with the president in a tenuous way. There was a dossier written by an ex-British spy circulating in Washington that he somewhat controversially decided to brief Trump on. It alleged damaging things about the president-elect, like that his campaign colluded with Russia to win. And it contained some guaranteed-to-go-viral (and evidence-free) accusations that Trump watched prostitutes urinate on a bed in a Moscow hotel room.

Comey testified to Congress that he was fully aware how precarious that first official meeting would be. And Comey says it played out worse than he had expected, with Trump allegedly fixated on the prostitute allegations and defending himself from unrelated sexual harassment allegations.

Jan. 27, 2017: A newly inaugurated president allegedly asks Comey  for “loyalty.”

Comey says he got a call from the president at lunchtime to come over to dinner that night, and Comey said he was surprised to arrive and find it was just a one-on-one.

According to Comey, this is when Trump asked him the now-famous line that, from Comey's perspective, sums up their relationship: “I need loyalty, I expect loyalty.” Comey says he tried to sidestep the question.

Feb. 14, 2017: The president allegedly asks Comey to drop the FBI investigation into one of his former aides.

According to Comey, Trump asks him to drop the FBI's investigation into his former national security adviser, Michael Flynn, whom Trump fired a day earlier. “He then said, 'I hope you can see your way clear to letting this go, to letting Flynn go. He is a good guy. I hope you can let this go,'" Comey would later tell Congress.

“It was very concerning,” Comey testified, “given the FBI's role as an independent investigative agency.”

Flynn would later plead guilty to lying to the FBI and end up helping the special counsel's Russia investigation.

March 20, 2017: Comey publicly acknowledges what the FBI has been doing in secret for nearly a year: investigating possible coordination between Trump's campaign and the Russians. The FBI confirming an ongoing investigation is unusual, but Comey said it was “in the public interest.”

March and April 2017: Comey takes two phone calls from Trump where the president allegedly asks him what he can do to “lift the cloud” of the Russia investigation. Comey says the April 11 phone call was the last time he spoke to the president.

May 2, 2017: A day before Comey is set to testify to Congress about the Russia investigation, Trump attacks him.

May 3, 2017: Comey testifies to Congress that it made him “mildly nauseous” to reopen the Clinton email investigation days before the election. In that testimony, he misstated how many Clinton emails he had found on a key computer used to reopen the investigation days before the presidential election.

May 9, 2017: Trump fires Comey, in part citing Comey's handling of the Clinton email investigation. Days later Trump says it was actually because of “this Russia thing.”

May 12, 2017: Faced with criticism from the left and right for firing Comey, Trump continues to attack his ousted FBI director.

May 16 and 17, 2017: Comey says he had planned to keep everything above “in a box” — until Trump taunted him with the above tweet. The New York Times reports on secret memos Comey wrote about his private meetings with Trump, which Comey later confirms he leaked.

A day after Comey released them to the media, the No. 2 at the Justice Department, Rod J. Rosenstein, appoints Robert S. Mueller III to investigate Russia meddling and whatever else may arise.

June 8, 2017: Comey testifies to Congress that he was wrongly fired and that Trump lied about why he was fired. The full weight of Comey's concerns about the president become evident: “I was honestly concerned he might lie about the nature of our meeting,” Comey said on why he wrote memos about all this.

Fairly consistently after that: Trump attacks the leadership at the FBI, saying Comey is just the first of tainted officials who should go.

March 16, 2018: Comey's No. 2, Andrew McCabe, gets fired

It happened a little more than 24 hours before McCabe was set to retire and receive a full pension, based on an internal Justice Department determination that McCabe wasn't candid about a news report during the election. McCabe alleges Trump and his allies were trying to undermine the special counsel investigation into Russia.

Comey backs McCabe up on that point. Which isn't surprising. At this point, Comey's Twitter account had become a reliable critic of the president.

April 12, 2018: Comey transforms his congressional testimony about his private meetings with Trump into a book. Journalists get a copy a few days ahead of time and publish its most scathing sections. Like how Comey calls Trump a congenital liar, an unethical leader and a president who is obsessed with defending himself from the salacious and unverified prostitute allegations, reports The Post's Philip Rucker.

April 16, 2018: Trump is in the middle of a multiday tweet attack on Comey

And this time, Comey is firing right back, arrow for arrow. He's in the middle of a multiday press tour about why he thinks Trump is “morally unfit” to be president. Clearly he has no qualms now about being the president's biggest critic.

Comey's book will actually be released Tuesday.