PHOENIX — Senator Jeff Flake, Republican of Arizona, faces political challenges from both sides in seeking re-election next year: On the left, emboldened Democrats are aggressively recruiting candidates to run against him. On the right, allies of President Trump are devising ways to punish Mr. Flake for his outspoken rejection of Mr. Trump last year.

Yet Mr. Flake, seemingly undaunted, has secretly planned an unconventional campaign kickoff that risks intensifying both threats: Working privately, and largely without the knowledge of political advisers, he has written a book that amounts to an ideological manifesto for his own version of conservatism, according to three people briefed on the manuscript who discussed it on the condition of anonymity.

All three said it was likely to inflame debate about the direction of the Republican Party.

In his writing, Mr. Flake draws a bright-line distinction between his outlook on government and a competing vision, associated with Mr. Trump, that Mr. Flake describes as nationalist and populist in nature, the people said. Mr. Flake links himself closely with Barry Goldwater, the former senator and presidential candidate from Arizona.

By leaning into his differences with the president, Mr. Flake, 54, may help ensure that his re-election race unfolds as a dramatic clash over what it means to be a Republican in the age of Trump. While many politicians write books, it is highly unusual for a senator to do so without extensively consulting advisers, particularly when the subject matter is so politically charged.

Even before Mr. Flake’s book, the Southwest was emerging as a pivotal testing ground for Mr. Trump’s leadership of the Republican Party. In neighboring Nevada, Senator Dean Heller, a fellow Republican, has faced threats of retribution from the White House for occasionally bucking the president’s agenda, most recently by panning an early version of the Senate health care bill. (Both Mr. Heller and Mr. Flake voted on Tuesday to move forward with a debate on the legislation.)

Democrats are preparing to compete heavily for both the Arizona and Nevada seats, viewing them as the best opportunities to defeat Republican incumbents in 2018.

In Arizona, Representative Kyrsten Sinema and Mayor Greg Stanton of Phoenix are both considering the race on the Democratic side, and State Representative Randy Friese is likely to run.

Wes Gullett, a Republican public relations executive who is a former adviser to Senator John McCain, said Mr. Flake’s book appeared to be part of a political strategy aimed both at defending himself on the right and at making overtures to the middle.

“Seize the Goldwater wing of the Republican Party and not alienate Republican and independent women who will decide the election in November,” Mr. Gullett said, describing Mr. Flake’s mission. “The way President Trump is headed, by the election next year, Trump may not be as popular amongst the right and Senator Flake will not be tied to him.”

Starting last year, Mr. Flake has consistently distanced himself from Mr. Trump and has instead presented himself as a traditional, small-government conservative. He was one of Mr. Trump’s most pointed Republican critics during the presidential race and rebuked Mr. Trump repeatedly for actions Mr. Flake described as “beyond the pale.”

Unlike Mr. Trump, Mr. Flake is an avowed fiscal hawk and a supporter of free trade and a comprehensive immigration overhaul. His position on immigration, especially, has often put him at odds with the Republican Party’s activist base in Arizona.

Robert Graham, a former state Republican Party chairman, and Jeff DeWit, the Arizona state treasurer, are both weighing bids against Mr. Flake. Kelli Ward, a former state senator who unsuccessfully ran against Mr. McCain last year, has already entered the Republican primary against Mr. Flake.

Mr. Graham said that White House advisers and political donors supportive of Mr. Trump were taking a close look at a number of 2018 Senate races, including those in Arizona and Nevada, to see where Republican incumbents might be replaced with people more supportive of the president.

“If you have somebody that is, I will call it, an obstacle on virtually every aspect of an agenda,” Mr. Graham argued, “then if this person gets re-elected, they have six more years where they will be in office and will likely maintain that same disposition.”

Mr. Trump carried Arizona only narrowly against Hillary Clinton, but he remains popular with Republicans in the state.

Josh Daniels, Mr. Flake’s campaign manager, signaled in a statement that Mr. Flake, still in his first term, was confident of his prospects in the race.

“Senator Flake is a principled conservative fighting every day for the people of Arizona,” Mr. Daniels said. “We’re building a winning campaign powered by strong fund-raising and a dominant ground game.”

If the book may rankle some of Mr. Flake’s critics on the right, his allies hope it will help address a more basic problem: He is a relatively undefined personality in Arizona and lacks the formidable profile of the state’s senior senator, Mr. McCain.

Pausing under the scorching July sun to talk politics, Linda McSweeney, a Republican voter who works in business development, said she viewed Mr. Flake as a distant figure. “Nobody knows who he is,” said Ms. McSweeney, 55, who described herself as having reluctantly voted for Mr. Trump last year.

Yet in what could be a hopeful sign for Mr. Flake, Ms. McSweeney said she would favor a risk-taker in the Senate race.

“I like people that take chances and shake things up,” she said.

A version of this article appears in print on , Section A, Page 8 of the New York edition with the headline: Arizona Senator, Facing Twin Threats, Takes On G.O.P. Rift in a New Book. Order Reprints | Today’s Paper | Subscribe