Dismissing-then-recruiting: a unique mechanism for symbiont recruitment and lignocellulose degradation in gut of black soldier fly larvae Authors: Fang Ming Xiang, Xiao Tian Tang, María Gómez Brandón, Ahmed R. Henawy, ShuoYun Jiang, XinHua Xu, XueXin Chen, ZhiJian Zhang Published: 2026 ABSTRACT BackgroundBlack soldier fly larvae (Hermetia illucens L., BSFL) efficiently degrade lignocellulosic waste despite lacking endogenous lignocellulolytic enzymes, indicating a critical dependence on gut-associated microbiota. However, how BSFL are associated with the enrichment and spatial organization of lignocellulose-degrading symbionts within the gut remains poorly understood.ResultsWe show that BSFL establish a spatially structured microbiome through gut compartment-specific immune regulation. Axenic larvae showed negligible lignocellulose degradation, whereas microbiota-associated larvae achieved ~ 33.3%, confirming microbial dependence. Antimicrobial peptides, including cecropin and defensin, were highly expressed in the anterior midgut, forming a selective barrier. In contrast, the posterior midgut showed reduced immune activity via peptidoglycan recognition proteins (PGRP-LB, PGRP-SC). Concurrently, host glycosylation-related genes (C1galt1, GlcAT-P, FUT8/11) were significantly upregulated in the posterior midgut (17–19 TPM), representing a 4–fivefold increase relative to the anterior region (p < 0.01). This region was correspondingly enriched in carbohydrate-active symbionts producing glycoside hydrolases, including galactosidases, fucosidases, and mannosidases, suggesting that upregulated glycan biosynthesis may provide sustained nutrient availability for microbial taxa with corresponding carbohydrate-utilizing capacities. Such compartmentalized immune–metabolic coordination is consistent with a potentially conserved strategy for modulating immune tolerance and fostering symbiont recruitment.ConclusionsCollectively, our findings define a compartmentalized “Dismissing–then–Recruiting” strategy for microbiome assembly in BSFL, which is associated with the structuring of functional symbiont communities for efficient lignocellulose bioconversion, thereby elucidating novel principles for sustainable waste management. Video AbstractSupplementary InformationThe online version contains supplementary material available at https://doi.org/10.1186/s40168-026-02441-6. Introduction Throughout evolutionary history, organisms have developed adaptive strategies that underpin Earth’s biodiversity. The gut, in particular, maintains close interactions with resident microbiota [1, 2], which are frequently regionally localized based on their metabolic preferences [3]. These microorganisms also synthesize essential compounds inaccessible to the host, detoxify harmful substances, and help prevent pathogen colonization through competitive exclusion and/or production of antimicrobial peptides (AMPs) [4, 5]. Consequently, sustaining gut microbiota homeostasis is vital for enhancing host environmental adaptability. Black soldier fly larvae (Hermetia illucens L., BSFL) have attracted growing interest for their remarkable efficiency in organic waste bioconversion [6–9]. However, lignocellulose—comprising 35.2% to 62.1% of typical waste (fruit and vegetable residues, livestock manure and household kitchen waste, etc.) [10–13]—cannot be broken down by BSFL alone due to their lack of endogenous enzymes [14, 15]. Despite this enzymatic limitation, surprisingly high lignocellulose degradation efficiencies (20% to 50%) have been reported in real-world BSFL bioconversion systems [7–9], underscoring the potential contribution of symbiotic microbes. Although microbes are known to drive lignocellulose breakdown [7, 8], the specific location of this process—whether it occurs primarily within the gut or externally—remains unclear. Furthermore, the mechanisms by which the BSFL gut modulates microbial activity are poorly understood. Gut compartmentalization, a common feature among insects, creates region-specific environments that differently influence microbial colonization through variations in pH, redox status, immunity, and nutrients [1–4]. This spatial organization likely enables BSFL to recruit specialized symbionts in distinct gut niches, particularly for lignocellulose breakdown. Understanding and harnessing this spatial structuring offers new opportunities to engineer insect–microbe systems for enhanced waste bioconversion under complex environmental conditions. In insects, innate immunity serves as a crucial host factor shaping gut microbiota composition [16–18]. Both the Toll and immune deficiency (Imd) pathways are conserved in Dipterans and regulate immune responses to Gram-positive and Gram-negative bacteria, respectively. The immune deficiency (Imd) pathway plays a central role by recognizing bacterial peptidoglycan via peptidoglycan recognition proteins (PGRPs) [19–21]. Specifically, PGRP-LC functions as a transmembrane receptor for extracellular peptidoglycan, while PGRP-LE detects cytoplasmic signals [22, 23]—both promoting the production of AMPs [24–26]. Additionally, negative regulators such as PGRP-LB and PGRP-SC further refine this response by suppressing AMP production to enable symbiont tolerance [27]. Concurrently, the intestinal epithelium actively contributes to microbial selection by secreting glycans—complex carbohydrate structures that serve as both nutrient sources and adhesion scaffolds [28–31]. Mucin-associated N- and O-linked glycans, shaped by host gene expression and environmental signals, mediate species-specific bacterial colonization [32–34]. For instance, glycan motifs such as digalactoside and fucose residues can selectively enhance the adhesion of Escherichia coli or Vibrio parahaemolyticus [35, 36], revealing how different bacteria exploit glycans for niche-specific colonization. Despite extensive studies in mammals, how immune and glycan pathways jointly modulate microbial recruitment in insects remains elusive. In BSFL, these host factors are not spatially uniform but follow the anatomical compartmentalization of the gut—a widespread feature among insects [2–4]. This spatial heterogeneity likely supports region-specific microbial filtering and provides a functional framework to interpret how gut compartmentalization may contribute to the selective enrichment of lignocellulose-degrading symbionts. Previous studies have shown that BSFL markedly reshape substrate microbial communities and that their guts are consistently enriched with lignocellulose-degrading bacteria [37]. However, the mechanisms underlying how these degraders are selectively recruited and spatially organized within the larval gut remain unknown. In this study, we demonstrate that BSFL selectively enrich lignocellulose-degrading symbionts within the compartmentalized midgut through a spatially coordinated mechanism involving both immune regulation and epithelial glycosylation. Region-specific suppression of immune responses along the gut axis established a selective barrier mainly by high expression of AMPs to “Dismiss” microbiome in the anterior midgut (AM) and then created a permissive niche mainly by PGRPs to “Recruit” microbiome in the posterior midgut (PM). Concurrently, metagenomic analyses reveal that microbial taxa enriched in the PM region harbor a broad array of glycoside hydrolases targeting host and plant-derived glycans. This unique host-driven microbiota recruitment enables the BSFL gut, which is inherently deficient in endogenous genes, to efficiently degrade lignocellulose. Beyond advancing BSFL bioconversion, our findings illuminate a potentially conserved evolutionary strategy for host-driven microbial assembly, offering insights into gut symbiosis and coadaptation across animal taxa. Materials and methods BSFL rearing The BSFL were raised under conditions of 28 ± 1 ℃ and 70%–80% relative humidity, with a 14 h light/10 h dark cycle. The eggs were laid in tissue culture bottles with the experimental diet until hatching. Experimental diet (Table S1) was composed of wheat bran (50%), corn meal (30%), and alfalfa meal (20%) mixed in a 1:2 ratio of dry matter/water [37]. Axenic BSFL were obtained by surface sterilizing freshly laid eggs (< 12 h old) following established protocols [38]. Eggs were immersed in 5% sodium hypochlorite for 3–5 min, rinsed twice with 75% ethanol and twice with sterile distilled water, then transferred to autoclaved flasks containing sterile substrate slurry. Incubation was conducted at 27 °C and 70% humidity until hatching. All operations were performed under aseptic conditions in a laminar flow hood. A schematic overview of the germ-free BSFL construction workflow is shown in Fig. S1. Sterility was verified by homogenizing a subset of eggs for LB agar plating and 16S rRNA PCR analysis (Fig. S2) [5]. Four-day-old larvae were used for all subsequent experiments. Experimental design for BSFL bioconversion The full-scale BSFL bioconversion project for organic waste treatment was established by the HangZhou GuSheng Biotechnology Co., Ltd. (30° 24′ 10.8″ N, 120° 09′ 43.3″ E) (Hangzhou, China). Food waste collected from the vicinity of the company was subjected to proper pretreatment and subsequently used for BSFL feeding (larvae treatment, LT) [39]. An identical batch of organic waste without the addition of BSFL was simultaneously established as a control (natural composting, NC). To better highlight the microbial recruitment capacity of BSFL rather than the influence of substrate-derived microbes, two additional experiments using chicken manure and bean dregs were conducted. For the laboratory BSFL bioconversion experiment, 50 4-day-old larvae were introduced into 50 g of diet under five treatment conditions: (i) SF (sterilized feed without larvae); (ii) NF (non-sterilized feed without larvae); (iii) SF + GF (sterilized feed with germ-free larvae); (iv) NF + GF (non-sterilized feed with germ-free larvae); and (v) NF + CL (non-sterilized feed with conventional larvae). The experimental units were maintained in a climate-controlled chamber at 28 ± 1 ℃ and 70%–80% relative humidity for 14 days. Each treatment was performed in two independent experiments with three biological replicates per experiment (n = 6 in total). The diet for axenic treatments was autoclaved (121 °C, 20 min) before use, whereas the diet for conventional treatments was not sterilized. Samples Substrate samples were periodically collected from LT and NC every 2 days, starting from day 0. Collect BSFL gut samples after dissection (larvae gut, LG) [15]. Transfer BSFL raised on experimental diet to fresh experimental diet supplemented with 0.5% (w/w) bromophenol blue. Before dissection, BSFL were surface-sterilized by immersion in 75% ethanol for 3 min and rinsed three times in axenic phosphate-buffered saline buffer (pH 7.4). The whole gut was carefully dissected and stretched out with flame-sterilized tools, then cut into three regions for RNA and DNA extraction: (1) anterior midgut (AM); (2) middle midgut (MM); and (3) posterior midgut (PM) (Fig. S3) [37]. Gut bacterial cultures and quantification Dissected samples of the three gut regions from approximately 30 BSFL were homogenized in 1 mL of axenic phosphate-buffered saline for 60 s using a burnisher at 70 Hz. An aliquot from these samples was serially diluted and plated onto Luria–Bertani nutrient agar plates. After incubation at 30 ℃ for 24–48 h, individual and morphologically distinct colonies were morphologically counted for colony-forming units (CFUs). Confocal microscopy Midguts of BSFL were dissected in sterile PBS and divided into three regions: anterior (AM), middle (MM), and posterior (PM). Each segment was fixed in 4% paraformaldehyde (PFA) at 4 °C overnight, washed twice in PBS, and treated with lysozyme (10 mg mL⁻1 in 0.1 M Tris–HCl, 0.05 M EDTA, pH 7.5) at 37 °C for 30 min to permeabilize bacterial cell walls. After two PBS washes, tissues were incubated in 0.1% Triton X-100 for 30 min at room temperature and equilibrated in hybridization buffer (0.9 M NaCl, 20 mM Tris–HCl pH 7.2, 0.01% SDS, 35% formamide). FISH was performed overnight at 46 °C using a 16S rRNA universal probe (EUB338 mix, 5′-GCTGCCTCCCGTAGGAGT-3′) labeled with Alexa Fluor 555 (orange; excitation 561 nm, emission 570–620 nm). After hybridization, samples were washed, counterstained with DAPI (10 µg mL⁻1; excitation 405 nm, emission 420–480 nm) for 30 min, and mounted in anti-fade medium. Imaging was performed on a Zeiss LSM 800 using sequential acquisition to avoid bleed-through (AF555, 561 nm laser; DAPI, 405 nm laser). Z-stacks were collected at 4 µm steps and processed in ZEN; overlays are shown with AF555 in orange and DAPI in blue. Substrate physicochemical properties and lignocellulose contents analysis After 14 days of bioconversion, BSFL and substrates were separated and weighed. Following the experimental manual [40], temperature was measured 5–8 cm below the substrate surface and in the greenhouse using a kerosene thermometer. Moisture content was determined by drying samples at 105 °C for 12 h. pH was measured in a 1:10 (w/v) deionized water extract using a pH meter (PHB-4, China). Total carbon (TC) and total nitrogen (TN) were measured using an elemental analyzer (Vario EL Cube, Elementar, Germany). Lignocellulose content was determined using Van Soest’s method [39]. The data used in Fig. S4 were previously published in our earlier study [39]. The data are reused here under permission from Elsevier (6,145,821,149,305). Assay of lignocellulose-degrading enzymes The activities of cellulase, β-glucosidase (β-GC), acidic xylanase (ACX), α-L-arabinofuranosidase (α-L-Af), laccase, manganese peroxidase (MnP), and lignin peroxidase (LiP) were determined using commercial assay kits (Boxbio, China; Cat. Nos. AKSU043C, AKSU039C, AKSU048C, AKSU077C, AKAO018C, AKSU057C, and AKSU072U, respectively) following the manufacturer’s protocols. Briefly, gut tissues and substrate were homogenized with the extraction buffer supplied in each kit. The homogenates were centrifuged at 10,000 × g for 10 min at 4 °C, and the supernatants were used for analysis. Absorbance was measured using a visible or UV spectrophotometer at the specific detection wavelengths: 540 nm for cellulase and ACX, 400 nm for β-GC and α-L-Af, 420 nm for laccase, 465 nm for MnP, and 310 nm for LiP. Nucleic acid extraction Genomic DNA was extracted using the QIAamp® PowerFecal® DNA Kit (QIAGEN, Germany) following the manufacturer’s protocol. DNA concentration and purity were assessed with a TBS-380 fluorometer (Turner Biosystems, USA) and an ND-2000 spectrophotometer (Thermo Fisher Scientific, USA). DNA integrity was confirmed by electrophoresis on 1% (w/v) agarose gels. Total RNA was extracted from tissue using TRIzol® Reagent (Thermo Fisher Scientific) according to the manufacturer’s instructions. RNA quality was evaluated with a 5300 Bioanalyzer (Agilent), and quantity measured using the ND-2000. Only high-quality RNA (OD260/280 = 1.8–2.2, OD260/230 ≥ 2.0, RQN ≥ 6.5, 28S:18S ≥ 1.0, yield > 1 µg) was used for library construction. Quantitative PCR analysis of host genes Total RNA was extracted from dissected AM, MM, and PM tissues of larvae using TRIzol reagent (Accurate Biology, China) following the manufacturer’s instructions. First-strand cDNA was synthesized from 1 µg of total RNA using the RT SuperMix (Accurate Biology, China). Quantitative PCR was performed with SYBR qPCR Master Mix (Accurate Biology, China) on an FMR3 Real-Time PCR System (Vazyme, China). The expression of host immune-related, antimicrobial peptide, and glycosylation-associated genes was quantified using gene-specific primers listed in Supplementary Table S2. TBP and RP49 were used as internal reference genes. Relative expression levels were calculated using the 2−ΔΔCt method. Each gut region was analyzed using eight independent biological samples (n = 8). Library preparation and sequencing The V3–V4 hypervariable region of the bacterial 16S rRNA gene was amplified using primers 338 F (5′-ACTCCTACGGGAGGCAGCAG-3′) and 806R (5′-GGACTACHVGGGTWTCTAAT-3′) [41] on an ABI GeneAmp® 9700 PCR thermocycler (ABI, USA). Amplicons were extracted from 2% agarose gels, purified with the AxyPrep DNA Gel Extraction Kit (Axygen, USA), and quantified using a Quantus™ Fluorometer (Promega, USA). Purified products were pooled in equimolar ratios and sequenced on an Illumina MiSeq PE300 or NovaSeq PE250 platform (Illumina, USA). For metagenomic, Genomic DNA was fragmented to ~ 400 bp using Covaris M220 (Gene Company Limited, China) for paired-end library preparation with the NEXTFLEX Rapid DNA-Seq Kit (Bioo Scientific, USA). Adapters were ligated to blunt-ended fragments, and libraries were sequenced on an Illumina NovaSeq 6000 platform. Transcriptome libraries were prepared from 1 µg of total RNA using the Illumina® Stranded mRNA Prep, Ligation protocol. Poly(A) + mRNA was isolated with oligo beads, fragmented, and reverse-transcribed to cDNA using the SuperScript kit (Invitrogen, USA) with random hexamer primers. The cDNA was end-repaired, A-tailed, adapter-ligated, and size-selected (~ 300 bp) on 2% Low Range Ultra Agarose. Libraries were amplified with Phusion DNA polymerase (NEB) for 15 cycles, quantified with Qubit 4.0, and sequenced on an Illumina NovaSeq X Plus platform. 16S rRNA data analysis After demultiplexing, the resulting sequences were quality filtered with fastp (0.19.6) [42] and merged with FLASH (v1.2.11) [43]. Then the high-quality sequences were de-noised using the DADA2 [4] plugin in the Qiime2 [44] (version 2020.2) pipeline with recommended parameters, which obtains single nucleotide resolution based on error profiles within samples. DADA2 denoised sequences are usually called amplicon sequence variants (ASVs). To minimize the effects of sequencing depth on alpha and beta diversity measure, the number of sequences from each sample was rarefied to 20,000, which still yielded an average Good’s coverage of 97.90%. Taxonomic assignment of ASVs was performed using the Naive bayes consensus taxonomy classifier implemented in Qiime2 and the SILVA 16S rRNA database (v138). Metagenome assembly and analysis Paired-end Illumina reads were adapter-trimmed and quality-filtered using fastp, removing reads < 50 bp, with quality < 20, or containing Ns. Host-derived sequences were filtered by aligning to the Hermetia illucens genome using BWA [45], and mapped reads were discarded. Clean reads were assembled with MEGAHIT [46] using succinct de Bruijn graphs; contigs ≥ 300 bp were retained for downstream analysis. Open reading frames (ORFs) were predicted using Prodigal or MetaGene, and ORFs ≥ 100 bp were translated using the NCBI translation table. A non-redundant gene catalog was generated using CD-HIT (v4.6.1) with 90% identity and coverage thresholds. Gene abundance was calculated by aligning high-quality reads to the catalog using SOAPaligner (v2.21) with 95% identity. Functional annotation of representative genes was performed using DIAMOND (v2.21) [47] against the NCBI NR database (taxonomy), eggNOG (COG), and KEGG (metabolism) using an e-value cutoff of 1e − 5. Carbohydrate-active enzymes (CAZymes) were annotated using HMMER against the CAZy database with the same threshold. The data used in Fig. S7 were previously published in our earlier study [39]. The data are reused here under permission from Elsevier (6,145,821,149,305). Metagenomic binning Quality-filtered metagenomic reads were co-assembled using MEGAHIT v1.2.9 with default parameters. Contigs ≥ 1000 bp were binned using MetaBAT2 v2.15, MaxBin2 v2.2.7, and CONCOCT v1.1.0, and the non-redundant consensus bins were refined with DAS Tool v1.1.2. The quality of MAGs was assessed using CheckM v1.2.1, and only bins with completeness ≥ 50% and contamination ≤ 10% were retained for downstream analyses. Taxonomic classification was assigned using GTDB-Tk v2.1.1 (https://ecogenomics.github.io/GTDBTk/) against the GTDB r214 reference database. Gene prediction was performed using Prodigal v2.6.3, and functional annotation was based on KEGG, COG, and CAZy databases. The quality and assembly statistics of all reconstructed MAGs are summarized in Supplementary Table S3. Functional scoring of MAGs Functional potential at the genome level was estimated based on CAZy annotations. For lignocellulose degradation, glycoside hydrolase (GH) and auxiliary activity (AA) families were assigned to cellulase, hemicellulase, and lignin-degrading categories according to established catalytic functions (Table S4), and MAG-level scores were calculated as the total number of genes within each category. Community-level functional potential was calculated as an abundance-weighted score, defined as the sum of each MAG’s functional score multiplied by its relative abundance. For glycan-cleavage potential, GH families targeting galactose-, glucuronic acid-, fucose-, and mannose-containing glycans were curated based on experimentally characterized enzyme activities and substrate specificity (Table S5). Core families with well-defined specificity were prioritized, while additional families with broader activities were included cautiously. Glycan-cleavage scores were calculated for each MAG as the sum of gene counts assigned to the selected families, and abundance-weighted scores were computed using the same approach. Differential gene expression analysis For host transcriptome analysis, raw reads were quality-filtered using fastp (v0.23.4) and aligned to the Hermetia illucens reference genome (NCBI Assembly GCF_905115235.1; Bioproject PRJEB37575) using HISAT2 (v2.2.1). Gene models were retrieved from the corresponding NCBI annotation, and candidate immune genes were extracted based on functional annotations associated with PGRP domains or antimicrobial peptide signatures. Gene expression levels were quantified with RSEM [48] after read mapping, and raw counts were imported into DESeq2 (v1.36.0) for differential expression analysis. Unless otherwise specified, all software was run with default parameters. Differentially expressed genes were identified based on normalized expression (TPM), and functional enrichment of DEGs was assessed using GOATOOLS and Python SciPy for Gene Ontology (GO) and KEGG pathways, with Bonferroni-corrected p < 0.05 as the significance threshold. In addition to pathway-level functional annotation, protein domain architecture of selected PGRPs was examined using the SMART database based on predicted protein sequences retrieved from NCBI. Results BSFL depend on recruited symbionts for lignocellulose degradation In a full-scale BSFL bioconversion system, measurement of lignocellulose content (Fig. S4) showed that BSFL first caused a relative concentration of lignocellulose in the substrate due to the depletion of easily degradable components, and then degraded 25.4% of it—specifically, 41.5% of cellulose, 12.5% of hemicellulose, and 19.6% of lignin. Through laboratory BSFL bioconversion (Fig. 1A), we found that axenic BSFL degraded the experimental diet 44.3% more efficiently than in situ microorganisms. Non-axenic BSFL further improved degradation by 11.5%. Notably, feeding axenic BSFL with a non-axenic diet restored their degradation rate. The final mass and conversion rate of axenic BSFL were 0.11 ± 0.007 g/larva and 0.57 ± 0.025 g/g dry matter (Fig. 1B–D), while non-axenic BSFL showed 57.6% and 41.1% increases, respectively. This growth was also recoverable through non-axenic feeding.Fig. 1Effects of microbial colonization on larval performance and lignocellulose degradation during BSFL bioconversion. A Schematic illustration of the experimental workflow. Dry matter reduction rate (B), larval mass (C), larval conversion rate (D), cellulose degradation rate (E), hemicellulose degradation rate (F), and lignin degradation rate across different experimental groups (G). H Activities of key lignocellulose-degrading enzymes in gut and substrate. (cellulase, β-glucosidase (β-GC), acidic xylanase (ACX), α-L-arabinofuranosidase (α-L-Af), laccase, manganese peroxidase (MnP), and lignin peroxidase (LiP)) Different letters denote significant differences (p < 0.05) among groups for lignocellulose degradation rates. Experimental groups include SF (sterilized feed without larvae), NF (non-sterilized feed without larvae), SF + GF (sterilized feed with germ-free larvae), NF + GF (non-sterilized feed with germ-free larvae), and NF + CL (non-sterilized feed with conventional larvae), n = 6 Effects of microbial colonization on larval performance and lignocellulose degradation during BSFL bioconversion. A Schematic illustration of the experimental workflow. Dry matter reduction rate (B), larval mass (C), larval conversion rate (D), cellulose degradation rate (E), hemicellulose degradation rate (F), and lignin degradation rate across different experimental groups (G). H Activities of key lignocellulose-degrading enzymes in gut and substrate. (cellulase, β-glucosidase (β-GC), acidic xylanase (ACX), α-L-arabinofuranosidase (α-L-Af), laccase, manganese peroxidase (MnP), and lignin peroxidase (LiP)) Different letters denote significant differences (p < 0.05) among groups for lignocellulose degradation rates. Experimental groups include SF (sterilized feed without larvae), NF (non-sterilized feed without larvae), SF + GF (sterilized feed with germ-free larvae), NF + GF (non-sterilized feed with germ-free larvae), and NF + CL (non-sterilized feed with conventional larvae), n = 6 Degradation by both in situ microbes and axenic BSFL did not differ significantly from the control (p > 0.05; Fig. 1E–G), confirming that neither group can degrade lignocellulose. In contrast, CL achieved a 33.3% degradation rate, with cellulose, hemicellulose, and lignin degradation at 43.9%, 23.2%, and 42.4%, respectively. Again, NF restored lignocellulose degradation in GF. To quantify enzymatic contributions during bioconversion, we measured key cellulolytic and ligninolytic enzyme activities in larval guts and substrate residues across treatments (Fig. 1G). Axenic larval guts displayed only minimal activities for cellulase, β-glucosidase (β-GC), ACX, α-L-arabinofuranosidase (α-L-AF), laccase, Mn-peroxidase (Mnp), and lignin peroxidase (LiP). Conventional larval guts showed markedly higher activities for all measured enzymes. In the substrate, normal feed without larvae exhibited only baseline activity, whereas feed incubated with larvae showed substantially elevated cellulolytic and ligninolytic enzyme activities. Selective enrichment of core gut microbiota during substrate conversion Across three substrates (bean dregs, chicken manure, and food waste), gut and substrate microbiota exhibited clear differences in both diversity and community structure (Fig. 2A). α-diversity analyses showed that Chao1 richness was consistently higher in substrates than in gut samples, and Simpson diversity was also lower in gut communities across all substrates (Fig. 2B). PCoA and constrained PCoA confirmed that gut microbiota differed significantly from those in substrates and residues (Fig. 2C, S5), suggesting that the gut acts as a selective filter.Fig. 2Gut and substrate microbiota exhibit distinct diversity patterns, community structures, and key genera across diets. A Schematic illustration of the experimental workflow. B Alpha-diversity comparison between gut and substrate microbiota under three diets (bean dregs, chicken manure, food waste). C Constrained PCoA (CPCoA) showing distinct clustering of substrate and gut microbial communities. D Stacked-bar relative abundance profiles at the phylum level for all gut and substrate samples. E Relative abundance of the five dominant phyla (Actinobacteriota, Bacteroidota, Firmicutes, Fusobacteriota, Proteobacteria) in gut and substrate. Group differences were tested using Wilcoxon rank-sum tests after BH correction. F Random Forest analysis identifying key genera distinguishing gut microbiota from substrate microbiota; top feature genera ranked by mean decrease in accuracy. Wilcoxon test was applied for pairwise comparisons (ns, not significant; *p < 0.05) Gut and substrate microbiota exhibit distinct diversity patterns, community structures, and key genera across diets. A Schematic illustration of the experimental workflow. B Alpha-diversity comparison between gut and substrate microbiota under three diets (bean dregs, chicken manure, food waste). C Constrained PCoA (CPCoA) showing distinct clustering of substrate and gut microbial communities. D Stacked-bar relative abundance profiles at the phylum level for all gut and substrate samples. E Relative abundance of the five dominant phyla (Actinobacteriota, Bacteroidota, Firmicutes, Fusobacteriota, Proteobacteria) in gut and substrate. Group differences were tested using Wilcoxon rank-sum tests after BH correction. F Random Forest analysis identifying key genera distinguishing gut microbiota from substrate microbiota; top feature genera ranked by mean decrease in accuracy. Wilcoxon test was applied for pairwise comparisons (ns, not significant; *p < 0.05) Phylum-level comparisons (Fig. 2D and E) showed strong enrichment of Bacteroidota in the gut and significantly higher levels of Firmicutes and Proteobacteria in the substrates. Actinobacteriota and Fusobacteriota exhibited no consistent differences between gut and substrate communities. At the family and genus levels (Fig. S6), gut samples were enriched in Lactobacillaceae, Dysgonomonadaceae, and Brevibacteriaceae, with dominant genera such as Lactobacillus, Dysgonomonas, and Weissella. In contrast, substrate samples showed higher abundances of Moraxellaceae, Enterobacteriaceae, and Paenibacillaceae, with genera including Acinetobacter, Aerococcus, and Paenibacillus. To identify taxa most strongly associated with gut communities, we applied a Random Forest classifier (Fig. 2F). The model achieved low cross-validation error with a small number of genera and highlighted Dysgonomonas, Actinomyces, Acinetobacter, Sphingobacterium, and Flavobacterium as the top contributors distinguishing gut communities from their corresponding substrates. These taxa represent reproducibly enriched gut members across different diets. Enrichment of carbohydrate-active functions in the gut microbiome of BSFL Given BSFL’s lack of endogenous lignocellulolytic activity (Fig. 1), we performed metagenomic sequencing on the food waste group to characterize the functional traits of associated microbiota. PCoA based on carbohydrate metabolism and glycan biosynthesis pathways revealed clear separation between gut and substrate microbiota, with PCoA1 explaining 83.1% and 74.5% of the variance, respectively (Fig. 3A–B), indicating substantial functional divergence. CAZy analysis showed that the gut microbiome contained 1.35–2.45 times more CAZy genes than the substrate, mainly due to enriched GHs (Fig. S7). In the NC, CAZy gene profiles remained essentially stable over time. The small fluctuations observed were within the range of stochastic variation in the native substrate microbiota and did not reflect any directional or biologically meaningful change.Fig. 3Functional divergence of carbohydrate and glycan metabolism between gut and substrate microbiota in BSFL bioconversion. A Principal coordinates analysis (PCoA) of carbohydrate metabolism and glycan biosynthesis pathways based on metagenomic profiles. B Relative abundance (TPM) of representative metabolic pathways significantly enriched in the gut microbiota. C Heatmap of glycoside hydrolase gene abundance differentiating gut and substrate microbiota. Groups were compared using ANOVA followed by Tukey’s test, with significant differences indicated (***p < 0.001; n.s., not significant) Functional divergence of carbohydrate and glycan metabolism between gut and substrate microbiota in BSFL bioconversion. A Principal coordinates analysis (PCoA) of carbohydrate metabolism and glycan biosynthesis pathways based on metagenomic profiles. B Relative abundance (TPM) of representative metabolic pathways significantly enriched in the gut microbiota. C Heatmap of glycoside hydrolase gene abundance differentiating gut and substrate microbiota. Groups were compared using ANOVA followed by Tukey’s test, with significant differences indicated (***p < 0.001; n.s., not significant) Four carbohydrate-related pathways were significantly enriched in the gut (p < 0.001): fructose and mannose metabolism, galactose metabolism, glycosaminoglycan degradation, and other glycan degradation (Fig. 3B). Glycoside hydrolases profiling revealed a diverse array of enzymes targeting celluloses, hemicelluloses, pectins, and host glycans, such as β-N-acetylhexosaminidase and α-L-fucosidase (Fig. 3C). The detection of enzymes such as chitinase, pullulanase, cyclomaltodextrinase, and α-/β-glucosidases further underscores the metabolic versatility of gut-associated microbes in deconstructing structurally diverse carbohydrates. Functional–taxonomic mapping further revealed that these CAZyme genes were primarily affiliated with Dysgonomonas, Corynebacterium, Enterococcus, and Lactobacillus, which together dominated GH, CE, and AA families (Supplementary Fig. S8). This division of enzymatic labor suggests that the BSFL gut community integrates complementary functional capacities across distinct bacterial guilds, collectively enhancing lignocellulose depolymerization efficiency. Compartmentalized microbial composition in the BSFL midgut To investigate spatial variation in gut microbiota, the midgut of BSFL was divided AM, MM, and PM regions [37] (Fig. 4A). The PM exhibited the highest relative bacterial load among the three gut segments, over three times greater than AM and MM (p < 0.001; Fig. 4B–C). Despite its smaller size, AM still contained significantly more bacteria than MM (p < 0.01). When normalized by tissue mass, AM and PM showed comparable bacterial densities, whereas MM remained significantly lower (Fig. 4D), revealing a consistent spatial enrichment pattern across gut regions. Although CFU counts represent only the culturable fraction of the microbiota, the FISH validation using a 16S rRNA universal probe (EUB338 labeled with AF555) revealed a consistent spatial pattern—dense microbial signals in the PM and AM but sparse fluorescence in the MM (Fig. 4E)—supporting the reliability of these relative estimates and confirming the spatial heterogeneity in bacterial distribution along the gut axis.Fig. 4Spatial heterogeneity of gut microbiota and bacterial load along the intestinal compartments of black soldier fly larvae (BSFL) midgut. A Dissection schematic of the BSFL gut showing the foregut, anterior midgut (AM), middle midgut (MM), posterior midgut (PM), and hindgut. B Relative mass of each gut compartment (mean ± S.E.M.; n = 6). Colony-forming units (CFUs) per larva (C) and relative CFU load across AM, MM, and PM segments determined by plate cultivation (D). E Fluorescence in situ hybridization (FISH) using a 16S rRNA universal probe (EUB338 labeled with AF555, orange) together with DAPI nuclear counterstain (blue; 405—nm channel). F Alpha-diversity indices (Chao1 and Simpson) based on 16S rRNA gene sequencing (*p < 0.05, **p < 0.01, ***p < 0.001; Wilcoxon test). G Principal coordinate analysis (PCoA) based on Bray–Curtis distances showing distinct clustering of microbiota among AM, MM, and PM compartments (R = 0.6678, p < 0.001; PERMANOVA). H Relative abundance of dominant bacterial phyla and (I) major genera in each gut compartment Spatial heterogeneity of gut microbiota and bacterial load along the intestinal compartments of black soldier fly larvae (BSFL) midgut. A Dissection schematic of the BSFL gut showing the foregut, anterior midgut (AM), middle midgut (MM), posterior midgut (PM), and hindgut. B Relative mass of each gut compartment (mean ± S.E.M.; n = 6). Colony-forming units (CFUs) per larva (C) and relative CFU load across AM, MM, and PM segments determined by plate cultivation (D). E Fluorescence in situ hybridization (FISH) using a 16S rRNA universal probe (EUB338 labeled with AF555, orange) together with DAPI nuclear counterstain (blue; 405—nm channel). F Alpha-diversity indices (Chao1 and Simpson) based on 16S rRNA gene sequencing (*p < 0.05, **p < 0.01, ***p < 0.001; Wilcoxon test). G Principal coordinate analysis (PCoA) based on Bray–Curtis distances showing distinct clustering of microbiota among AM, MM, and PM compartments (R = 0.6678, p < 0.001; PERMANOVA). H Relative abundance of dominant bacterial phyla and (I) major genera in each gut compartment Alpha diversity analysis showed the highest richness in MM (Chao index), while AM and PM had higher evenness (Simpson index; Fig. 4F). PCoA revealed clear compositional separation among segments (Fig. 4G), with PM forming a distinct cluster along PCoA1 (39.3% variance), and partial overlap between AM and MM. Taxonomic analysis revealed Firmicutes, Proteobacteria, Bacteroidetes, and Actinobacteria as the dominant phyla (Fig. 4H). Firmicutes were most abundant in AM (> 50%), followed by Proteobacteria, which peaked in MM. Bacteroidetes were enriched in PM (~ 20%), contrasting with their low abundance in AM and MM. At the genus level (Fig. 4I), Klebsiella and Weissella dominated AM and MM, while Pediococcus was highly abundant in AM (22.5%) but nearly absent in MM and PM. In contrast, Dysgonomonas and Enterococcus were selectively enriched in PM, with Dysgonomonas reaching 20% abundance. Kruskal–Wallis analysis confirmed significant differences across regions (Fig. S9). Cyanobacteria were enriched in MM, while Bacteroidota were specific to PM. Ten genera showed significant variation, with Enterococcus, Dysgonomonas, and Proteus notably enriched in PM. Spatial activation of the Imd pathway drives compartmentalized AMP expression To examine host regulation of gut symbionts, we profiled AMP expression across AM, MM, and PM. Seven PGRPs were detected, including both immune activators and negative regulators (Fig. 5A). Among the 48 antimicrobial peptide (AMP) genes detected, 28 genes (21 cecropins and 7 defensins) showed relatively high expression levels (TPM > 0.5) (Fig. 5B). All AMP genes detected in the transcriptome corresponded to distinct gene loci in the BSFL genome. Examination of exon–intron structures and transcript models in the NCBI GFF3 annotation revealed no shared isoforms, indicating that these AMPs are encoded by separate genes rather than splice variants. Both transcriptomic data and qPCR validation showed that cecropin expression was highest in the AM and significantly lower in the MM and PM. Defensin expression displayed a similar spatial trend, being higher in the AM and lower in the MM and PM, but significant differences among gut regions were detected only by qPCR, whereas the transcriptomic data did not reach significance (Fig. 5C, D). AMP expression showed a negative correlation with several PM-enriched taxa, including Koukoulia, Morganella, and Dysgonomonas (Fig. 5E). In axenic larvae, regional AMP differences disappeared, and cecropin expression in the AM dropped markedly compared with non-axenic larvae (Fig. S10 and S11).Fig. 5Spatial regulation of AMP expression and its association with gut microbiota composition. A Schematic overview of PGRP–Imd–AMP regulatory pathways detected in BSFL. B Heatmap showing transcript abundance (TPM, z-score scaled) of cecropin and defensin genes across the anterior midgut (AM), middle midgut (MM), and posterior midgut (PM). C Regional expression patterns of cecropin and defensin based on transcriptomic data. D qPCR validation of representative cecropin and defensin genes showing significantly higher AMP expression in the AM and reduced levels in the MM and PM. E Spearman correlations between AMP gene expression and dominant gut bacterial genera; dot size indicates significance (− lgp) and color indicates correlation coefficient Spatial regulation of AMP expression and its association with gut microbiota composition. A Schematic overview of PGRP–Imd–AMP regulatory pathways detected in BSFL. B Heatmap showing transcript abundance (TPM, z-score scaled) of cecropin and defensin genes across the anterior midgut (AM), middle midgut (MM), and posterior midgut (PM). C Regional expression patterns of cecropin and defensin based on transcriptomic data. D qPCR validation of representative cecropin and defensin genes showing significantly higher AMP expression in the AM and reduced levels in the MM and PM. E Spearman correlations between AMP gene expression and dominant gut bacterial genera; dot size indicates significance (− lgp) and color indicates correlation coefficient Activator PGRPs (PGRP-LA, LC, and LE) showed strong regional differentiation (Fig. 6A), with highest expression in the AM and significantly reduced levels in the MM and PM (to 15–67% of AM levels; Fig. 6B). In contrast, PGRP-SD showed no clear spatial variation. Among negative regulators, PGRP-LB displayed the highest overall expression and was strongly enriched in the PM, with 4.85- and 4.12-fold higher levels than in the AM and MM, respectively. PGRP-SC was almost exclusively expressed in the PM (Fig. 6B). Domain analysis of representative PGRP-LB-like and PGRP-SC-like proteins revealed the presence of conserved PGRP domains (SMART: smart00701), supporting their classification within the PGRP family (Table S6). These spatial patterns were further validated by qPCR of representative PGRP genes, which confirmed elevated expression of PGRP-LA, LC, and LE in the AM and strong enrichment of PGRP-LB and SC in the PM (Fig. 6C). In axenic larvae, PGRP-LA, LC, and LE were markedly downregulated in the AM (65–97% reduction), whereas PM expression of PGRP-LB and SC remained unchanged (Fig. S12 and S13). These results indicate that while activator PGRPs in the AM are responsive to microbial presence, the spatial enrichment of certain negative regulators in the PM is maintained even in the absence of microbiota. Notably, despite these region-specific patterns in PGRP expression, antimicrobial peptide expression did not exhibit corresponding spatial differences under axenic conditions (Fig. S10), suggesting that regional variation in PGRP expression alone is insufficient to drive downstream AMP activation without microbial stimulation. PGRP expression in the MM and PM showed no significant differences between axenic and non-axenic larvae.Fig. 6Spatial expression patterns of PGRP genes across BSFL gut regions. A Heatmap showing transcript abundance (TPM, z-score scaled) of PGRP genes across the anterior midgut (AM), middle midgut (MM), and posterior midgut (PM). B Expression levels of seven PGRP genes based on transcriptomic data, including immune activators (PGRP-LA, PGRP-LC, PGRP-LE, and PGRP-SD) and negative regulators (PGRP-LB and PGRP-SC). C qPCR validation of representative activator (PGRP-LA, PGRP-LC, PGRP-LE) and negative regulator (PGRP-LB, PGRP-SC) genes, confirming elevated AM expression of activators and strong PM enrichment of inhibitory PGRPs Spatial expression patterns of PGRP genes across BSFL gut regions. A Heatmap showing transcript abundance (TPM, z-score scaled) of PGRP genes across the anterior midgut (AM), middle midgut (MM), and posterior midgut (PM). B Expression levels of seven PGRP genes based on transcriptomic data, including immune activators (PGRP-LA, PGRP-LC, PGRP-LE, and PGRP-SD) and negative regulators (PGRP-LB and PGRP-SC). C qPCR validation of representative activator (PGRP-LA, PGRP-LC, PGRP-LE) and negative regulator (PGRP-LB, PGRP-SC) genes, confirming elevated AM expression of activators and strong PM enrichment of inhibitory PGRPs Compartmentalized transcriptional patterns of O- and N-glycan biosynthetic enzymes To investigate this mechanism by which host-secreted glycans serve as key carbon sources for gut microbes, we profiled the transcription of genes involved in both O- and N-glycosylation across three distinct midgut compartments in the axenic BSFL. To assess regional O-glycosylation, we analyzed the expression of Galnt, C1galt1, and GlcAT-P (Fig. 7A). Galnt showed no significant regional differences, whereas C1galt1 and GlcAT-P were significantly upregulated in the PM compared with the AM and MM (Fig. 7B). qPCR validation confirmed these patterns, showing uniform Galnt expression and PM-biased expression of C1galt1 and GlcAT-P isoforms (Fig. 7C).Fig. 7Regional expression of O-glycan biosynthetic enzymes in the BSFL midgut. A Schematic representation of the O-glycan biosynthetic pathway involving Galnt, C1galt1, and GlcAT-P. B Transcriptomic expression (TPM) of Galnt, C1galt1, and GlcAT-P across the anterior midgut (AM), middle midgut (MM), and posterior midgut (PM). C qPCR validation of representative Galnt, C1galt1, and GlcAT-P isoforms Regional expression of O-glycan biosynthetic enzymes in the BSFL midgut. A Schematic representation of the O-glycan biosynthetic pathway involving Galnt, C1galt1, and GlcAT-P. B Transcriptomic expression (TPM) of Galnt, C1galt1, and GlcAT-P across the anterior midgut (AM), middle midgut (MM), and posterior midgut (PM). C qPCR validation of representative Galnt, C1galt1, and GlcAT-P isoforms To characterize regional N-glycosylation, we examined the expression of key trimming and modification enzymes in the BSFL gut, including the OST catalytic subunit STT3, glucose-removing enzymes MOGS and GANAB, mannosidases MAN1A, MAN1B, MAN2, the GlcNAc-transferase MGAT1, core fucosyltransferases FUT8 and FUT11, and the GlcNAc-removing enzyme FDL (Fig. 8A). Transcriptomic data showed that several genes, including STT3, MAN1A, MAN2, MGAT1, FUT8, and FUT11, were significantly upregulated in the PM compared with the AM and MM (Fig. 8B). MAN1B exhibited an increasing trend without statistical significance, while FDL showed a decreasing trend in the PM. These results indicate an overall enhancement of N-glycan processing and core fucosylation in the PM. qPCR validation supported these trends: MAN1A, MAN1B, MAN2, MGAT1, FUT8, FUT11, and FDL showed consistently higher expression in the PM, whereas STT3 and MOGS displayed relatively uniform levels across gut regions (Fig. 8C). Together, these data indicate a compartmentalized enhancement of N-glycan maturation and fucosylation in the PM.Fig. 8Regional expression of N-glycan processing enzymes in the BSFL midgut. A Overview of the N-glycan processing pathway, including the OST catalytic subunit STT3; glucose-trimming enzymes (MOGS and GANAB); mannosidases (MAN1A, MAN1B, MAN2); the GlcNAc-transferase MGAT1; core fucosyltransferases (FUT8 and FUT11); and the GlcNAc-removing enzyme FDL. B Transcriptomic expression (TPM) of N-glycan enzymes across the anterior midgut (AM), middle midgut (MM), and posterior midgut (PM), showing PM-enriched expression of multiple enzymes involved in N-glycan trimming, maturation, and core fucosylation. C qPCR validation of representative isoforms, confirming PM-biased expression of MAN1A/B, MAN2, MGAT1, FUT8, FUT11, and FDL, and relatively uniform expression of STT3 and MOGS across gut regions Regional expression of N-glycan processing enzymes in the BSFL midgut. A Overview of the N-glycan processing pathway, including the OST catalytic subunit STT3; glucose-trimming enzymes (MOGS and GANAB); mannosidases (MAN1A, MAN1B, MAN2); the GlcNAc-transferase MGAT1; core fucosyltransferases (FUT8 and FUT11); and the GlcNAc-removing enzyme FDL. B Transcriptomic expression (TPM) of N-glycan enzymes across the anterior midgut (AM), middle midgut (MM), and posterior midgut (PM), showing PM-enriched expression of multiple enzymes involved in N-glycan trimming, maturation, and core fucosylation. C qPCR validation of representative isoforms, confirming PM-biased expression of MAN1A/B, MAN2, MGAT1, FUT8, FUT11, and FDL, and relatively uniform expression of STT3 and MOGS across gut regions Compartmentalized profiles of glycan and carbohydrate metabolism To characterize regional functional specialization, we compared CAZy gene profiles between non-PM and PM microbiota (Fig. 9A). Auxiliary activities (AA), carbohydrate-binding modules (CBM), and carbohydrate esterases (CE) were significantly enriched in the PM (p < 0.0001–0.01), whereas GH, GT, and PL families showed no differences. Pathway annotation further revealed PM-enriched glycan-related functions and higher activity in pentose/glucuronate and galactose metabolism (Fig. 9B). Correspondingly, multiple carbohydrate-active enzymes—including β-/α-glucosidases, β-galactosidase, and xylan 1,4-β-xylosidase—were more abundant in the PM (Fig. 9C). Enzyme activity assays further supported this pattern: cellulase, β-GC, ACX, α-L-AF, laccase, Mn-peroxidase, and LiP activities were all significantly higher in the PM than in the AM and MM (Fig. 9D). These results indicate a pronounced posterior midgut specialization in carbohydrate-processing capacity, including enriched potential for lignocellulose degradation.Fig. 9Spatial differentiation of carbohydrate-active enzymes and lignocellulolytic activities along the BSFL midgut. A CAZy gene families enriched in the PM, including AA, CBM, and CE; GH, GT, and PL showed no regional differences. B PM microbiota showed higher abundance of glycan-related and carbohydrate-metabolism pathways. C Polysaccharide-degrading enzymes (e.g., β-/α-glucosidases, β-galactosidase, xylanase) were more abundant in the PM. D Enzyme assays confirmed elevated cellulase, β-GC, ACX, α-L-Af, laccase, MnP, and LiP activities in the PM Spatial differentiation of carbohydrate-active enzymes and lignocellulolytic activities along the BSFL midgut. A CAZy gene families enriched in the PM, including AA, CBM, and CE; GH, GT, and PL showed no regional differences. B PM microbiota showed higher abundance of glycan-related and carbohydrate-metabolism pathways. C Polysaccharide-degrading enzymes (e.g., β-/α-glucosidases, β-galactosidase, xylanase) were more abundant in the PM. D Enzyme assays confirmed elevated cellulase, β-GC, ACX, α-L-Af, laccase, MnP, and LiP activities in the PM Spatially resolved functional coupling of CAZy and glycan metabolism in MAGs To elucidate the functional architecture of the gut microbiota, we performed genome-resolved analyses based on metagenome-assembled genomes (MAGs). A total of 22 high-quality MAGs were recovered and taxonomically classified using GTDB-Tk, belonging to 8 families dominated by Enterococcaceae, Morganellaceae, and Lactobacillaceae, consistent with major taxa identified in both 16S rRNA and metagenomic profiles, suggesting that they represent core members of the BSFL gut microbiota (Table S3). Across MAGs, CAZy gene abundance was strongly and positively correlated with glycan metabolism pathways (R2 = 0.81, p < 0.001; Fig. S14), indicating coordinated enrichment of carbohydrate-processing and glycan-utilization functions. MAGs enriched in glycoside hydrolases and auxiliary activities frequently encoded enzymes such as β-glucuronidase and α-iduronidase, while those with expanded carbohydrate esterase and GH families showed enhanced capacities for galactose and amino sugar metabolism (Fig. S14). At the community level, MAG relative abundances varied across gut compartments, and although most individual MAGs did not exhibit significant differences between non-PM and PM groups (Fig. 10A), notable exceptions were observed, including MAG9, which showed significant enrichment in the PM. To quantify functional differences, abundance-weighted scores based on CAZy annotations were calculated, with CAZy families systematically classified into cellulase-, hemicellulase-, and lignin-associated enzyme groups according to their established catalytic functions (Table S4). The PM group exhibited significantly higher cellulose (p = 0.0081) and hemicellulose (p = 0.036) degradation potential, whereas lignin-associated functions showed no significant difference (p = 0.93) (Table S7) (Fig. 10B–D). The overall lignocellulose degradation potential showed an increasing trend but was not statistically significant (p = 0.055) (Fig. 10E). This PM-enriched MAG also encoded multiple glycoside hydrolase families associated with cellulose and hemicellulose degradation. In addition, a MAG affiliated with Lacrimispora xylanolytica contained multiple hemicellulose-degrading enzymes, consistent with its known xylanolytic capability, while MAGs assigned to Morganella morganii and Klebsiella spp. also encoded diverse CAZy families (e.g., GH5, GH10, GH43), suggesting potential roles in polysaccharide degradation. These observations indicate that lignocellulose-degrading capacity is not uniformly distributed across the microbial community but is instead associated with specific MAGs, particularly those enriched in the posterior midgut. To further link microbial function with host glycosylation patterns, glycan-cleavage potential was quantified for individual MAGs based on CAZy glycoside hydrolase families targeting galactose-, glucuronic acid-, fucose-, and mannose-containing glycans (Table S5). The PM microbiome showed significantly higher cleavage potential for galactose (p = 0.0043), fucose (p = 0.0043), and mannose (p = 0.0043), whereas glucuronic acid-associated functions did not differ significantly (p = 0.2468) (Table S8) (Fig. 10F–I).Fig. 10Genome-resolved functional characterization of lignocellulose degradation and glycan utilization in BSFL gut microbiota. A Relative abundance of metagenome-assembled genomes (MAGs) across gut compartments (non-PM and PM). Each point represents a sample, and boxplots summarize the distribution of log-transformed relative abundance for each MAG. B–E Abundance-weighted functional scores for lignocellulose degradation potential based on CAZy annotations, including cellulose (B), hemicellulose (C), lignin (D), and overall lignocellulose degradation (E). F–I Abundance-weighted glycan-cleavage potential of MAGs targeting specific sugar residues, including galactose (F), glucuronic acid (G), fucose (H), and mannose (I) Genome-resolved functional characterization of lignocellulose degradation and glycan utilization in BSFL gut microbiota. A Relative abundance of metagenome-assembled genomes (MAGs) across gut compartments (non-PM and PM). Each point represents a sample, and boxplots summarize the distribution of log-transformed relative abundance for each MAG. B–E Abundance-weighted functional scores for lignocellulose degradation potential based on CAZy annotations, including cellulose (B), hemicellulose (C), lignin (D), and overall lignocellulose degradation (E). F–I Abundance-weighted glycan-cleavage potential of MAGs targeting specific sugar residues, including galactose (F), glucuronic acid (G), fucose (H), and mannose (I) Discussion Efficient lignocellulose degradation by BSFL occurs on a markedly shorter timescale than conventional composting or vermicomposting, which typically requires 30–70 days to reach comparable degradation levels [49–51]. In our system, BSFL-mediated bioconversion achieved substantial lignocellulose breakdown within 2 weeks, underscoring the effectiveness of this host–microbiota system. Axenic larvae exhibited poor degradation and impaired growth, confirming that BSFL alone lack sufficient endogenous degradative capacity. Restoration of both development and lignocellulose degradation following microbial inoculation supports a facultative symbiosis in which microbial partners provide essential metabolic functions. Importantly, lignocellulose degradation occurred only when substrate-derived microbial communities were present, indicating that BSFL do not introduce external degraders but instead selectively recruit functional taxa from indigenous substrate microbiota [52, 53]. Although larval feeding may contribute limited mechanical fragmentation, multiple lines of evidence—including metagenomic CAZyme profiles and enzyme activity assays—indicate that native substrate microbiota alone possess negligible lignocellulose-degrading capacity compared with the BSFL gut community. The pronounced acceleration of lignocellulose decomposition in the presence of BSFL therefore reflects host-driven enrichment and activation of functional microbial consortia rather than physical processing alone. This observation is consistent with earlier reports showing that BSFL reshape substrate-associated microbiota [6, 39, 54], and our use of axenic larvae further demonstrates that this enrichment originates from indigenous microbes rather than exogenous sources. Across diverse waste substrates, BSFL guts displayed striking microbial convergence characterized by reduced α-diversity and strong separation from surrounding residues. Decreases in richness and diversity metrics indicate that most environmental microbes are excluded, while a limited set of specialized taxa is consistently retained. This host-driven filtering results in a core gut microbiota largely independent of substrate composition, dominated by genera such as Dysgonomonas, Morganella, and Anaerococcus. These findings support a model in which BSFL are associated with strong ecological selection to assemble a functionally coherent microbiome optimized for lignocellulose processing. Although the BSFL genome encodes some carbohydrate-active enzymes, it lacks key cellulolytic families required for efficient lignocellulose depolymerization, paralleling observations in other insects such as Protaetia brevitarsis [55]. Consistent with this pattern, BSFL gut microbiota exhibited pronounced enrichment of carbohydrate-active functions relative to substrate communities, particularly glycoside hydrolases involved in glycan metabolism. While CAZy families are not specific markers of lignocellulose degradation, their enrichment reflects a broader increase in carbohydrate-processing capacity and metabolic versatility. Such functional expansion likely supports both microbial growth and host energy acquisition, highlighting the BSFL gut microbiome as a reservoir of enzymes relevant to biomass conversion. Despite increasing interest in BSFL–microbiota interactions [56], spatial organization along the gut axis has remained poorly resolved [57]. Spatial differentiation of microbial communities (Fig. 4) was evident along the BSFL midgut, characterized by a pronounced decrease in microbial load from the AM to MM, followed by a marked increase in microbial abundance in the PM. Despite comparable tissue mass, the MM exhibited substantially reduced microbial colonization, suggesting the presence of a filtering process during gut transit [58]. In contrast, the PM harbored the highest bacterial load and a distinct community composition, suggesting that this region may provide a permissive niche for microbial persistence and enrichment. PCoA further confirmed that the PM microbiota was compositionally distinct from the AM and MM communities. Taxonomically, Bacteroidetes and Dysgonomonas were enriched in the PM, consistent with their roles in glycan metabolism [59] and carbohydrate use plus antimicrobial resilience [60], respectively. The similarity between the PM-enriched taxa and those found at the whole-gut level suggests the PM represents the primary site of symbiont enrichment and maintenance. Together, these results suggest that region-specific regulation of immunity and nutrient availability likely shapes a specialized microbiota that supports host digestion and waste bioconversion efficiency. Host tolerance of commensal microbiota while restricting potential pathogens is a central challenge of mucosal immunity. In metazoans, the gastrointestinal tract is spatially compartmentalized into regions with distinct immune properties and functional roles [61, 62]. Consistent with this principle, BSFL exhibited pronounced spatial compartmentalization of immune signaling along the midgut, as reflected by region-specific expression of PGRPs and AMPs. AMP production is primarily regulated by the Imd signaling pathway, whose activation is spatially constrained along insect guts [63, 64]. In BSFL, AMPs were highly expressed in the AM but markedly reduced in the MM and PM. In axenic larvae, this spatial expression pattern was largely abolished, suggesting that AMP activation in the AM is associated with microbial presence [65]. In contrast, the elevated expression of the negative regulators PGRP-LB and PGRP-SC in the PM was maintained under axenic conditions, suggesting that their regional expression is at least partly host-intrinsic rather than induced by resident microbiota, similar to immune compartmentalization reported in other insects [2, 66, 67]. Domain analysis further supported their classification as members of the PGRP family, which are widely reported as amidase-type regulators involved in modulation of Imd pathway activity. These observations support a model in which BSFL gut immunity is spatially structured, with strong immune activity in the AM and reduced immune activity in the PM, consistent with a functional separation between microbial exclusion and tolerance. Notably, the directionality of this relationship appears to be region-dependent: immune activation in the AM is closely associated with microbial presence, whereas immune attenuation in the PM shows a substantial host-intrinsic component. However, whether this spatial immune patterning directly drives microbiome assembly or is partly shaped by microbial colonization remains to be further determined. In addition, although AMP expression showed negative correlations with several PM-enriched taxa, no direct functional assays were performed to test their antibacterial activity. Therefore, the proposed role of AMPs in shaping microbial composition remains inferential and requires experimental validation, such as in vitro inhibition assays using representative isolates. Host mucin glycosylation is a well-established determinant of gut microbiota composition, as defects in glycosylation pathways markedly alter microbial communities across metazoans [28–30, 36, 68]. In BSFL, glycosylation-related genes exhibited pronounced region-specific expression along the midgut (Fig. 6), indicating spatially compartmentalized glycan synthesis. In this study, the elevated expression of O-glycosylation genes in the PM were validated, including Galnt and GlcAT-P, while N-glycosylation genes (STT/OST, FUT2, FUT8, ALG1/13/14) were upregulated in MM and PM. These spatially distinct glycan profiles are consistent with enhanced host glycan output in the PM and are associated with the presence of microbial taxa with corresponding glycan-degrading capacities. The concordance between host glycosylation patterns and microbial glycan metabolism suggests a coordinated pattern between host glycosylation and microbial functional potential that is consistent with functional compartmentalization of the BSFL gut. However, direct evidence linking specific glycan structures to taxon-level recruitment is worthy of investigation in future. Metagenomic analyses revealed that CAZy-encoding genes were most enriched in the posterior midgut (PM), accompanied by increased representation of glycoside hydrolase families and microbial glycan metabolism pathways (Fig. 9A). These pathways correspond to host-derived glycan substrates, including galactose, glucuronic acid, fucose, and mannose residues, suggesting a spatial coupling between host glycan availability and microbial functional potential. Similar glycan-mediated host–microbe interactions have been reported in Drosophila and mammals [3, 4, 69]. Consistently, metagenomic binning recovered 22 high-quality MAGs from the PM that co-encoded CAZy genes and glycan metabolism pathways (Table S5 and S8), indicating coordinated metabolic capacities within PM-enriched symbionts. Enzyme activity assays further supported elevated microbial activity in the PM, with higher activities of cellulase, β-glucosidase, ACX, α-L-arabinofuranosidase, laccase, MnP, and LiP compared with upstream gut regions (Fig. 9). However, because CAZy families and glycan metabolism pathways are not specific to lignocellulose degradation, these results alone cannot resolve whether the observed enrichment reflects functional specificity or a general increase in carbohydrate metabolism. To address this limitation, we performed genome-resolved analyses based on MAGs (Fig. 10). Functional quantification revealed that enrichment in the PM was selective rather than global: cellulose and hemicellulose degradation capacities were significantly increased, whereas lignin-associated functions remained unchanged (Fig. 10B–D). Similarly, glycan-cleavage potential showed selective enrichment, with higher capacities for galactose, fucose, and mannose, but no significant difference for glucuronic acid (Fig. 10F–I). This pattern argues against a non-specific increase in carbohydrate metabolism and instead supports selective functional enrichment. Notably, these functional capacities were associated with specific MAGs enriched in the PM, including MAG9, which encoded multiple glycoside hydrolase families linked to cellulose and hemicellulose degradation. This MAG-level evidence further supports that functional specialization is concentrated in a subset of symbionts rather than uniformly distributed across the microbial community (Fig. 11). The enriched sugar-targeting functions correspond to the predicted products of host O- and N-linked glycosylation, supporting a model in which host-derived glycans may contribute to the formation of selective nutrient niches that favor microorganisms capable of utilizing specific sugar residues. Together, these genome-resolved results support an association between microbial functional potential and host glycosylation patterns and refine the interpretation of metagenomic data beyond taxonomic associations.Fig. 11Mechanism of symbiont recruitment in larval gut Mechanism of symbiont recruitment in larval gut However, it should be noted that host responses were inferred from transcriptomic data rather than protein-level measurements, and no perturbation-based experiments were performed. Therefore, while the observed patterns support a coherent host–microbiota association, direct causal relationships remain to be established. Future studies integrating functional validation will be required to confirm these mechanisms. Collectively, these results are consistent with a spatially coordinated framework in which BSFL gut microbiota assembly is structured along the gut axis to facilitate lignocellulose bioconversion. The gut appears to operate through a two-step “Dismissing–then–Recruiting” strategy: strong Imd-dependent antimicrobial activity in the anterior midgut likely restricts non-beneficial microbes, whereas immune attenuation and glycan enrichment in the posterior midgut may be associated with the enrichment and persistence of carbohydrate-active symbionts. The consistent assembly of lignocellulolytic consortia across diverse waste substrates further supports a generalizable model of host-driven microbial filtering. Nevertheless, the molecular mechanisms underlying microbial sensing, glycan-mediated recruitment, and long-term symbiont retention remain unresolved [29]. In addition, direct experimental validation linking host responses with microbial composition and function will be required to establish causal relationships. Future studies integrating proteomic profiling, targeted manipulation of host glycosylation pathways, and microbiota reconstitution or gnotobiotic assays will be essential to directly test the specificity of host–microbe interactions and to identify key lignocellulose-degrading taxa involved in this process. Addressing these gaps will be critical for translating ecological insights into applied bioconversion systems [70]. Conclusions This study shows that black soldier fly larvae are associated with a functional gut microbiome structured along spatial immune and metabolic gradients, contributing to lignocellulose bioconversion. Rather than relying on endogenous degradative capacity, the host appears to selectively enrich indigenous microbial communities under gut compartment–specific immune conditions and glycan availability. Strong Imd-dependent antimicrobial activity in the anterior midgut likely restricts non-beneficial microbes, while immune attenuation and enhanced glycan availability in the posterior midgut may provide a permissive niche for carbohydrate-active symbionts. By integrating axenic experiments, metagenomics, metagenome-assembled genomes, and enzyme activity assays, we propose a “Dismissing–then–Recruiting” framework that explains how larvae consistently assemble lignocellulolytic consortia across diverse substrates. This spatial immune–metabolic coupling is consistent with a potentially generalizable strategy for microbiome assembly under environmental variability. Beyond advancing understanding of insect–microbe symbioses, these findings provide conceptual guidance for microbiota engineering, suggesting that targeted manipulation of host-derived substrates may provide a basis for the selective enrichment of functional microbial consortia for waste valorization and related biotechnological applications. Supplementary Information Supplementary Material 1. Supplementary Material 1.