It’s a Thursday afternoon at the Tesla Factory in Fremont, California, and the robots are humming. Humans in T-shirts and San Francisco Giants caps trade jokes as they help a massive robotic arm guide a touchscreen dashboard assembly past the B-pillar of a partially built Model S. Farther down the assembly line, finished cars rest in sleek rows according to their export destinations: Frankfurt, Oslo, Hong Kong.

Heading into its second decade as a company, Tesla might look like it’s on cruise control. After proving electric-car doubters wrong in 2008 by building a screaming-fast sports car, the Roadster, it proved them even wronger in 2012 by building the wildly popular—and surprisingly practical—Model S sedan. A hit with critics and rich techies alike, the Model S has rapidly become one of the world’s most coveted—and, in some markets, best-selling—luxury cars. Demand is building in Europe and Asia. A second high-end model, the Model X SUV, will hit the market next year.

If Tesla’s goal were simply to become a world-beating luxury automaker, crafting pricey toys for the environmentally conscious elite, it would already have succeeded. But Elon Musk’s aim all along has been to build an electric car for the masses. Specifically, the company’s plan is a $35,000 “third-generation” electric sedan with competitive performance and a 200-mile-plus range—all by the year 2017. (This third-generation sedan has been popularly dubbed Model E, though that’s unlikely to end up as its real name.) By 2020, Tesla hopes to be shipping 500,000 cars a year. That’s more than 10 times its current output. And it will probably have to do it without the federal subsidies that have helped make its cars more affordable so far.

If Tesla pulls it off, it will secure its place among the world’s great car companies while helping to push electric cars into the mainstream. If Tesla falls short, it will remain a glitzy sideshow while established players like Nissan and BMW figure out the future of the car, electric or otherwise.

The enduring problem with electric cars is that batteries cost far more than internal combustion engines relative to the power they provide. Before Tesla, the prevailing approach was to keep electric cars as affordable as possible by skimping on performance and range. The result: $35,000 plug-ins that drove like $12,000 econo-boxes. Musk turned that equation on its head by casting price concerns aside and building the best cars he could—the Model S costs $80,000, and it outperforms the best gas-guzzlers in its class.

It was a stroke of strategic brilliance, but it didn’t solve the underlying problem. Electric batteries are still nowhere near as cost-effective as gasoline engines (unless you count the societal costs of air pollution—but that’s another debate). So how can Tesla possibly achieve its stated objectives for its third-generation vehicle?

Elon Musk’s answer: Build a Gigafactory.

The Gigafactory is Tesla’s name for the massive, all-in-one battery factory it’s planning to build somewhere in the American West, starting in the next few weeks. It will be the largest factory of its kind, capable of producing more lithium-ion batteries each year than were produced in the whole world in 2013. Through manufacturing efficiencies and economies of scale, Tesla believes it can bring down the cost of its battery packs by more than 30 percent using already-available technology. That would be enough to make its $35,000 third-generation model economically viable.

The approach is classic Musk, says Steve LeVine, a Future Tense fellow at the New America Foundation who is working on a book about the race to build a better battery. Where other automakers have been waiting for fundamental advances in technology, Musk is plowing ahead with commodity battery cells, convinced he can bring down costs through a combination of ingenuity and brute force.

On Tesla’s earnings call last week, Musk announced that Panasonic has signed a letter of intent to partner with Tesla on the Gigafactory and manufacture its battery cells there. But that will be just part of the operation. The idea is to bring in other companies to produce all the necessary battery-pack components at the same facility. “It’s sort of like an industrial park under one roof,” Musk said. “Tesla’s producing the modules—Tesla’s sort of the overall landlord.”

Tesla has also been approaching mining companies about bulk discounts on the relevant raw materials, such as nickel and cobalt, Musk added. “It’s kind of funny, in talking to the mining companies, it’s like, nobody ever calls them. … So the mining guys were just super happy to hear from us and have quite good ideas for how to optimize the cost of the materials,” Musk said.

The concept is reminiscent of Henry Ford’s famous River Rouge complex, which integrated virtually the entire supply chain for vehicle production, observes John Voelcker, editor of Green Car Reports: “The old saying was that iron ore would go in one end and a Model T would come out the other.” At the Gigafactory, nickel, cobalt, and lithium would go in one end, and finished battery packs would come out the other.

Tesla will still assemble the actual cars at its existing factory in Fremont. The company was stupendously fortunate to buy the former General Motors–and-Toyota-owned NUMMI auto plant in 2010 for the fire-sale price of $42 million following GM’s bankruptcy. The facility is far bigger than what Tesla needs: When I visited in April, the company was only using one wing of the plant to build all its Model S cars, even as it ramped up production in anticipation of its first exports to China. That extra space will come in handy as the company expands.

The Gigafactory, in contrast, will have to be built from scratch at an estimated cost of $5 billion. Tesla has named five states as possible sites: Texas, Arizona, New Mexico, Nevada, and California. Yet with groundbreaking less than a month away, the company is still keeping coy as to which one it has chosen, perhaps in a bid to wrangle final-hour concessions from the candidates.

In another quintessential Musk move, the company has said it plans to break ground on two sites at once, because it can’t afford to be held back by permitting and construction delays. Whichever one comes along more slowly, presumably, will be jettisoned or repurposed. The project would be audacious even for the world’s largest automakers. For one that sold just 20,000 cars last year, it seems crazy. But Musk has built his career on projects that seemed crazy—right up until he completed them.