How eduardomar/edi-viewer works
Project type and purpose
• This is a front‑end only, single‑page React application (bootstrapped with Create React App) written in TypeScript.
• Its core purpose is to let users upload, parse, browse, and view EDI (Electronic Data Interchange) files. It uses a large set of static JSON “record” definitions as schemas to interpret segments in an uploaded EDI file, then displays both a structured tree and a rich view.
File structure
• Top‑level: standard CRA files (public/, src/, config files).
• public/: static HTML, manifest, robots.
• src/: contains assets, components, constants, hooks, interfaces, pages, record definitions (in src/records), utils, and bootstrap (index.tsx).
• Pages:
• UploadEDI – file‑upload UI
• ViewerEDI – main viewer with subcomponents (Accordion, JsonView, RichView, Navbar, Offcanvas, MissingRecords, etc.)
• NotFound – 404
• Utilities: EDI parsing (ediToObject.ts, writeSegmentEdi.ts), file download, clipboard copying.
• Data: src/records/*.json and nested directories – these are static schemas for all supported EDI record types.
• Hooks: custom React hooks for clipboard and URL parameter handling.
• Types and interfaces: defined in src/interfaces.
README
• It’s the standard CRA README without any architecture notes. We must infer architecture from the code.
a. Main components
• Browser / User
• React SPA container
• UI Layer
– Pages (UploadEDI, ViewerEDI, NotFound)
– Shared Components (ButtonClipboard, EDI display helpers)
• Business Logic Layer
– Hooks (useClipboard, useParams)
– Utils (ediToObject parser, writeSegmentEdi, downloadFile, copyToClipboard)
• Data Layer
– Static records JSON schemas (src/records)
– Constants (countries.json, other mappings)
• Type Definitions / Interfaces
b. Relationships & interactions
1. User interacts with UploadEDI page → chooses EDI file
2. File is read by browser FileReader and passed to ediToObject (utility)
3. Parser uses src/records/*.json schema definitions + interfaces to build a typed object tree
4. Parsed object is stored in React state and passed to ViewerEDI page
5. ViewerEDI subcomponents (AccordionItem, JsonView, RichView, MissingRecords) render based on the parsed data
6. Hooks (useClipboard, useParams) manage URL parameters and copy‑to‑clipboard actions from UI
7. Utilities like downloadFile allow exporting modified EDI
c. Architectural patterns & principles
• Single Page Application (SPA)
• Separation of concerns:
• UI vs. parsing logic vs. data schemas
• Reusable hooks for cross‑cutting concerns (clipboard, routing params)
• Static data assets (JSON) packaged at build time for offline schema lookup
• Type‑safe data flows guaranteed by TypeScript interfaces
d. Key technologies / frameworks
• React (with CRA)
• TypeScript
• Webpack (implicitly via CRA)
• ESLint, Prettier, Husky (dev tooling)
Elements
• from Browser → UploadEDI UI → Util (parser)
• from Util → Data Layer (records JSON)
• back to React state → Viewer components