# piyushvirani/librange architecture

> Architecture diagram of the GitHub repository piyushvirani/librange, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/piyushvirani/librange
- Repository: https://github.com/piyushvirani/librange

## Overview

#### Purpose and Entry Points
LibRange is a client-side React application for locating MacOdrum Library items from call numbers. It maps a user-entered call number to both a physical shelf range and a broader library section. Browser startup is `src/main.tsx`; application orchestration is in `src/App.tsx`.

#### UI Interaction Layer
The UI is organized around call-number input, result presentation, and a visual location display:
- `src/components/CallNumberForm.tsx`
- `src/components/ResultPanel.tsx`
- `src/components/MapView.tsx`

`App.tsx` owns the lookup workflow and passes input/results between these components. `MapView` is the physical-location boundary, consuming range/floor information rather than performing call-number parsing itself.

#### Call-Number Normalization Pipeline
User input is transformed into a comparable ordering key before data lookup:
- `src/lib/parseCallNumber.ts`
- `src/lib/getCallNumberKey.ts`
- `src/types/ParsedCallNumber.ts`

This isolates human-readable library call-number syntax from lookup logic. Parsing yields structured call-number data; key generation provides a sortable representation used to compare input against configured spans.

#### Physical Range Resolution
Shelf lookup is driven by physical range records:
- `src/lib/findRange.ts`
- `src/data/ranges.json`
- `src/types/RangeRecord.ts`

Each range contains independent left- and right-side spans plus floor and range identifiers. `findRange` computes comparison keys at runtime from the stored human-readable boundaries, then determines the matching physical range/side. Result shape is represented by `src/types/RangeMatch.ts`.

#### General Section Resolution
Section labeling is a separate, parallel lookup rather than a property inferred from a physical shelf:
- `src/lib/findSection.ts`
- `src/data/sections.json`
- `src/types/SectionRecord.ts`

This separation is intentional: one physical range may span multiple general sections. The application independently resolves the section span and combines it with physical lookup output for display. `src/types/SectionMatch.ts` defines the resulting section match.

#### Data and Control Flow
The main flow is: form submission → parse/normalize call number → resolve physical range from `ranges.json` → resolve section from `sections.json` → render textual result and map location. Invalid or unmatched input remains at the application/UI boundary; lookup libraries operate on normalized values and static record data.

#### Runtime and Delivery
The project is TypeScript + React, bundled with Vite:
- `package.json`
- `vite.config.ts`
- `src/main.tsx`

There is no backend, database, or external service indicated. Shelf and section data is versioned in the frontend bundle. Production artifacts are present under `dist/index.html` and `dist/assets/`.

Main entry points: [`src/App.tsx`](https://github.com/piyushvirani/librange/blob/main/src/App.tsx) (Lookup orchestration), [`src/lib/findRange.ts`](https://github.com/piyushvirani/librange/blob/main/src/lib/findRange.ts) (Physical range resolver), [`src/lib/getCallNumberKey.ts`](https://github.com/piyushvirani/librange/blob/main/src/lib/getCallNumberKey.ts) (Sortable key generator), [`src/lib/findSection.ts`](https://github.com/piyushvirani/librange/blob/main/src/lib/findSection.ts) (Section resolver)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["React UI"]
  node_main(("Browser entry<br/>React entry<br/>[main.tsx]"))
  node_app["Lookup orchestration<br/>React application<br/>[App.tsx]"]
  node_form["Call number form<br/>input component<br/>[CallNumberForm.tsx]"]
  node_result["Result panel<br/>presentation component<br/>[ResultPanel.tsx]"]
  node_map["Map view<br/>location component<br/>[MapView.tsx]"]
end

subgraph group_lookup["Lookup pipeline"]
  node_parse["Call number parser<br/>normalizer<br/>[parseCallNumber.ts]"]
  node_parsed_type["Parsed call number<br/>domain type"]
  node_key["Sortable key generator<br/>normalizer"]
  node_range_lookup["Physical range resolver<br/>lookup service<br/>[findRange.ts]"]
  node_range_match["Range match<br/>result type<br/>[RangeMatch.ts]"]
  node_section_lookup["Section resolver<br/>lookup service<br/>[findSection.ts]"]
  node_section_match["Section match<br/>result type<br/>[SectionMatch.ts]"]
end

subgraph group_data["Bundled reference data"]
  node_ranges[("Shelf ranges<br/>static JSON<br/>[ranges.json]")]
  node_range_record["Range record<br/>data type<br/>[RangeRecord.ts]"]
  node_sections[("Section spans<br/>static JSON<br/>[sections.json]")]
  node_section_record["Section record<br/>data type<br/>[SectionRecord.ts]"]
end

node_vite{{"Vite build<br/>bundler<br/>[vite.config.ts]"}}
node_production["Production bundle<br/>static artifacts<br/>[index.html]"]

node_vite -->|"bundles"| node_main
node_vite -->|"emits"| node_production
node_main -->|"mounts"| node_app
node_app -->|"collects input"| node_form
node_form -->|"submits call number"| node_app
node_app -->|"parses"| node_parse
node_parse -->|"produces"| node_parsed_type
node_parse -->|"normalizes"| node_key
node_key -->|"comparison key"| node_range_lookup
node_key -->|"comparison key"| node_section_lookup
node_ranges -->|"range spans"| node_range_lookup
node_range_record -.->|"defines records"| node_ranges
node_range_lookup -->|"keys stored boundaries"| node_key
node_range_lookup -->|"returns"| node_range_match
node_sections -->|"section spans"| node_section_lookup
node_section_record -.->|"defines records"| node_sections
node_section_lookup -->|"returns"| node_section_match
node_app -->|"resolves range"| node_range_lookup
node_app -->|"resolves section"| node_section_lookup
node_app -->|"renders combined result"| node_result
node_app -->|"passes range and floor"| node_map

click node_vite "https://github.com/piyushvirani/librange/blob/main/vite.config.ts"
click node_main "https://github.com/piyushvirani/librange/blob/main/src/main.tsx"
click node_app "https://github.com/piyushvirani/librange/blob/main/src/App.tsx"
click node_form "https://github.com/piyushvirani/librange/blob/main/src/components/CallNumberForm.tsx"
click node_result "https://github.com/piyushvirani/librange/blob/main/src/components/ResultPanel.tsx"
click node_map "https://github.com/piyushvirani/librange/blob/main/src/components/MapView.tsx"
click node_parse "https://github.com/piyushvirani/librange/blob/main/src/lib/parseCallNumber.ts"
click node_parsed_type "https://github.com/piyushvirani/librange/blob/main/src/types/ParsedCallNumber.ts"
click node_key "https://github.com/piyushvirani/librange/blob/main/src/lib/getCallNumberKey.ts"
click node_range_lookup "https://github.com/piyushvirani/librange/blob/main/src/lib/findRange.ts"
click node_range_match "https://github.com/piyushvirani/librange/blob/main/src/types/RangeMatch.ts"
click node_section_lookup "https://github.com/piyushvirani/librange/blob/main/src/lib/findSection.ts"
click node_section_match "https://github.com/piyushvirani/librange/blob/main/src/types/SectionMatch.ts"
click node_ranges "https://github.com/piyushvirani/librange/blob/main/src/data/ranges.json"
click node_range_record "https://github.com/piyushvirani/librange/blob/main/src/types/RangeRecord.ts"
click node_sections "https://github.com/piyushvirani/librange/blob/main/src/data/sections.json"
click node_section_record "https://github.com/piyushvirani/librange/blob/main/src/types/SectionRecord.ts"
click node_production "https://github.com/piyushvirani/librange/blob/main/dist/index.html"

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_main,node_app,node_form,node_result,node_map toneBlue
class node_parse,node_parsed_type,node_key,node_range_lookup,node_range_match,node_section_lookup,node_section_match toneAmber
class node_ranges,node_range_record,node_sections,node_section_record toneMint
class node_vite,node_production toneNeutral
```

## Components

### React UI

- [Browser entry](https://github.com/piyushvirani/librange/blob/main/src/main.tsx): React entry · `src/main.tsx`
- [Lookup orchestration](https://github.com/piyushvirani/librange/blob/main/src/App.tsx): React application · Coordinates validation, parallel lookups, and rendered results. · `src/App.tsx`
- [Call number form](https://github.com/piyushvirani/librange/blob/main/src/components/CallNumberForm.tsx): input component · `src/components/CallNumberForm.tsx`
- [Result panel](https://github.com/piyushvirani/librange/blob/main/src/components/ResultPanel.tsx): presentation component · `src/components/ResultPanel.tsx`
- [Map view](https://github.com/piyushvirani/librange/blob/main/src/components/MapView.tsx): location component · Consumes resolved range and floor information only. · `src/components/MapView.tsx`

### Lookup pipeline

- [Call number parser](https://github.com/piyushvirani/librange/blob/main/src/lib/parseCallNumber.ts): normalizer · Converts library syntax into structured data. · `src/lib/parseCallNumber.ts`
- [Parsed call number](https://github.com/piyushvirani/librange/blob/main/src/types/ParsedCallNumber.ts): domain type · `src/types/ParsedCallNumber.ts`
- [Sortable key generator](https://github.com/piyushvirani/librange/blob/main/src/lib/getCallNumberKey.ts): normalizer · Creates comparable ordering keys. · `src/lib/getCallNumberKey.ts`
- [Physical range resolver](https://github.com/piyushvirani/librange/blob/main/src/lib/findRange.ts): lookup service · Matches a call number against left and right shelf spans. · `src/lib/findRange.ts`
- [Range match](https://github.com/piyushvirani/librange/blob/main/src/types/RangeMatch.ts): result type · `src/types/RangeMatch.ts`
- [Section resolver](https://github.com/piyushvirani/librange/blob/main/src/lib/findSection.ts): lookup service · Independently matches broader library section spans. · `src/lib/findSection.ts`
- [Section match](https://github.com/piyushvirani/librange/blob/main/src/types/SectionMatch.ts): result type · `src/types/SectionMatch.ts`

### Bundled reference data

- [Shelf ranges](https://github.com/piyushvirani/librange/blob/main/src/data/ranges.json): static JSON · Physical ranges with side spans, floor, and identifiers. · `src/data/ranges.json`
- [Range record](https://github.com/piyushvirani/librange/blob/main/src/types/RangeRecord.ts): data type · `src/types/RangeRecord.ts`
- [Section spans](https://github.com/piyushvirani/librange/blob/main/src/data/sections.json): static JSON · General section boundaries independent of shelf ranges. · `src/data/sections.json`
- [Section record](https://github.com/piyushvirani/librange/blob/main/src/types/SectionRecord.ts): data type · `src/types/SectionRecord.ts`

### Other components

- [Vite build](https://github.com/piyushvirani/librange/blob/main/vite.config.ts): bundler · Bundles the client application for production. · `vite.config.ts`
- [Production bundle](https://github.com/piyushvirani/librange/blob/main/dist/index.html): static artifacts · `dist/index.html`

## Connections

- Vite build → Browser entry: bundles
- Vite build → Production bundle: emits
- Browser entry → Lookup orchestration: mounts
- Lookup orchestration → Call number form: collects input
- Call number form → Lookup orchestration: submits call number
- Lookup orchestration → Call number parser: parses
- Call number parser → Parsed call number: produces
- Call number parser → Sortable key generator: normalizes
- Sortable key generator → Physical range resolver: comparison key
- Sortable key generator → Section resolver: comparison key
- Shelf ranges → Physical range resolver: range spans
- Range record → Shelf ranges: defines records
- Physical range resolver → Sortable key generator: keys stored boundaries
- Physical range resolver → Range match: returns
- Section spans → Section resolver: section spans
- Section record → Section spans: defines records
- Section resolver → Section match: returns
- Lookup orchestration → Physical range resolver: resolves range
- Lookup orchestration → Section resolver: resolves section
- Lookup orchestration → Result panel: renders combined result
- Lookup orchestration → Map view: passes range and floor
