How highonicee/open-materials-explorer works
Purpose and Runtime
Open Materials Explorer is a Next.js 15 / React 19 TypeScript application for browsing a curated materials dataset, inspecting elements and material properties, viewing CIF crystal structures, calculating properties, and asking an AI assistant materials-science questions. It is deployable as a server-rendered/client-interactive web application, with static material and structure assets served from public/.
Application Shell and Entry Points
The App Router defines route-level entry points and global UI composition. app/layout.tsx supplies the shared layout/theme boundary; app/page.tsx is the home route; app/loading.tsx provides route loading UI. Feature pages are exposed directly under app/, including:
• Explorer: app/explorer/page.tsx
• Periodic table: app/periodic-table/page.tsx
• Crystal viewer: app/viewer/page.tsx
• Calculator: app/calculator/page.tsx
• Chat interfaces: app/chat/page.tsx, app/chatbot/page.tsx
Materials Catalog and Search
The primary catalog is prebuilt JSON, rather than a database represented in this tree. Browser-facing datasets include public/data/materials.json, public/data/materials_with_paths.json, and public/data/real-500-materials-cleaned-readable-names.json. Explorer UI composes filters, result lists, detail views, comparison, and history:
• components/page/explorer-page.tsx
• components/search-filters.tsx
• components/search-results.tsx
• components/material-details.tsx
lib/search-service.ts is the application search boundary. The README describes Elasticsearch, fuzzy matching, and range/category filtering, but no Elasticsearch client or infrastructure definition is present; validate whether search is local/client-side or expects an external service before changing it.
Element and Materials Analysis Views
The periodic-table flow uses structured element data and an element detail presentation:
• data/elements.ts
• types/element.ts
• components/page/periodic-table-page.tsx
• components/element-details.tsx
Material-centric analysis renders catalog metadata and visual summaries, with charts likely powered by Recharts as declared by the README:
• components/materials-grid.tsx
• components/material-comparison.tsx
• components/charts-section.tsx
Favorites are a distinct UI route at app/favorites/page.tsx; persistence infrastructure is not represented in the tree.
Crystal-Structure Delivery and Rendering
CIF files are static domain assets under public/structures/ (for example public/structures/ac2o3.cif and public/structures/al2o3.cif). Material records containing structure paths connect catalog selection to visualization. Rendering is isolated behind viewer components:
• components/crystal-viewer.tsx
• components/structure-viewer.tsx
• components/ui/StructureViewerClient.tsx
The client-specific viewer boundary is material because Three.js requires browser APIs. A second viewer implementation exists at components/page/CIFViewer.tsx; determine ownership/consolidation before extending structure behavior.
AI Chat Boundary
Chat UI is separated from its server route. User prompts originate in reusable/page-level chat components and are sent to a Next route handler:
• components/chatbot-interface.tsx
• components/page/chatbot-page.tsx
• app/chatapi/chat/route.ts
The API boundary presumably invokes OpenAI, per README; API credentials and provider configuration are absent from the supplied tree and must remain server-side. app/api/materials/route.ts provides a separate materials API surface.
Offline Data Pipeline
Python scripts build, repair, enrich, and map catalog data and CIF assets outside the Next runtime:
• fetch_materials.py
• cif_pipeline.py
• add_iupac_names.py
• update_structure_paths.py
• download_missing_cifs.py
Their outputs are checked into root/data/public JSON and public/structures/. This establishes a build-time ingestion boundary from Materials Project, NIST, COD, and curated sources into static application data; no live source integration is evidenced by the app tree.
Presentation and UI Infrastructure
Tailwind plus global styles establish presentation, while reusable Radix/Shadcn-style primitives support feature components:
• app/globals.css
• styles/globals.css
• components/theme-provider.tsx
• components/navbar.tsx
Theme state and navigation cross-cut all pages. Keep domain logic out of components/ui/, which is primarily a shared design-system layer.
Main entry points: page.tsx Feature routes · materials_with_paths.json Materials catalog · theme-provider.tsx Shared UI infrastructure · explorer-page.tsx Explorer UI
Components 17
Next.js application
Routes and server boundaries.
- App shell
app/layout.tsx - Feature routes · Home, explorer, periodic table, viewer, calculator, chat, and favorites routes.
app/page.tsx - Chat route · Keeps provider credentials server-side.
app/chatapi/chat/route.ts - Materials API
app/api/materials/route.ts
Feature UI
Client-facing domain views.
- Explorer UI · Filters, results, details, comparison, and history.
components/page/explorer-page.tsx - Search service · Search implementation may be local or externally backed.
lib/search-service.ts - Material analysis · Grid, comparisons, metadata, and charts.
components/materials-grid.tsx - Periodic table UI
components/page/periodic-table-page.tsx - Crystal viewer · Client boundary for Three.js and browser APIs.
components/ui/StructureViewerClient.tsx - Chat UI
components/chatbot-interface.tsx - Shared UI infrastructure · Theme provider, navigation, global styles, and UI primitives.
components/theme-provider.tsx
Static catalog pipeline
Checked-in datasets and structure assets.
- Element dataset
data/elements.ts - CIF structures
- Materials catalog · Browser-served material records, including structure paths.
public/data/materials_with_paths.json - Data ingestion pipeline · Builds, enriches, repairs, and maps catalog and CIF outputs.
cif_pipeline.py
External sources
Build-time sources and server-side AI provider.
- AI provider · Presumed OpenAI integration.
- Materials data sources · Materials Project, NIST, COD, and curated sources.
Connections 22
- App shell → Feature routes: wraps
- App shell → Shared UI infrastructure: provides
- Feature routes → Explorer UI: renders
- Feature routes → Periodic table UI: renders
- Feature routes → Crystal viewer: renders
- Feature routes → Chat UI: renders
- Explorer UI → Search service: queries
- Search service → Materials catalog: searches
- Explorer UI → Material analysis: presents
- Material analysis → Materials catalog: reads
- Periodic table UI → Element dataset: reads
- Crystal viewer → Materials catalog: uses structure paths
- Crystal viewer → CIF structures: loads CIF
- Chat UI → Chat route: sends prompts
- Chat route → AI provider: invokes
- Materials API → Materials catalog: serves
- Materials data sources → Data ingestion pipeline: ingested by
- Data ingestion pipeline → Materials catalog: builds and enriches
- Data ingestion pipeline → CIF structures: downloads and maps
- Shared UI infrastructure → Explorer UI: supports
- Shared UI infrastructure → Periodic table UI: supports
- Shared UI infrastructure → Chat UI: supports