# highonicee/open-materials-explorer architecture

> Architecture diagram of the GitHub repository highonicee/open-materials-explorer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/highonicee/open-materials-explorer
- Repository: https://github.com/highonicee/open-materials-explorer

## Overview

#### 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: [`app/page.tsx`](https://github.com/highonicee/open-materials-explorer/blob/main/app/page.tsx) (Feature routes), [`public/data/materials_with_paths.json`](https://github.com/highonicee/open-materials-explorer/blob/main/public/data/materials_with_paths.json) (Materials catalog), [`components/theme-provider.tsx`](https://github.com/highonicee/open-materials-explorer/blob/main/components/theme-provider.tsx) (Shared UI infrastructure), [`components/page/explorer-page.tsx`](https://github.com/highonicee/open-materials-explorer/blob/main/components/page/explorer-page.tsx) (Explorer UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Next.js application"]
  node_shell["App shell<br/>layout and theme<br/>[layout.tsx]"]
  node_routes["Feature routes<br/>App Router pages<br/>[page.tsx]"]
  node_chat_api{{"Chat route<br/>Next route handler<br/>[route.ts]"}}
  node_materials_api{{"Materials API<br/>Next route handler<br/>[route.ts]"}}
end

subgraph group_ui["Feature UI"]
  node_explorer["Explorer UI<br/>catalog search UI<br/>[explorer-page.tsx]"]
  node_search{{"Search service<br/>search boundary<br/>[search-service.ts]"}}
  node_material_views["Material analysis<br/>material UI<br/>[materials-grid.tsx]"]
  node_periodic["Periodic table UI<br/>element UI"]
  node_viewer["Crystal viewer<br/>browser 3D renderer"]
  node_chat_ui["Chat UI<br/>assistant interface"]
  node_design_system["Shared UI infrastructure<br/>theme and navigation<br/>[theme-provider.tsx]"]
end

subgraph group_data["Static catalog pipeline"]
  node_elements["Element dataset<br/>typed domain data<br/>[elements.ts]"]
  node_cif_assets["CIF structures<br/>static structure assets"]
  node_catalog[("Materials catalog<br/>static JSON datasets")]
  node_pipeline["Data ingestion pipeline<br/>Python batch scripts<br/>[cif_pipeline.py]"]
end

subgraph group_external["External sources"]
  node_openai(("AI provider<br/>server-side integration"))
  node_sources(("Materials data sources<br/>external datasets"))
end

node_shell -->|"wraps"| node_routes
node_shell -->|"provides"| node_design_system
node_routes -->|"renders"| node_explorer
node_routes -->|"renders"| node_periodic
node_routes -->|"renders"| node_viewer
node_routes -->|"renders"| node_chat_ui
node_explorer -->|"queries"| node_search
node_search -->|"searches"| node_catalog
node_explorer -->|"presents"| node_material_views
node_material_views -->|"reads"| node_catalog
node_periodic -->|"reads"| node_elements
node_viewer -->|"uses structure paths"| node_catalog
node_viewer -->|"loads CIF"| node_cif_assets
node_chat_ui -->|"sends prompts"| node_chat_api
node_chat_api -->|"invokes"| node_openai
node_materials_api -->|"serves"| node_catalog
node_sources -->|"ingested by"| node_pipeline
node_pipeline -->|"builds and enriches"| node_catalog
node_pipeline -->|"downloads and maps"| node_cif_assets
node_design_system -.->|"supports"| node_explorer
node_design_system -.->|"supports"| node_periodic
node_design_system -.->|"supports"| node_chat_ui

click node_shell "https://github.com/highonicee/open-materials-explorer/blob/main/app/layout.tsx"
click node_routes "https://github.com/highonicee/open-materials-explorer/blob/main/app/page.tsx"
click node_explorer "https://github.com/highonicee/open-materials-explorer/blob/main/components/page/explorer-page.tsx"
click node_search "https://github.com/highonicee/open-materials-explorer/blob/main/lib/search-service.ts"
click node_material_views "https://github.com/highonicee/open-materials-explorer/blob/main/components/materials-grid.tsx"
click node_periodic "https://github.com/highonicee/open-materials-explorer/blob/main/components/page/periodic-table-page.tsx"
click node_elements "https://github.com/highonicee/open-materials-explorer/blob/main/data/elements.ts"
click node_viewer "https://github.com/highonicee/open-materials-explorer/blob/main/components/ui/StructureViewerClient.tsx"
click node_chat_ui "https://github.com/highonicee/open-materials-explorer/blob/main/components/chatbot-interface.tsx"
click node_chat_api "https://github.com/highonicee/open-materials-explorer/blob/main/app/chatapi/chat/route.ts"
click node_materials_api "https://github.com/highonicee/open-materials-explorer/blob/main/app/api/materials/route.ts"
click node_catalog "https://github.com/highonicee/open-materials-explorer/blob/main/public/data/materials_with_paths.json"
click node_pipeline "https://github.com/highonicee/open-materials-explorer/blob/main/cif_pipeline.py"
click node_design_system "https://github.com/highonicee/open-materials-explorer/blob/main/components/theme-provider.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_shell,node_routes,node_chat_api,node_materials_api toneBlue
class node_explorer,node_search,node_material_views,node_periodic,node_viewer,node_chat_ui,node_design_system toneAmber
class node_elements,node_cif_assets,node_catalog,node_pipeline toneMint
class node_openai,node_sources toneRose
```

## Components

### Next.js application

Routes and server boundaries.

- [App shell](https://github.com/highonicee/open-materials-explorer/blob/main/app/layout.tsx): layout and theme · `app/layout.tsx`
- [Feature routes](https://github.com/highonicee/open-materials-explorer/blob/main/app/page.tsx): App Router pages · Home, explorer, periodic table, viewer, calculator, chat, and favorites routes. · `app/page.tsx`
- [Chat route](https://github.com/highonicee/open-materials-explorer/blob/main/app/chatapi/chat/route.ts): Next route handler · Keeps provider credentials server-side. · `app/chatapi/chat/route.ts`
- [Materials API](https://github.com/highonicee/open-materials-explorer/blob/main/app/api/materials/route.ts): Next route handler · `app/api/materials/route.ts`

### Feature UI

Client-facing domain views.

- [Explorer UI](https://github.com/highonicee/open-materials-explorer/blob/main/components/page/explorer-page.tsx): catalog search UI · Filters, results, details, comparison, and history. · `components/page/explorer-page.tsx`
- [Search service](https://github.com/highonicee/open-materials-explorer/blob/main/lib/search-service.ts): search boundary · Search implementation may be local or externally backed. · `lib/search-service.ts`
- [Material analysis](https://github.com/highonicee/open-materials-explorer/blob/main/components/materials-grid.tsx): material UI · Grid, comparisons, metadata, and charts. · `components/materials-grid.tsx`
- [Periodic table UI](https://github.com/highonicee/open-materials-explorer/blob/main/components/page/periodic-table-page.tsx): element UI · `components/page/periodic-table-page.tsx`
- [Crystal viewer](https://github.com/highonicee/open-materials-explorer/blob/main/components/ui/StructureViewerClient.tsx): browser 3D renderer · Client boundary for Three.js and browser APIs. · `components/ui/StructureViewerClient.tsx`
- [Chat UI](https://github.com/highonicee/open-materials-explorer/blob/main/components/chatbot-interface.tsx): assistant interface · `components/chatbot-interface.tsx`
- [Shared UI infrastructure](https://github.com/highonicee/open-materials-explorer/blob/main/components/theme-provider.tsx): theme and navigation · Theme provider, navigation, global styles, and UI primitives. · `components/theme-provider.tsx`

### Static catalog pipeline

Checked-in datasets and structure assets.

- [Element dataset](https://github.com/highonicee/open-materials-explorer/blob/main/data/elements.ts): typed domain data · `data/elements.ts`
- **CIF structures**: static structure assets
- [Materials catalog](https://github.com/highonicee/open-materials-explorer/blob/main/public/data/materials_with_paths.json): static JSON datasets · Browser-served material records, including structure paths. · `public/data/materials_with_paths.json`
- [Data ingestion pipeline](https://github.com/highonicee/open-materials-explorer/blob/main/cif_pipeline.py): Python batch scripts · Builds, enriches, repairs, and maps catalog and CIF outputs. · `cif_pipeline.py`

### External sources

Build-time sources and server-side AI provider.

- **AI provider**: server-side integration · Presumed OpenAI integration.
- **Materials data sources**: external datasets · Materials Project, NIST, COD, and curated sources.

## Connections

- 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
