# assem-gh/csv-viewer architecture

> Architecture diagram of the GitHub repository assem-gh/csv-viewer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/assem-gh/csv-viewer
- Repository: https://github.com/assem-gh/csv-viewer

## Overview

##### Project Type and Purpose
- This is a client-side, single-page React application named “CSV-Viewer.”
- Purpose: let users import, view, edit, export CSV data and render charts.
- No backend/microservice layer—everything runs in the browser, relying on local file input/output and in-memory state.

##### File Structure Analysis
- Top level
- index.html  – HTML shell
- public/     – static assets, sample CSV data, images
- src/        – React/TypeScript source
- src/main.tsx + src/App.tsx          – application entrypoint and root component
- src/store/                            – Redux Toolkit slices (gridSlice, uiSlice), store setup, typed hooks
- src/helpers/                          – CSV parsing (PapaParse wrapper), chart data computation, formatting utilities
- src/Components/                       – reusable UI pieces (buttons, modals, drawers, DataGrid subcomponents)
- src/Pages/                            – DataGridPage and StartPage (route targets)
- Configuration                         – vite.config.ts, tsconfig.json etc.

##### Key Technologies (from README)
- React + TypeScript
- Redux Toolkit (state management)
- PapaParse (CSV parsing)
- AG-Grid (data grid UI)
- AG-Chart (charting)
- Mantine (UI library)

##### Main Components & Relationships
- User Browser: hosts the React SPA
- File Input Module (FileUploadButton) → PapaParse helper → CSV data
- Redux Store:
- gridSlice holds tabular data and edits
- uiSlice manages modal/drawer state, pagination, loading flags
- DataGridPage:
- AG-Grid component reads from gridSlice selector
- DataGridToolbar, PaginationControl, RowControl, Actions all dispatch Redux actions
- AddRowDrawer & AppDrawer open on dispatch from toolbar/menu
- ChartForm & ChartModal:
- User selects columns → passes to calculateChartData → AG-Chart renders inside ChartModal
- Export Module: transforms Redux state back to CSV string → triggers browser download

##### Architectural Patterns & Design Principles
- Unidirectional data flow (React → Redux → React)
- Component hierarchy:
- Pages at top, composite Components next, leaf Components for buttons, modals, etc.
- Separation of concerns: parsing & data formatting live in helpers, UI in Components, state in store
- Single-responsibility: each slice, helper, and component focuses on one aspect

- Clear component/module names matching folder/package names
- Annotations for key Redux slices and helpers

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Host Environment
    subgraph "Browser Host Environment"
        direction TB
        U1(("User Upload CSV")):::action
        U2(("User Export CSV")):::action
        U3(("User Open Chart")):::action
    end

    %% File I/O Layer
    subgraph "File I/O Layer"
        direction TB
        FUB[/FileUploadButton/]:::dataio
        EM[/Export Module/]:::dataio
    end

    %% Data Processing Layer
    subgraph "Data Processing Layer"
        direction TB
        PC["parseCsv()"]:::processing
        CC["calculateChartData()"]:::processing
        DF["dataFormat()"]:::processing
        FS["formatFileSize()"]:::processing
    end

    %% State Management Layer
    subgraph "State Management Layer"
        direction TB
        S[(Redux Store)]:::state
        GS[gridSlice]:::state
        US[uiSlice]:::state
        HK[hooks.ts]:::state
    end

    %% React Application Layer
    subgraph "React Application Layer"
        direction TB
        ME[main.tsx]:::app
        AP[App.tsx]:::app
        SP[StartPage.tsx]:::app
        DP[DataGridPage.tsx]:::app
    end

    %% UI Components Layer
    subgraph "UI Components Layer"
        direction TB
        subgraph "Data Grid Components"
            direction TB
            DGT[DataGridToolbar]:::ui
            PCn[PaginationControl]:::ui
            RC[RowControl]:::ui
            DGA[DataGridActions]:::ui
        end
        subgraph "Chart Components"
            direction TB
            CF[ChartForm]:::ui
            CM[ChartModal]:::ui
        end
        subgraph "Drawers"
            direction TB
            ARD[AddRowDrawer]:::ui
            AD[AppDrawer]:::ui
        end
        subgraph "Modals"
            direction TB
            AM[AppModal]:::ui
            ISM[ImportSuccessModal]:::ui
            CM
        end
        subgraph "Additional UI Helpers"
            direction TB
            AH[AppHeader]:::ui
            DSB[DataSourceButton]:::ui
        end
    end

    %% Connections
    U1 -->|select file| FUB
    FUB -->|invoke parseCsv| PC
    PC -->|parsed data| S
    PC -->|uses formatFileSize| FS
    PC -->|uses dataFormat| DF
    U2 -->|click export| EM
    EM -->|generate CSV from state| S
    EM -->|download| U2

    S -->|provide data| DP
    DP -->|renders grid| DGT
    DP -->|renders grid| PCn
    DP -->|renders grid| RC
    DP -->|renders grid| DGA

    DGT -->|dispatch actions| S
    PCn -->|dispatch actions| S
    RC -->|dispatch actions| S
    DGA -->|dispatch actions| S

    ME --> AP
    AP --> SP
    AP --> DP

    U3 --> CF
    CF -->|generate chartData| CC
    CC --> CM
    CM -->|render chart| CM

    %% Store slices linkage
    S --> GS
    S --> US
    S --> HK

    %% Click Events
    click ME "https://github.com/assem-gh/csv-viewer/blob/main/src/main.tsx"
    click AP "https://github.com/assem-gh/csv-viewer/blob/main/src/App.tsx"
    click SP "https://github.com/assem-gh/csv-viewer/blob/main/src/Pages/StartPage.tsx"
    click DP "https://github.com/assem-gh/csv-viewer/blob/main/src/Pages/DataGridPage.tsx"
    click FUB "https://github.com/assem-gh/csv-viewer/blob/main/src/Components/FileUploadButton.tsx"
    click PC "https://github.com/assem-gh/csv-viewer/blob/main/src/helpers/parseCsv.ts"
    click CC "https://github.com/assem-gh/csv-viewer/blob/main/src/helpers/calculateChartData.ts"
    click DF "https://github.com/assem-gh/csv-viewer/blob/main/src/helpers/dataFormat.ts"
    click FS "https://github.com/assem-gh/csv-viewer/blob/main/src/helpers/formatFileSize.ts"
    click GS "https://github.com/assem-gh/csv-viewer/blob/main/src/store/gridSlice.ts"
    click US "https://github.com/assem-gh/csv-viewer/blob/main/src/store/uiSlice.ts"
    click HK "https://github.com/assem-gh/csv-viewer/blob/main/src/store/hooks.ts"
    click S "https://github.com/assem-gh/csv-viewer/blob/main/src/store/store.ts"
    click DGT "https://github.com/assem-gh/csv-viewer/blob/main/src/Components/DataGrid/DataGridToolbar.tsx"
    click PCn "https://github.com/assem-gh/csv-viewer/blob/main/src/Components/DataGrid/PaginationControl.tsx"
    click RC "https://github.com/assem-gh/csv-viewer/blob/main/src/Components/DataGrid/RowControl.tsx"
    click DGA "https://github.com/assem-gh/csv-viewer/blob/main/src/Components/DataGrid/DataGridActions.tsx"
    click CF "https://github.com/assem-gh/csv-viewer/blob/main/src/Components/ChartForm.tsx"
    click CM "https://github.com/assem-gh/csv-viewer/blob/main/src/Components/Modals/ChartModal.tsx"
    click ARD "https://github.com/assem-gh/csv-viewer/blob/main/src/Components/Drawers/AddRowDrawer.tsx"
    click AD "https://github.com/assem-gh/csv-viewer/blob/main/src/Components/Drawers/AppDrawer.tsx"
    click AM "https://github.com/assem-gh/csv-viewer/blob/main/src/Components/Modals/AppModal.tsx"
    click ISM "https://github.com/assem-gh/csv-viewer/blob/main/src/Components/Modals/ImportSuccessModal.tsx"
    click AH "https://github.com/assem-gh/csv-viewer/blob/main/src/Components/AppHeader.tsx"
    click DSB "https://github.com/assem-gh/csv-viewer/blob/main/src/Components/DataSourceButton.tsx"

    %% Styles
    classDef dataio fill:#ffe4b5,stroke:#cc9f71
    classDef processing fill:#d1e7dd,stroke:#19692c
    classDef state fill:#e2e3e5,stroke:#6c757d
    classDef app fill:#cfe2ff,stroke:#084298
    classDef ui fill:#f8d7da,stroke:#842029
    classDef action fill:#fff3cd,stroke:#856404
```
