Not long ago, I found myself standing on a gritty stretch of sidewalk in San Francisco, South of Market, near the Tenderloin, with Sean Miller, a twenty-four-year-old software engineer. Miller is the developer of Snapcrap, a camera-based smartphone app that allows users to document human and animal waste on the street and report it with an automatically generated message—“I see poop”—to the city’s 311 program. For years, visitors to San Francisco have been shocked by the jewel-box city’s intensifying filth; according to the Guardian, complaints about feces have gone up four hundred per cent in the past decade. To remedy the problem, Mayor London Breed, who campaigned on cleanliness and who sometimes makes unannounced appearances on especially squalid blocks carrying a broom, instituted a new public-works unit called the Poop Patrol. Still, the city has only twenty-five public toilets serving an unhoused population of some seventy-five hundred people. An infectious-disease specialist at the University of California, Berkeley, has compared certain parts of San Francisco—where contaminants include a proliferation of discarded needles—to slums he’s studied in the developing world. The slums were cleaner.

Miller is pale and unprepossessing. Behind us stood the hacker house where, two years ago, as a recent graduate of the University of Vermont, he found a room to rent. “I get dropped off literally right here, and, at first glance, it’s a Friday afternoon, I was, like, O.K., good enough,” he told me. “Within a week of living here, it became very apparent that it’s not the most desirable neighborhood to live in.” For months, commuting to his job at a software company that facilitates in-app messaging—for when, say, a rideshare driver needs to contact a fare—he avoided piles of excrement. A few of his housemates stepped in them (and threw out their shoes). Many of the housemates were working on startups, and one eventually developed Ample, a successful food-replacement drink. One night, at a gathering that they called Beers and Ideas, talk turned to complaints about the street, and a friend suggested that they make an app for reporting waste. “I definitely don’t consider myself a social-justice champion or warrior or whatever,” Miller said. “But it was, like, This is insane; we’re all sort of pissed off. We thought, This’ll be funny, and make it easier for people to submit tickets, and bring it some attention.”

Once Miller came up with the name Snapcrap, the concept followed easily. The logo—which Snapchat’s lawyers took offense at, and which has since been changed—featured a caution-tape-yellow backdrop with a stylized white poop emoji. Understandably, the app has no feed. “I thought about doing that initially,” Miller said, “but then I thought, Does anyone really want to go through and look at that?” In South of Market, Miller took me on a brief tour of the block, which generated only a handful of potential reports—a clean day. The human story, however, was bleak: older, ailing people missing teeth and limbs; a motionless body removed by paramedics from the corner single-room-occupancy hotel. Miller knows the identity of each user, which, he says, discourages cruel and degrading misuse of the app, such as photographing suffering people or encampments. I asked him for a theory of the fecal Zeitgeist. “It’s the dichotomy between the über-wealthy people in the tech industry living, you know, next to people who essentially have nothing,” he said. “Which is, like, pretty insane, when you think about it.”

Shit-talking, any reader of Twitter knows, is Donald Trump’s strategy of choice. And the deeper in the shit he sinks—politically, legally, logically, grammatically—the more he flings. In January, when the Speaker of the House, Nancy Pelosi, or, as Trump calls her, “Nancy,” refused to submit to his call for the southern-border wall as a way to end the longest government shutdown in history, conditions on the ground in San Francisco were on his mind. After castigating her for behaving “irrationally,” he tweeted, “She is so petrified of the ‘lefties’ in her party that she has lost control . . . And by the way, clean up the streets in San Francisco, they are disgusting!” Clearly, Pelosi isn’t responsible for municipal sanitation in the city that elected her. But that was not Trump’s point. He was attempting to humiliate her; in his version of events, she had “lost control,” and the mess in her city was proof.

Poop is Trump’s Other (in close competition with menstrual blood, which he figures as a pollutant that flows from “wherever”). Last year, in a failed discussion of immigration policy, he invented the noxious, racially anxious category of “shithole countries,” which, attending lawmakers told reporters, he defined as places like Haiti, El Salvador, and a number of African nations. The catch-all term included capitals that happen to lack central sewage systems, but it was evident that the reference was to more than plumbing. His fecal aversion—which, if you follow French psychoanalytic theory, may also explain his love of gilt—was neatly expressed in a 2003 interview with Howard Stern. In it, the future President brings up the bathroom habits of his future wife, Melania, claiming that, as far as he knows, she does not defecate. “I’ve never seen it; it’s amazing,” he says, grinning—in you know what fashion. “Maybe they save that for after marriage.”

Political liberalism is a strange place to lay blame for problems—like unaffordable housing and the lack of a social safety net—that stem from raw capitalism. Housing scarcity exerts pressure on even those participating in the narrowly distributed bounty of the tech economy. Miller told me that, even with his decent-paying work as an engineer, he lives with a roommate, and that he has heard of engineers at companies like Google who are living in R.V.s. As the tremendous wealth generated by the region’s tech companies continues to grow—so much that the industry feels ready to erect a monument to itself—the crisis on the streets of San Francisco is especially troubling. This is the progressive city where our ultra-modern, post-biological future is being invented. Why, then, does it look so much like our idea of the past?

For help answering this, I called Guy Geltner, an urban historian at the University of Amsterdam who studies the late Middle Ages. (His book “Roads to Health: Infrastructure and Urban Well-Being in Later Medieval Italy” comes out in July.) Geltner, who recently lived in San Francisco for a year, told me that, for residents of a modern city in a supposedly sanitized society, the threat of human feces is symbolic. “We look at poop, and it embodies something greater than a disease,” he said. “It’s something about the human body and human body politic that we’re afraid of watching as we commute to work. Public defecation is associated with mental illness. It’s a loss of control. Who in their right mind, with the most minimal resources, would choose to squat between two parked cars. Who? To us, it’s this painful illustration of something gone unimaginably wrong. That’s more powerful than the actual biological dangers that these smelly piles pose.”

Geltner makes the point that anything we don’t like in ourselves we consign to the pre-industrial past, so that the word “medieval” is a term of derision, and the phrase “the Dark Ages”—actually the period when universities and urbanization were invented—speaks for itself. But, epidemiologically, the largest medieval city in Western Europe —Paris, which had a population of two hundred thousand people before the Black Death—was biologically far safer than contemporary San Francisco or Los Angeles (or any large airport or hospital). Early civilizations had elaborate methods for waste disposal: the vast bureaucracy of Edo (medieval Tokyo) codified collection and composting; medieval Islamic regulations addressed how to move waste through the streets without spillage. The advent of plumbing is what led to the putrefaction of the canals of Venice, as the waste that accumulated in septic systems had nowhere else to go. “Modernity is far messier than what came before,” he said.