The web application for LexBuild — a multi-source legal content browser serving the U.S. Code (54 titles, 60,000+ sections), eCFR (50 titles, 200,000+ sections), and Federal Register (770,000+ documents, 2000–present) as structured Markdown with syntax-highlighted source views.
Production: lexbuild.dev
| Layer | Technology |
|---|---|
| Framework | Astro 6 (SSR, @astrojs/node adapter) |
| Islands | React 19 via @astrojs/react |
| Styling | Tailwind CSS 4 via @tailwindcss/vite + @tailwindcss/typography |
| Components | shadcn/ui (Radix primitives, radix-nova preset, zinc theme) |
| Syntax Highlighting | Shiki 4 (pre-rendered HTML, runtime fallback for dev) |
| Markdown | unified + remark + rehype pipeline with rehype-sanitize |
| Sidebar | @tanstack/react-virtual for virtualized section lists |
| Search | Meilisearch (~1.05M docs, gated behind ENABLE_SEARCH) |
| Fonts | IBM Plex Sans (body) / IBM Plex Serif (display) / IBM Plex Mono (code) via @fontsource |
- Node.js >= 22
- pnpm >= 10
- Converted content — run the CLI to generate Markdown files before starting the app. The app browses every granularity (section, chapter, title, and part for eCFR), so emit them all in a single parse using
--granularities:
# From the monorepo root
pnpm turbo build
# USC: download once, then emit section + chapter + title from one parse
node packages/cli/dist/index.js download-usc --all
node packages/cli/dist/index.js convert-usc --all \
--granularities section,title,chapter \
--output ./output \
--output-title ./output-title \
--output-chapter ./output-chapter
# eCFR: download once, then emit all four granularities from one parse
node packages/cli/dist/index.js download-ecfr --all
node packages/cli/dist/index.js convert-ecfr --all \
--granularities section,title,chapter,part \
--output ./output \
--output-title ./output-title \
--output-chapter ./output-chapter \
--output-part ./output-part
# Federal Register (no granularities — documents are atomic)
node packages/cli/dist/index.js download-fr --recent 30
node packages/cli/dist/index.js convert-fr --allFor routine updates, use ./scripts/update.sh — the wrapper scripts already use --granularities internally.
Symlink CLI output into the app's content/ directory:
cd apps/astro
bash scripts/link-content.shBuild sidebar JSON from _meta.json sidecar files (USC/eCFR) and frontmatter (FR):
npx tsx scripts/generate-nav.ts # All sources
npx tsx scripts/generate-nav.ts --source fr # Single sourcepnpm dev
# → http://localhost:4321The dev server uses Astro 6's production runtime via Vite — dev behavior matches production. Syntax highlighting falls back to runtime Shiki when pre-rendered .highlighted.html files aren't present.
Generate syntax-highlighted HTML for all Markdown files (recommended for large datasets):
npx tsx scripts/generate-highlights.ts # Full run (~1M files with FR)
npx tsx scripts/generate-highlights.ts --source fr # Single source
npx tsx scripts/generate-highlights.ts --limit 50 # Test subset
npx tsx scripts/generate-highlights.ts --chunk-size 1000 # Smaller chunks for memory-constrained runsHighlights are generated in forked child processes (2k files/chunk, 2GB heap cap per child) to avoid Shiki memory leaks.
brew install meilisearch && brew services start meilisearch
npx tsx scripts/index-search.ts # Full reindex (~1M docs, ~15 min)
npx tsx scripts/index-search-incremental.ts --source fr # Single source incrementalSet ENABLE_SEARCH=true in .env.local to enable the search UI.
| Variable | Default | Description |
|---|---|---|
CONTENT_DIR |
./content |
Root path to content directory |
NAV_DIR |
./public/nav |
Root path to pre-built sidebar JSON |
SITE_URL |
https://lexbuild.dev |
Base URL for sitemap and OG tags |
ENABLE_SEARCH |
false |
Enable Meilisearch-powered search UI |
MEILI_URL |
http://127.0.0.1:7700 |
Meilisearch endpoint (/search in production for Caddy proxy) |
MEILI_SEARCH_KEY |
— | Meilisearch search-only API key (not needed in proxy mode) |
Create .env.local for local overrides (git-ignored).
After converting content with the CLI, these scripts prepare the app's data. Run from apps/astro/. All scripts support --source usc|ecfr|fr to process a single source.
| Script | Purpose | Speed |
|---|---|---|
link-content.sh |
Symlink CLI output into content/ |
Instant |
generate-nav.ts |
Build sidebar JSON from _meta.json (USC/eCFR) and frontmatter (FR) |
< 5s |
generate-highlights.ts |
Pre-render Shiki HTML for all .md files (2k files/chunk, heap-capped) |
Incremental |
generate-sitemap.ts |
Build sitemap index + chunked sitemaps (~1M URLs) | < 10s |
index-search.ts |
Full reindex into Meilisearch (~1.05M docs) | ~15 min |
index-search-incremental.ts |
Incremental upsert (--source, --set-checkpoint, --prune) |
Varies |
All outputs (content/, public/nav/, public/sitemap*.xml, *.highlighted.html) are git-ignored.
Every page is server-rendered. The server reads .md files from the local filesystem, parses YAML frontmatter, renders Markdown to HTML, and serves pre-rendered syntax-highlighted source views. No database, no CMS — content is generated by the CLI and served directly.
Astro renders pages as static HTML with zero client-side JavaScript by default. Interactive components are React islands hydrated only where needed:
| Component | Hydration | Purpose |
|---|---|---|
ContentViewer |
client:load |
Tabbed source/preview with copy and download |
Sidebar |
client:load |
Desktop sticky sidebar with resizable drag handle |
MobileNav |
client:load |
Hamburger + Sheet drawer with source switcher (USC / eCFR / FR) |
SearchDialog |
client:idle |
Cmd+K search with source filter tabs |
ThemeToggle |
client:load |
Dark/light mode toggle |
Static components (no JS): BaseLayout.astro, FrontmatterPanel.astro, BreadcrumbNav.astro
| Source | URL Pattern | Granularity |
|---|---|---|
| USC | /usc/title-01 |
title |
| USC | /usc/title-01/chapter-01 |
chapter |
| USC | /usc/title-01/chapter-01/section-1 |
section |
| eCFR | /ecfr/title-17 |
title |
| eCFR | /ecfr/title-17/chapter-IV |
chapter |
| eCFR | /ecfr/title-17/chapter-IV/part-240 |
part |
| eCFR | /ecfr/title-17/chapter-IV/part-240/section-240.10b-5 |
section |
| FR | /fr/2026 |
year |
| FR | /fr/2026/03 |
month |
| FR | /fr/2026/03/2026-06029 |
document |
USC and eCFR use hierarchical title/chapter paths. FR uses date-based year/month paths. Slug segment count determines granularity per source.
All three sources have sidebar navigation:
- USC: Title → chapter → section tree (lazy-loaded per title)
- eCFR: Title → chapter → part → section tree (lazy-loaded per title)
- FR: Year → month tree (loaded from
years.json, months are links to listing pages)
The sidebar is resizable via drag handle (200–500px range, width persisted to localStorage). Mobile uses a Sheet drawer with a source switcher.
Meilisearch indexes ~1.05M documents across all three sources. Filterable by source, title_number, granularity, status, document_type, and publication_date. In production, Caddy proxies /search to Meilisearch with auth header injection — no API key exposed to the browser.
This app has no import from @lexbuild/core, @lexbuild/usc, @lexbuild/ecfr, or @lexbuild/fr. It consumes their output — .md files with YAML frontmatter and _meta.json sidecar files — as data.
Five brand palettes defined in src/styles/global.css as Tailwind @theme inline variables:
- Slate Blue — primary UI, headings, sidebar, USC accents
- Summer Green — eCFR accents, published badges, output section
- Putty — future/planned items, warm amber accent
- Lavender — FR accents (source cards, parser borders, sidebar)
- Chestnut — available for future use (error states, alerts)
Dark mode uses a dark slate-blue palette (not default shadcn grey). Semantic tokens (bg-surface, text-ink-muted, border-border-base) auto-adapt via :root/.dark runtime vars.
pnpm run build:astro # Production build
pnpm run preview # Preview production build locallyFrom the monorepo root:
pnpm turbo build:astro --filter=@lexbuild/astroNote: This app is intentionally excluded from the default
pnpm turbo buildpipeline. It has nobuildscript inpackage.json— onlybuild:astro. This prevents CI failures since the app requires content files that aren't in git.
The production build produces a standalone Node.js server (dist/server/entry.mjs). Deploy behind a reverse proxy (Caddy, Nginx) with a process manager (PM2, systemd). Content is served from the local filesystem — upload converted content to the server and set CONTENT_DIR accordingly.
Cache strategy: set long s-maxage on responses and let a CDN (Cloudflare, etc.) cache at the edge. Purge cache after content updates.