In some towns, visitors are warned to keep an eye on their stuff, or to watch out late at night. In the Californian city of Stockton, the anxiety is more precise – and it kicks in early. "Take care downtown after 5pm," one local person told me. "Don't hang out too long."

A few hours later, I saw what she meant. Almost as soon as the offices shut, the city centre empties. Then the sun goes down and a different cast takes to the streets: the homeless, the drug dealers, and clusters of young men patrolling up and down on bicycles.

Stockton ranks among America's 10 most dangerous cities, and everyone here seems to operate under a self-imposed curfew. The commuter admits she doesn't dare go to the cinema after 8pm; the father expects his 18-year-old daughter home by 10 – "and she totally gets why." Others prefer not to go out at all. All give the same reason: the spiralling number of violent crimes.

Last weekend, the city notched up its 60th murder of the year, up from 24 for all of 2008. At just under 300,000 residents, this river port has about the same population as a London borough. Imagine a couple of your neighbours getting killed every week, and you'll understand why almost all the conversations here touch on a recent homicide.

It happened in this park, they tell you; outside that drive-through; on a first date. Then the inevitable coda: "It happened in broad daylight."

The last time Stockton attracted so much attention was in 2008, as the biggest housing bubble America had ever enjoyed was turning into the biggest bust it had ever suffered.

With nearly one in 10 homes repossessed that year alone, the city became known as the foreclosure capital of the US and formed part of the backdrop of economic catastrophe against which Barack Obama was elected president.

Then: nothing. For the next four years, the name barely cropped up in the news, so that you'd have been forgiven for believing the bad times had eased off. Until this summer, that is, when it became the largest city in America to file for bankruptcy. The bushfire had not died down, far from it – while the rest of the world was not looking, it had escalated.

The two-and-a-half-hour drive there inland from San Francisco moves from coastal grooviness to municipal crack-up. You're told as much by the local TV news network, whose reports bear the strapline Stockton in Crisis. Or you can infer it from the defensiveness of the signage. "Stockton is Magnificent!" reads one banner. "Don't give up!!!" says the hoarding over empty shop fronts.

Apart from the odd grocery store and a giant wig emporium, what downtown Stockton has in abundance is abandoned shops.

What makes the dereliction disconcerting is that it nestles amid civic grandeur, some of it quite recent. Stockton rivalled Seattle and San Francisco for importance as a transport hub during the gold rush on the 19th-century west coast, which must help to account for its grand boulevards, spacious enough to march elephants.

But there are also marbled bank offices, refurbished theatres and government offices, none of which look more than a few years old.

"The downtown could have been like Paris's 6th arrondissement!" local property developer Dan Cort tells me. While it sounds preposterous now, his claim underscores one thing: there can't be many cities in America unravelling as fast as this one.

Yet it would be wrong to dismiss Stockton as a curio, an outlandish disaster that couldn't happen here, for three reasons. First, many other towns in California, a state of 40 million that on its own would count among the 10 biggest economies on earth, are scrambling to avoid bankruptcy. This tale shares elements of the debacles in Greece, Spain and Britain, too – almost as if all the factors behind the western meltdown had been chucked in a Walmart blender and poured over one small town. What's unfurling here sums up the distinctive, dangerous way in which the great slump is playing out. Extreme it may be, but Stockton's story is also one version of a future that awaits many other cities, including those in Britain.

Let's begin with that last point. Most recessions follow a familiar waltz. First, there is the economic downturn, then there are the politicians' responses, before the social fallout: cause, effect, aftermath. But Stocktonians don't talk about a recession; they call it a depression. With one in eight workers out of a job, unemployment is almost double the national average. Six years after the peak of the market, house prices are still around half what they once were.

The local council's cash used to come from property and sales taxes; when those dried up, it rammed through cuts: the police force was shrunk by 25%, the fire department slashed by 30%, libraries and community centres either closed or are on short hours. Finally, this summer, officials ran out of services to shut, and declared the city bust.

As has happened in southern Europe, and threatens to happen under David Cameron too, this slump has been so severe and so prolonged that the economic, political and social crises are now overlapping, and amplifying each other.

To see that play out, head to Weston Ranch, a southern suburb devastated by the sub-prime mortgage crisis. According to research by Maianna Voge at George Washington University, almost one in three houses on some blocks suffered foreclosure in the bust.

When a Guardian reporter last dropped by, in 2008, he noted a forest of estate agents' boards and window signs: "Bank-owned – no trespassing". Four years on, there's much less of either. Buyers have since come along – but, rather than the families of old, they're often speculators, holding out for a blip in the market before offloading their auction bargains. While waiting, they rent the properties out carelessly and cheaply. Among these Frank Capra-esque homes, the signs of distress are now more subtle: cracked windows and lawns with overgrown brown grass.

On this afternoon, the only activity is on one driveway with a removals van. Sure enough, the bank is foreclosing on Susan and her family in the morning. Within a few minutes it all comes out: how her father moved them all here from Fremont in San Francisco's Bay Area; how his ultra-low "teaser rate" mortgage repayments rocketed without warning. How, just as that happened, property prices plunged so that they were "upside down", with the house worth less than they'd paid for it. How the lender didn't return their calls. How her father was diagnosed with cancer. Finally: how he'd died at the start of this month, just as the new buyer, one of the investors taking over the area, had offered her $3,000 to return the keys and leave without smashing the place up.

The story you're sometimes told about the sub-prime bubble is that it was a bunch of people who should never have been lent a dime suddenly being given the keys to the palace of debt. Wherever that applies, it isn't Weston Ranch. As Voge points out, household incomes here average between $60,000 and $80,000 a year: enough to warrant a middle class lifestyle, but insufficient to afford one in the pricey Bay Area. So, just as Susan's father did, they moved further and further out.

"At 4am, you'd see the house lights come on," is how another Weston Ranch resident, Alicia Calhoun, remembers life during the supposed good times. "By 6am – click! — the garage doors would go up and the street would empty out." Calhoun worked in customer services for a bank in Palo Alto: at least a four-hour round trip, on top of the 9-5 job and looking after her kids.

That commute, those dodgy mortgages, this entire "bedroom community" deep in the Central Valley: all were products of a country growing vastly more unequal within a generation. According to IMF researchers Michael Kumhof and Romain Rancière, by 2007 the richest 5% of Americans were pocketing 34 cents of every dollar earned in the US; a level of inequality last seen just before the Wall Street Crash of 1929. Most of the rest of the country saw negligible rises in their wages, and had to rely instead on borrowing. What followed was the crash of 2008 – and human and civic wreckage in places such as Stockton.

In T-shirt and shorts, Susan's mood flits between volcanic and eve-of-holiday. "You know how many homes here have been foreclosed? That one. That one. That one." She's jabbed her finger along almost the entire cul-de-sac. "Only the family next door haven't. I give them six months."

Weston Ranch, which is about 80% non-white, is basically Obamaville: full of the middle-class families he claims as his bedrock. But throughout the sub-prime freefall, his administration in effect delegated responsibility to local governments and market forces. And even in the last days of this campaign, neither Obama nor Mitt Romney has seriously addressed the housing crash. Yet according to the Chicago economist, Amir Sufi, the property bust and the recession have between them wiped out the 20 years' worth of savings by middle-income and poor families.

Susan's brother Dusty has been helping shift boxes. Another jabbing finger: "He fought in Iraq and now he's back here and the only jobs around are in warehouses at $9 an hour." Breath. "This economy is garbage."

The rec where Susan used to stroll has got so violent it's been dubbed Bullet Park. And last summer, she says, about 60 teenagers got into a pitched battle on the grass in front of her house. "They were going at each other with metal poles." Her husband phoned the police again and again, but they were too short-staffed to help. "It went on for hours."

When I run this story by police sergeant Kathryn Nance, she is puzzled: "We would have come out for an incident like that." Yet as we sit in her patrol car, she taps at the laptop: 6.30 on a Friday evening and there are already 27 outstanding calls for assistance. Top of the list is a rape reported an hour and a half ago, yet which no officer is free to deal with.

Nance's officers pile into a run-down area to chase some warrants. It's a sweep that the accompanying local TV reporter seems ecstatic about filming, but which feels like a formulaic show of police strength; strength that the downsized force no longer has. A colleague, Mark, estimates there are promising leads on more than a dozen murder cases but no manpower to investigate them. Nance talks about how the cuts made by various council departments are making parts of Stockton into no-go areas. She drives past one block and sighs: "There used to be parks and it was cleaned up. In the past four years it's gone bad again: dope dealers and vagrants.". And hassling drug dealers has become an occasional pursuit

If you don't want your area to go bad, you have to lay on your own services. On the "miracle mile", the boutiques spend their former marketing budget on a security patrol and street sweepers. They even maintain municipal car parks. A local hotelier pays to keep two public swimming pools open.

Such a sudden, drastic downgrade in what Stocktonians can expect from their mortgage lender, their council, their police, their neighbours, not to mention their own homes and pensions is dizzying even for the well-off.

As a developer of affordable housing, Carol Ornelas patiently talks me through what the sub-prime crisis means for her customers. Then she mentions her own situation – and the rush of words is like letting the air out of a balloon: "I used to live in middle-class America; now I don't know where I live. What I've seen come into my neighbourhood after all the foreclosures ... I don't even want to be around it." Again, she talks of fights in the yard just opposite.

Yet a quarter of an hour's drive from Nance's block-gone-bad is Brookside: an empty six-lane highway, a country club, and a string of small gated communities bearing such names as Nostalgia, where houses back on to fake lakes. Sneak inside and you see marble statues of cherubs. One cliché about recessions is that they make rich and poor slightly more equal. Not this time: according to Berkeley economist Emmanuel Saez, the top 1% saw their incomes soar by 11.6% in 2010; the wages of the other 99% grew only 0.2%.

"The American dream used to be within reach of the middle class," says Ornelas. "Now it's on offer only to an elite."

Stockton's city hall bears an inscription: "Let that which the fathers have builded inspire their sons to civic patriotism." Inside, the mayor's office is full of photos of what the city fathers have built in the past decade: a baseball stadium, an arena (where Neil Diamond played to a half-empty auditorium for a million-dollar fee), a swanky hotel – all around a redeveloped waterfront. They're the kind of job-free cultural makeover projects that middle-aged officials threw up all over the west in the noughties. In Stockton, estimates Jeffrey Michael at the local University of the Pacific, they were largely paid for by $100m in bonds issued over three years. For Ann Johnston, who only took over as mayor after the building spree: "Paying for these things is why we're now bust."

Well, yes and no; Stockton's problems go much deeper. Spend even a little time here and you notice something missing: middle-income employment. To the south are low-wage warehouses and food-processing plants, but the local public sector is the only home for anyone who wants a middle-class job without having to drive two hours. The city's regeneration and its encouragement of new housing estates was an attempt to bring in middle class people while skirting over the lack of decent private-sector employment. "They wanted a white-tablecloth kind of town," says former planning official Denise Jefferson.

The most grotesque example of that was a restaurant. Paragary's does a roaring business in the state capital of Sacramento, selling hand-cut rosemary noodles with seared chicken to people with large expense accounts. The city paid $2.7m in redevelopment funds to build a branch of Paragary's: its valet parking and expensive menu drew more resentment than custom, and it closed down within months.

In some ways, the entire debacle was no different from what much of Britain tried under New Labour. Except that, since Californian cities depend on property and retail taxes, Stockton council had a vested interest in inflating its bubble – only then could it keep paying for services and infrastructure to the new housing estates. As former city manager Dwayne Milnes says, "The entire system was a Ponzi scheme."

The result is a glut of houses and a glut of debt, both of which will take a long time to sort out. It's hard to imagine a time when the builders' cranes will start up again. The downtown developer Dan Cort tells me about a rival who recently pulled plans to build new houses on land by the motorway. "He's made it a walnut orchard instead." En route to the airport, the University of California sociologist Jesus Hernandez and I stop off and there they are: instead of rows of suburban homes, lines of walnut trees. Far away is the belch of Central Valley traffic; close up is the hiss of sprinklers.

As we set off, I mumble something sentimental about Stockton's retreat from postmodern financial engineering back to its agricultural roots. Jesus corrects me: "He's probably passing it off as farmland and getting a great tax break."