# nci-c4cp/biospecimen architecture

> Architecture diagram of the GitHub repository nci-c4cp/biospecimen, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nci-c4cp/biospecimen
- Repository: https://github.com/nci-c4cp/biospecimen

## Overview

##### Main Components Identification
- Entry Point & Application Shell: Highlight index.html (the static HTML host) and index.js (the main application initialization and orchestration logic).
- Service Infrastructure: Include serviceWorker.js and manifest.json since these support Progressive Web App (PWA) capabilities like caching and manifest configuration.
- Configuration & Environment Handling: There are dedicated directories for dev, stage, and production (each with its own config.js and identityProvider.js). This indicates that environment-specific configuration and authentication are modularized.
- Page-Based Modules: The src/pages directory contains a wealth of page components (e.g., checkIn, dashboard, reportsQuery, siteCollection, homeCollection, etc.). These represent the main functional areas of the dashboard.
- Static Assets: The “static” directory holds CSS, images, and libraries that provide styling and external functionality.
- Shared Modules: Files such as src/shared.js, src/events.js, src/fieldToConceptIdMapping.js, etc., suggest common utilities or event handling that are utilized across the application.

##### Relationships and Interactions
- The user loads index.html, which in turn loads index.js – this bootstraps the application.
- index.js is responsible for instantiating the overall application logic and coordinating navigation between different page components.
- Depending on the environment (dev, stage, or prod), the application loads the corresponding configuration (config.js) and identity provider modules for authentication/authorization needs.
- Each page module (within src/pages) is a self-contained unit that handles specific functionality (for example, homeCollection handles kit assignments and shipments, while siteCollection deals with shipping reports and package receipts).
- Common services (like events and shared utilities) are used by multiple page components to coordinate actions and maintain consistent state management.
- Static assets (from static/css and static/images) are consumed by index.html and the various UI components to style the dashboard and provide graphical resources.

##### Architectural Patterns and Technologies
- Modular Design: The separation into environment-specific directories and many page modules indicates a modular design approach.
- Progressive Enhancement: Use of a service worker and manifest suggests the app is built as a Progressive Web App (PWA), ensuring offline capabilities and app-like behavior.
- Component-Based UI: With directories for different pages, the system likely uses a component-based structure, a pattern common in modern front-end development.
- Separation of Concerns: Different responsibilities (authentication, configuration, UI logic, common utilities) are clearly segregated.

- Use clear, legible labels for each block/component.
- Architectural principles such as modularity, separation of concerns, and the specific integration of PWA elements.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Entry
    subgraph "Frontend Entry"
        idxHtml["index.html"]:::front
        idxJS["index.js"]:::front
    end

    %% PWA Components
    subgraph "PWA Components"
        sw["serviceWorker.js"]:::pwa
        manifest["manifest.json"]:::pwa
    end

    %% Environment Modules
    subgraph "Environment Modules"
        subgraph "Development"
            devCfg["config.js"]:::env
            devIdp["identityProvider.js"]:::env
        end
        subgraph "Staging"
            stageCfg["config.js"]:::env
            stageIdp["identityProvider.js"]:::env
        end
        subgraph "Production"
            prodCfg["config.js"]:::env
            prodIdp["identityProvider.js"]:::env
        end
    end

    %% Page-Based Modules
    subgraph "Page-Based Modules"
        generalPages["General Pages (/src/pages)"]:::pages
        homeCollection["Home Collection Module (/src/pages/homeCollection)"]:::pages
        siteCollection["Site Collection Module (/src/pages/siteCollection)"]:::pages
        specificPages["Other Specific Pages (/src/pages)"]:::pages
    end

    %% Shared Utilities
    subgraph "Shared Utilities"
        sharedUtil["shared.js"]:::shared
        eventsUtil["events.js"]:::shared
        fieldMapping["fieldToConceptIdMapping.js"]:::shared
        navbarUtil["navbar.js"]:::shared
        shippingState["shippingState.js"]:::shared
        tubeValidation["tubeValidation.js"]:::shared
    end

    %% Static Assets
    subgraph "Static Assets"
        cssAssets["CSS (/static/css)"]:::static
        imageAssets["Images (/static/images)"]:::static
        libAssets["Libraries (/static/lib)"]:::static
    end

    %% Connections between components
    idxHtml -->|"loads"| idxJS
    idxHtml -->|"loads"| cssAssets
    idxHtml -->|"loads"| imageAssets
    idxHtml -->|"loads"| libAssets

    idxJS -->|"registers"| sw
    idxJS -->|"loads"| manifest

    %% Environment configuration loading
    idxJS -->|"loads"| devCfg
    idxJS -->|"loads"| devIdp
    idxJS -->|"loads"| stageCfg
    idxJS -->|"loads"| stageIdp
    idxJS -->|"loads"| prodCfg
    idxJS -->|"loads"| prodIdp

    %% Navigation to page modules
    idxJS -->|"navigates"| generalPages
    idxJS -->|"navigates"| homeCollection
    idxJS -->|"navigates"| siteCollection
    idxJS -->|"navigates"| specificPages

    %% Pages use shared utilities (representative connection)
    generalPages -->|"uses"| sharedUtil
    homeCollection -->|"uses"| sharedUtil
    siteCollection -->|"uses"| sharedUtil
    specificPages -->|"uses"| sharedUtil

    %% Styling: define classes for coloring
    classDef front fill:#f9c74f,stroke:#000,stroke-width:1px;
    classDef pwa fill:#9d4edd,stroke:#000,stroke-width:1px;
    classDef env fill:#90be6d,stroke:#000,stroke-width:1px;
    classDef pages fill:#277da1,stroke:#000,stroke-width:1px;
    classDef shared fill:#f3722c,stroke:#000,stroke-width:1px;
    classDef static fill:#43aa8b,stroke:#000,stroke-width:1px;

    %% Click Events for Frontend Entry
    click idxHtml "https://github.com/nci-c4cp/biospecimen/blob/master//index.html"
    click idxJS "https://github.com/nci-c4cp/biospecimen/blob/master//index.js"

    %% Click Events for PWA Components
    click sw "https://github.com/nci-c4cp/biospecimen/blob/master//serviceWorker.js"
    click manifest "https://github.com/nci-c4cp/biospecimen/blob/master//manifest.json"

    %% Click Events for Environment Modules - Development
    click devCfg "https://github.com/nci-c4cp/biospecimen/blob/master//src/dev/config.js"
    click devIdp "https://github.com/nci-c4cp/biospecimen/blob/master//src/dev/identityProvider.js"

    %% Click Events for Environment Modules - Staging
    click stageCfg "https://github.com/nci-c4cp/biospecimen/blob/master//src/stage/config.js"
    click stageIdp "https://github.com/nci-c4cp/biospecimen/blob/master//src/stage/identityProvider.js"

    %% Click Events for Environment Modules - Production
    click prodCfg "https://github.com/nci-c4cp/biospecimen/blob/master//src/prod/config.js"
    click prodIdp "https://github.com/nci-c4cp/biospecimen/blob/master//src/prod/identityProvider.js"

    %% Click Events for Page-Based Modules
    click generalPages "https://github.com/nci-c4cp/biospecimen/tree/master//src/pages"
    click homeCollection "https://github.com/nci-c4cp/biospecimen/tree/master//src/pages/homeCollection"
    click siteCollection "https://github.com/nci-c4cp/biospecimen/tree/master//src/pages/siteCollection"
    click specificPages "https://github.com/nci-c4cp/biospecimen/blob/master//src/pages/bptl.js"

    %% Click Events for Shared Utilities
    click sharedUtil "https://github.com/nci-c4cp/biospecimen/blob/master//src/shared.js"
    click eventsUtil "https://github.com/nci-c4cp/biospecimen/blob/master//src/events.js"
    click fieldMapping "https://github.com/nci-c4cp/biospecimen/blob/master//src/fieldToConceptIdMapping.js"
    click navbarUtil "https://github.com/nci-c4cp/biospecimen/blob/master//src/navbar.js"
    click shippingState "https://github.com/nci-c4cp/biospecimen/blob/master//src/shippingState.js"
    click tubeValidation "https://github.com/nci-c4cp/biospecimen/blob/master//src/tubeValidation.js"

    %% Click Events for Static Assets
    click cssAssets "https://github.com/nci-c4cp/biospecimen/tree/master//static/css"
    click imageAssets "https://github.com/nci-c4cp/biospecimen/tree/master//static/images"
    click libAssets "https://github.com/nci-c4cp/biospecimen/tree/master//static/lib"
```
