# connectaryal/word-counter architecture

> Architecture diagram of the GitHub repository connectaryal/word-counter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/connectaryal/word-counter
- Repository: https://github.com/connectaryal/word-counter

## Overview

##### Project type and purpose
- This is a single-page application (SPA) front-end project built with React, TypeScript, and Vite.
- Purpose: provide a minimal React+TS template with hot-module replacement (HMR), ESLint, and Tailwind CSS integration. It includes a simple word-count feature (textarea → stats).

##### File structure
Top-level:
- index.html         → root HTML shell, loads the Vite bundle
- package.json, package-lock.json
- config files: tsconfig.json/.node.json, vite.config.ts, postcss.config.js, tailwind.config.js, .eslintrc.cjs
- /src
- main.tsx        → entry point, mounts <App/>
- App.tsx         → root component, orchestrates layout
- index.css       → global CSS import (Tailwind base, components, utilities)
- /components     → UI building blocks
· header, footer, textarea, counter, hooks
- /services       → business logic (word.service.ts counts words)
- /helpers        → style helpers, common utilities

##### README
- Confirms the stack: React + TS + Vite, plus ESLint recommendations and available plugins.
- Advises on expanding lint rules (not directly affecting runtime architecture).

a. Main components
- Developer machine
‣ Code editor → runs Vite dev server (vite.config.ts)
‣ ESLint + TypeScript compiler (tsconfig.json)
- Vite Dev Server / Build Pipeline
‣ Reads index.html, TSX, CSS, Tailwind config, PostCSS → bundles into JS/CSS
- Browser (User)
‣ index.html + bundle.js + styles.css
‣ Browser DOM renderer
- React App
‣ App.tsx (Root)
· Header
· Textarea (user input)
↳ uses useWordCount hook
· Counter/Stats (displays result from word.service)
· Footer
- Services & Helpers
‣ word.service.ts: pure function for word counting
‣ style.helper.ts: utility for dynamic class names
- External libraries
‣ React, ReactDOM, Vite plugin, TailwindCSS, PostCSS, ESLint plugins

b. Relationships & interactions
1. Developer triggers “npm run dev” → Vite starts dev server
2. Vite watches /src and /public → hot-reloads on save
3. Browser requests index.html → Vite serves processed HTML + JS + CSS
4. main.tsx mounts <App/>, which renders Header, Textarea, Counter, Footer
5. User types in Textarea → onChange → useWordCount hook calls word.service.count() → returns stats → Counter updates UI
6. style.helper merges Tailwind classes for components

c. Architectural patterns
- Component-based UI (React function components)
- Unidirectional data flow (props & hook state)
- Service layer for business logic (separation from UI)
- Build pipeline abstraction (Vite + plugins)
- CSS utility-first (Tailwind + PostCSS)

d. Key technologies
- React & ReactDOM
- TypeScript (static typing, tsconfig)
- Vite (fast build & HMR, vite.config.ts)
- Tailwind CSS + PostCSS (tailwind.config.js, postcss.config.js)
- ESLint + TypeScript-ESLint + React plugin (.eslintrc.cjs)

##### Detail
- Layer: Developer, Build, Runtime
- Separate by function: UI vs logic vs config vs assets
- Don’t over-complicate: show all components, services, and their interactions clearly.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Developer Environment
    subgraph "Developer Environment"
        DE1["Code Editor"]
        DE2["ESLint + TypeScript Compiler"]:::config
    end

    %% Build Pipeline
    subgraph "Build Pipeline / Vite"
        VITECFG["vite.config.ts"]:::config
        TAILWINDCFG["tailwind.config.js"]:::config
        POSTCSSCFG["postcss.config.js"]:::config
        VITE["Vite Dev Server"]:::config
    end

    %% Browser Runtime
    subgraph "Browser Runtime"
        HTML["index.html"]:::config
        CSS["bundle.css"]:::config
        JS["bundle.js"]:::config
        MAIN["main.tsx"]:::ui
        REACTDOM["ReactDOM.render"]:::external
        subgraph "React App"
            ROOT["App.tsx"]:::ui
            HEADER["Header"]:::ui
            TEXTAREA["Textarea"]:::ui
            COUNTER["Counter"]:::ui
            STATS["Stats"]:::ui
            FOOTER["Footer"]:::ui
        end
    end

    %% Services & Helpers
    SERVICE["word.service.ts"]:::service
    HOOK["useWordCount Hook"]:::service
    HELPER["style.helper.ts"]:::service

    %% Static Assets
    PUBLIC["public/ (Static Assets)"]:::assets

    %% External Libraries
    REACT["React & ReactDOM"]:::external
    VITEPLUG["Vite Plugins"]:::external
    TAILWINDPLUG["TailwindCSS & PostCSS"]:::external
    ESLINTPLUG["ESLint Plugins"]:::external

    %% Connections
    DE1 -->|"runs npm run dev"| VITE
    DE2 --> VITE
    VITECFG --> VITE
    TAILWINDCFG --> VITE
    POSTCSSCFG --> VITE
    VITE --> HTML
    VITE --> CSS
    VITE --> JS
    VITE --> PUBLIC
    HTML --> MAIN
    JS --> MAIN
    MAIN --> REACTDOM
    REACTDOM --> ROOT
    ROOT --> HEADER
    ROOT --> TEXTAREA
    ROOT --> COUNTER
    ROOT --> FOOTER
    TEXTAREA -->|"onChange"| HOOK
    HOOK --> SERVICE
    SERVICE --> COUNTER
    COUNTER --> STATS
    HEADER -->|uses| HELPER
    FOOTER -->|uses| HELPER
    ROOT -->|styles via| HELPER
    PUBLIC -->|served by| VITE
    REACT --> REACTDOM
    VITEPLUG --> VITE
    TAILWINDPLUG --> VITE
    ESLINTPLUG --> DE2

    %% Click Events
    click MAIN "https://github.com/connectaryal/word-counter/blob/dev/src/main.tsx"
    click ROOT "https://github.com/connectaryal/word-counter/blob/dev/src/App.tsx"
    click CSS "https://github.com/connectaryal/word-counter/blob/dev/src/index.css"
    click HEADER "https://github.com/connectaryal/word-counter/blob/dev/src/components/header/index.tsx"
    click TEXTAREA "https://github.com/connectaryal/word-counter/blob/dev/src/components/textarea/index.tsx"
    click COUNTER "https://github.com/connectaryal/word-counter/blob/dev/src/components/counter/index.tsx"
    click STATS "https://github.com/connectaryal/word-counter/blob/dev/src/components/counter/stats.tsx"
    click FOOTER "https://github.com/connectaryal/word-counter/blob/dev/src/components/footer/index.tsx"
    click HOOK "https://github.com/connectaryal/word-counter/blob/dev/src/components/hooks/useWordCount.tsx"
    click SERVICE "https://github.com/connectaryal/word-counter/blob/dev/src/services/word.service.ts"
    click HELPER "https://github.com/connectaryal/word-counter/blob/dev/src/helpers/style.helper.ts"
    click PUBLIC "https://github.com/connectaryal/word-counter/tree/dev/public/"
    click VITECFG "https://github.com/connectaryal/word-counter/blob/dev/vite.config.ts"
    click TAILWINDCFG "https://github.com/connectaryal/word-counter/blob/dev/tailwind.config.js"
    click POSTCSSCFG "https://github.com/connectaryal/word-counter/blob/dev/postcss.config.js"
    click DE2 "https://github.com/connectaryal/word-counter/blob/dev/.eslintrc.cjs"
    click DE2 "https://github.com/connectaryal/word-counter/blob/dev/tsconfig.json"
    click HTML "https://github.com/connectaryal/word-counter/blob/dev/index.html"
    click VITEPLUG "https://github.com/connectaryal/word-counter/blob/dev/package.json"
    click TAILWINDPLUG "https://github.com/connectaryal/word-counter/blob/dev/package.json"
    click ESLINTPLUG "https://github.com/connectaryal/word-counter/blob/dev/package.json"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366d6,stroke-width:1px
    classDef service fill:#E6FFEA,stroke:#1F8A70,stroke-width:1px
    classDef config fill:#FFF4E5,stroke:#D9822B,stroke-width:1px
    classDef assets fill:#F0F0F0,stroke:#A0A0A0,stroke-width:1px,stroke-dasharray: 5 5
    classDef external fill:#F5F5FF,stroke:#6F42C1,stroke-width:1px,stroke-dasharray: 2 2
```
