Whatever candidate wants James Murphy's vote for mayor has to start outside the gate to his house at 52nd and Just streets NE, go through his working-class neighborhood, Deanwood, and come to terms with Murphy's ward, Ward 7.

From the mayor's office atop the District Building downtown, the ward can seem a distant, 'cross-the-river mix of middle-class, working people with many of the city's poor.

But close up, Murphy sees a nearby alley that he thinks is the dirtiest in the city, he sees fear of muggers and robbers running through his neighborhood and businesses struggling to stay alive in a ward that he suspects never sees the city services that more affluent areas get.

For politicians, the way to victory in the Sept. 14 primary begins with adding up enough wins in the city's eight wards to equal victory citywide. And as the primary campaign enters its final six weeks, Ward 7 may offer some insight into the other wards, because it is one ward that appears to be choosing sides early.

Ward 7 has become a stronghold for Marion Barry. With a shrewd use of incumbency and political savvy somewhat new to Washington's still young local political process, Barry has made this ward that snubbed his candidacy only four years ago into a home for his family as well as his political career.

"I don't know if I have a political base," Barry said in a recent interview. "I want the whole city to be my base. When I moved out there I didn't have politics in mind.

"Now, the people out there like me. I think they know the city government is working for them, I've made an effort to make that clear. They don't feel separated and they know I live out there. So in that sense they have every reason to like me."

This ward in the far eastern wedge of the city was ripe to be Barry's home in a unique way, almost tailor-made. Barry is not from a long line of Washingtonians like many of the political activists in other wards that for years have produced recognized political leaders. Here, he is among many people like himself who settled here after growing up in the South not long enough ago to lose their accents.

Among these people, the idea that the mayor lives near them is a matter of great pride. He is a star here in a way he might not be in any of the other wards. Barry has prospered in this ward hungry for recognition by giving its residents appointments to boards and commissions and a place on the political map.

"Patronage isn't evil," says Barry campaign manager Ivanhoe Donaldson when asked if his candidate was intentionally currying political favor in Ward 7. "Just good politics."

A recent poll by The Washington Post found that in this ward, Barry leads his opponents for the Democratic nomination by a larger margin than anywhere else, and is regarded better by voters here than any other ward in the city. He has fewer hard-core opponents here than elsewhere, the poll found, and a high proportion of people who describe themselves as rock-ribbed Barry supporters.

This hard core support is a striking reversal of the 1978 Democratic primary, which he won with a scant 35 percent of the vote but finished third in Ward 7 with 29 percent.

In many respects, 68-year-old James Murphy is representative of one major sector of this ward's residents. He has lived here 32 years and is a retired government employe with a yearly income of around $25,000 which, he says, makes him "middle-class for black people."

Deanwood, with its struggling business strip, its public housing, its mix of middle-class homes and apartment buildings filled with working-class people, is a topographical microcosm of Ward 7.

"This ward is a place where people settle down to live, raise a family and go to church," said Murphy, a former bookbinder at the Bureau of Printing and Engraving. "You've got some areas where people have more money and public housing, but it's all very much homes and families here for people who work downtown in the government."

Murphy's description of the ward, which basically is made up of the easternmost wedge of the District of Columbia east of the Anacostia River, is supported by 1980 census data.

It is a ward with one movie theatre--the Senator on Minnesota Avenue NE, which tried to show pornographic films but was stopped by neighbors armed with a court injunction. It has only four major supermarkets, few sit-down family restaurants and an ever growing number of fast-food restaurants that have residents concerned about noise and litter.

The ward also has dozens of churches, including Upper Room Baptist, Anacostia Baptist and Capitol View Baptist, whose pastor, the Rev. Andrew Fowler, is executive secretary of the Committee of 100 Ministers.

This ward is also a picture of economic contrasts. It has the most public housing of any ward in the city with 12 projects, but also houses several strongly middle-class neighborhoods, largely to the south of Fort DuPont Park--Hillcrest, Fort DuPont, Penn-Branch.

In fact, there are so many middle- and upper middle-income homes in some stretches of the ward that some have called that area the "Silver Coast," a Ward 7 version of the "Gold Coast" off upper 16th Street NW, an area known for its large brick houses and well-to-do families.

Ward 7 has the highest population of blacks in the city, 78,779, and the lowest number of whites, 3,053. The ward also has the second highest number of women, 45,087, and a slightly higher number of widowed, separated or divorced women than most wards.

Politically the ward has a history of friendliness to incumbents, with its key precincts both north and south of the park located among the middle-class homeowners who often work in the governemnt.

"Ward 7 politically is a ward that went for Walter Washington last time because we are a ward of workers, government workers," said Geraldine Boykin, executive director of Council 20 of the American Federation of State, County and Municipal Employees, which represents several thousand city employes.

Boykin has lived on Highwood Drive in Ward 7 for 23 years. "People in Ward 7 look at the mayor as someone they relate to day-to-day," she said. "They want access to the mayor. He's very important to them as their boss."

Donaldson, Barry's campaign manager, said the ward, which has the third largest number of registered Democrats in an overwhelmingly Democratic city, is a traditional base for any incumbent.

"We won without it last time but it's a ward you have to pay attention to," Donaldson said. "You have to pay attention to all the wards, but especially a ward like 7 because of its size. If you ignore it, someone could come along and build an edge there that you can't overcome in other wards."

Barry's drive to prominence in Ward 7 is a study in good politicking. Part of his edge, for instance, stems from support among public housing residents. Barry's key supporter in that community of 15,000 people, about 7,000 of whom are registered to vote, is Kimi Gray, who works for the city's roving leader program and who Barry appointed head of the city's public housing advisory board shortly after he was elected.

In 1978, Gray supported Tucker. In the last three years, however, she has brought Barry to the projects regularly and sent out the message that despite his problems, Barry is the best hope for public housing tenants.

"Marion brought us respect," said Gray said, explaining why she supports Barry. "He's been fixing up the streets out here . . . He started a six-month experimental program with mini-buses to help our people get to the Metro. We've got environmental service picking up the trash like never before."

In appealing to the ward's middle-income residents, Donaldson said, Barry is relying on the message that the government is doing well and has made a point of putting more Ward 7 residents on boards and commissions.

At the same time, Barry is remaking his image as a threatening, angry young man into the family man, government worker who other family-oriented government workers can feel has matured into one of them.

"Being mayor has taught me a great deal," said Barry when asked about relating to the stable homeowners who once viewed him askance. "I don't have to do the things I had to do in the streets in order to be heard anymore. They know that."

The large number of city workers in the ward also know that Barry gave them a 20 percent pay raise over the next three years in the election year contract the city negotiated as well as added optical and dental coverage in their city-paid health care packages.

Part of Barry's apparent success in building a base in Ward 7 may have been his establishing residence there in a four-bedroom house on Suitland Road with an antebellum facade in the front.

It is a move from Capitol Hill, where he was renting, that Barry says was motivated less by politics and more by a good sale price and his memory of growing up in Mississippi with a backyard.

"Effi's a New Yorker," he said of his wife. "She'd be happy living in a condominium, one of those Southwest apartments overlooking the river. I want a yard, a house big enough for a mayor . . . And we got a good deal, so we settled on the house. Politics don't come into everything, you know."

The Barry family lives right behind Margaret Jones, an alternate delegate to the Democratic convention in 1980 and part of Barry's ward organization.

"I see him coming in and going out. I couldn't tell you why I like him but he's tops with me. He's a people-oriented person . . . I guess I like him living out here. Once you cross that bridge it's different, you can breathe out here."

Barry's Ward 7 political organization is headed by Lorraine Whitlock of Deanwood, a former city schoolteacher he appointed to the board of the University of the District of Columbia after he became mayor. For more than a year, the organization has been working to build support for this year's primary.

Barry's summertime lead in Ward 7 has not lulled his opponents into concession. "He has an edge," said Sharon Pratt Dixon, campaign director for Barry's leading opponent, lawyer Patricia Roberts Harris. "But it's not an edge we capitulate to."

"He gets some spillover good feeling from living in the ward. But we can hold him even or beat him if Pat can communicate the kind of change she has in mind that would make government workers proud to be part of the District government and not feel defensive about what they do," Dixon said.

James W. Baldwin, the city's former human rights director, is organizing the Ward 7 campaign of council member John Ray, who has run well behind Barry and Harris in most polls. In 1980, Baldwin ran H.R. Crawford's successful bid for the ward's seat on the City Council.

"He might be out front," Baldwin said of Barry. "But I find it hard to believe he has a 2-to-1 edge in Ward 7" as indicated by The Post's poll.

"If he does have a lead, I'd attribute it to incumbency and he has a good organization out here," Baldwin said. "But what actually is going to happen at the polls may be a different story. What they really think of Barry may come out there."