Casa El Presidente, a shelter run by Southwest Key Programs, in Brownsville, Texas, June 20, 2018. Immigration authorities have opened shelter space for children under the age of 12, referred to as “tender age” detainees, who are entering the detention system in ever-larger numbers.

The shelters' rush to house, and cash in on, the surge of children has made them a new target for Democrats, immigrant advocates and a vocal chorus of local, state and federal officials and community leaders.

For years, including during the Obama administration, contractors housed children who were caught illegally crossing the border unaccompanied by a parent or guardian. After the new policy, the contractors put in new beds and expanded beyond their licensed capacities to house the growing numbers of children the government separated from their families. In Texas alone, 15 shelters have received variances from state officials to expand, including adding bedroom space and toilets, increasing the total licensed capacity in Texas to nearly 5,300 children, from around 4,500.

The migrant-shelter business has been booming since family separations began on a large scale last month along the southwest border.

But several large defense contractors and security firms are also building a presence in the system, including General Dynamics, the global aerospace and defense company, and MVM Inc., which until 2008 contracted with the government to supply guards in Iraq. MVM recently put up job postings seeking "bilingual travel youth care workers" in the McAllen area of South Texas. It described the jobs as providing care to immigrant children "while you are accompanying them on domestic flights and via ground transportation to shelters all over the country."

BCFS, a global network of nonprofit groups, has received at least $179 million in federal contracts since 2015 under the government's so-called unaccompanied alien children program, designed to handle migrant youths who arrive in the country without a parent or other family member. Many of the contractors, some of which are religiously affiliated organizations and emergency-management agencies such as Catholic Charities, see their work as humanitarian aid to some of the most vulnerable children in the world.

A small network of private prison companies already is operating family detention centers in Texas and Pennsylvania , and those facilities are likely to expand under the new presidential directive, should it stand up to legal review, analysts said.

The recent separation of some 2,300 migrant children from their families under the Trump administration's "zero tolerance" policy on illegal border crossers has thrust this invisible industry into the spotlight in recent weeks, as images of toddlers and teenagers taken from their parents and detained behind locked doors have set off a political firestorm. President Trump's order on Wednesday calling for migrant families to be detained together likely means millions more in contracts for private shelter operators, construction companies and defense contractors.

If there is a migrant-shelter hub in America , then it is perhaps in the four-county Rio Grande Valley region of South Texas, where about a dozen shelters occupy former stores, schools and medical centers. They are some of the region's biggest employers, though what happens inside is often highly confidential: One group has employees sign nondisclosure agreements, more a fixture of the high-stakes corporate world than of nonprofit child-care centers.

The nonprofit Southwest Key Programs has won at least $955 million in federal contracts since 2015 to run shelters and provide other services to immigrant children in federal custody. Its shelter for migrant boys at a former Walmart Supercenter in South Texas has been the focus of nationwide scrutiny, but Southwest Key is but one player in the lucrative, secretive world of the migrant-shelter business. About a dozen contractors operate more than 30 facilities in Texas alone, with numerous others contracted for about 100 shelters in 16 other states.

The business of housing, transporting and watching over migrant children detained along the southwest border is not a multimillion-dollar business.

A two-year-old Honduran asylum seeker cries as her mother is searched and detained near the U.S.-Mexico border on June 12, 2018 in McAllen, Texas.

Many of these contractors, including Southwest Key, whose president and chief executive, Juan Sánchez, has been a well-known and politically connected figure in South Texas for years, saw themselves as the good guys in all the years they were sheltering, housing and educating young people who had crossed the border on their own. But as their client base increasingly has included children forcibly removed from their parents, that public good will has eroded.

Critics have released tax records showing Mr. Sánchez's compensation — more than $770,000 in 2015 alone — and his organization's usually under-the-radar efforts to open new shelters have become pitched public battles. In Houston, a number of Democratic officials, including Mayor Sylvester Turner, called on Mr. Sánchez to abandon plans to turn a former homeless shelter into a new migrant youth shelter near downtown. Mr. Turner and others said they would urge state regulators to deny the proposed shelter a child-care-facility license.

Some have raised concerns that the rush to expand will make it difficult to properly manage the housing and care of infants, toddlers and teenagers, all of whom have a host of complex emotional, health and legal issues. In recent years, a number of migrant youth shelters have run into problems unseen by the public: fire-code violations, lawsuits claiming abuse, and complaints from employees alleging wrongful termination and unpaid wages.

The former Walmart shelter failed two of its 12 fire inspections, including for sprinkler-system problems, but passed its most recent inspection this month. State officials have investigated allegations of sexual abuse and neglectful supervision at numerous facilities.

Shelter executives and their supporters, as well as federal officials, say they stand behind the contractors' management, their fiscal responsibility and their overall mission.

"Our growth is in direct response to kids coming to the border," said Alexia Rodriguez, Southwest Key's vice president of immigrant children's services.

She said that Southwest Key shelters must be in compliance with hundreds of standards to keep their state licenses.

The majority of the thousands of potential violations that are investigated each year are self-reported by Southwest Key staff to state licensing officials, who conduct an investigation and decide whether there has been a violation. When applicable, Ms. Rodriguez said, staff members under investigation are suspended pending the results.

The 150 or so deficiencies cited over the past three years are out of tens of thousands of potential violations, most of which were reported by Southwest Key, Ms. Rodriguez said. "We may overreport. But what's critical is how a company responds to a possible incident," she said. "I can say we've never had a deficiency that was not addressed appropriately."

While Southwest Key has garnered attention because of the Trump administration's policy of breaking up families at the border, only 10 percent of children in its facilities were separated from their relatives. The vast majority in its care still came to the United States alone as unaccompanied minors, mainly from Guatemala and El Salvador.

The group's shelter capacity has grown significantly: In 2010, it had capacity for up to 500 children a day across 10 shelters. Now it can serve up to 5,000 children a day across 26 shelters. The recent surge in family separations has put even more of a demand on its facilities.

In Harlingen one recent morning, the federal courthouse that hears immigration cases was packed. Teenagers who had been apprehended crossing the border sat in the courtrooms, fidgeting in their rolled-up jeans and sneakers.

In the lobby, a group of men and women whispered among themselves as they patiently waited for the hearings to end. They were there for the migrant youth. But they were neither relatives nor lawyers. They were contractors. Their job was to escort the detained children back to nearby shelters.

Transportation to and from shelters is but one service supplied by contractors on the federal dime.

Adults and children who are apprehended illegally crossing the border are detained and housed in a variety of facilities, some of which are run by the government and some by private contractors. There are detention centers at Border Patrol stations and at facilities operated by private-prison contractors such as CoreCivic. And then there are the migrant youth shelters.

One of the best-known is Casa Padre, the name of Southwest Key's shelter for 10- to 17-year-old boys at the converted Walmart. It is the largest shelter of its kind in the country, with nearly 1,500 boys.

The building is owned not by Walmart but by private owners, who lease it to Southwest Key. The Walmart was gutted, redesigned and renovated into a kind of mini-city, with murals, classrooms, medical offices, on-call physicians, work cubicles, movie theaters, a barbershop and a cafeteria.

Pre-Trump, Southwest Key was warmly received by left-leaning immigration activists and civil rights organizations. Post-Trump, some of the group's former allies are now leading the outcry.

Legal organizations including the A.C.L.U. and the Lawyers' Committee for Civil Rights Under Law represented Southwest Key in a 2015 lawsuit against Escondido, Calif., accusing the city of manipulating land use and zoning laws to block the opening of a new center that could house 96 children.

The lawsuit quoted Escondido citizens who had opposed the facility in letters and hearings. "I believe most of us are sick of paying for undocumented invaders," one comment read.

Southwest Key eventually received a $550,000 settlement from Escondido, but during the case the organization opened housing elsewhere instead.

"I was taken aback by the venom that came out of certain members of that community, and the threats I received personally to my safety and security," said Ms. Rodriguez, the Southwest Key executive. "These are innocent children that have done nothing wrong, fleeing violent communities, and this is the response we were getting in Escondido?"

Migrant shelter operators say they have been wrongly thought to be housing youths in the kind of heavily crowded facilities near border crossings at which migrants receive their initial processing.

Images of children in chain-link cages and pens that have circulated online recently are mainly taken at Border Patrol sites run by the government. Housing at places like Southwest Key facilities generally include dorms, classroom areas and medical and counseling centers.

"If we ever put a kid in a cage, we'd be shut down for mistreating children," said Ms. Rodriguez. "People are conflating us with the facilities run by Border Patrol, which is a division of Homeland Security. We work with the social service side of the federal government. We are not law enforcement."