# punchbat/react-boilerplate-cra-template architecture

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

- Interactive diagram: https://gitdiagram.com/punchbat/react-boilerplate-cra-template
- Repository: https://github.com/punchbat/react-boilerplate-cra-template

## Overview

##### Project type & purpose
- This is a **CRA template** (npm package `cra-template-rb`) that bootstraps a React + TypeScript + Redux + Saga + i18n + styled-components project.
- It also contains **internal scripts** and **Plop generators** for quick scaffolding of components, routes, slices, sagas, tests, etc.

##### File structure
- **internals/** – Node-based CLI scripts, Plop generators, message extraction pipeline, starter-template source.
- **public/** + **src/** – the “**startingTemplate**” (and what ends up in a user’s new app).  Inside src:
– app/components, pages (Home, NotFound), features (RepoForm, ThemeSwitch, LanguageSwitch)
– store (Redux Toolkit + sagas)
– locales (i18n via i18next)
– styles (styled-components, ThemeProvider, globals)
– utils (loadable, message handling, redux-injectors, HTTP requests)
– tests co-located with code
- **.github/workflows/** – CI (build, lint, test, release)
- Root scripts/configs – ESLint, Prettier, Husky, commitlint, TypeScript config, release tooling

##### Key insights from README
- **best DX**: hot reload, lint/format on-save, high test coverage
- **Predictable state**: Redux + redux-saga + Redux Toolkit + selectors
- **Next-gen CSS**: styled-components, theming, co-located styles
- **Routing**: react-router
- **i18n**: i18next + JSON translation files
- **CLI scaffolding**: `yarn create react-app --template cra-template-rb` + `yarn cleanAndSetup`

##### Main components & their relationships
a. **Developer/Consumer**
– invokes:
- `create-react-app --template cra-template-rb`
- internal scripts (`cleanAndSetup`, `create-cra-app.script.ts`, etc.)
b. **Template Package (npm)**
– contains `internals/` and `startingTemplate/`
– on install: runs `create-cra-app` script → copies `startingTemplate` into new project → sets up configs, dependencies
c. **Code-gen & Extraction Pipeline**
– **Plop Generators** (component, slice)
– **extractMessages** (i18next scanner)
– **scripts/** for changelog, publishing, verifying template
d. **Generated Application**
– **public/** (index.html, manifest, robots.txt)
– **src/**:
- **app** (layout, NavBar, PageWrapper)
- **pages** (HomePage, NotFoundPage)
- **features** (Redux slices & sagas under pages)
- **store** (rootReducer, configureStore)
- **locales** (en/de JSON + i18n setup)
- **styles** (global, theme provider, constants)
- **utils** (code splitting, HTTP requests, redux injectors)
- **tests** (co-located Jest + React Testing Library)
e. **CI/CD & Release**
– GitHub Actions: build, lint, test, release
– NPM registry: template is published here
– optional deploy docs (AWS, Azure, Heroku, Netlify)

##### Architectural patterns & design principles
- **Separation of concerns**: `internals/` vs. `startingTemplate/`; `components` vs. `pages` vs. `store` vs. `styles` vs. `utils`.
- **Unidirectional data flow**: Redux + Saga → selectors → React components.
- **Modular code**: Plop generators enforce slice/component conventions; co-located tests.
- **Dynamic code-splitting**: `loadable.tsx` for lazy loading pages/components.
- **i18n pipeline**: extractor → JSON files → `i18n.ts` loader.
- **Theming**: styled-components + context via ThemeProvider + slice for theme state.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Developer / CLI
    subgraph "Developer / CLI"
        CLI["Developer invokes\n`yarn create react-app --template cra-template-rb`\nand `yarn cleanAndSetup`"]:::developer
    end

    %% Template Package internals
    subgraph "Template Package (internals/)" 
        extractMessages["extractMessages\n(i18next-scanner)"]:::pipeline
        plopfile["Plopfile\ninternals/generators/plopfile.ts"]:::pipeline
        genComponent["Generator: component"]:::pipeline
        genSlice["Generator: slice"]:::pipeline
        createAppScript["create-cra-app.script.ts"]:::pipeline
        cleanScript["clean.ts"]:::pipeline
        npmPackageScript["create-npm-package.script.ts"]:::pipeline
        verifyScript["verify-startingTemplate-changes.ts"]:::pipeline
        startingTemplatePublic["startingTemplate/public"]:::package
        startingTemplateSrc["startingTemplate/src"]:::package
    end

    %% Code Generation & Extraction Pipeline
    subgraph "Code Generation & Extraction Pipeline"
        extConfig["i18next-scanner.config.js"]:::pipeline
        stringify["stringfyTranslations.js"]:::pipeline
        plopTemplates["Plop generators\n(internals/generators/)"]:::pipeline
        scriptsPipeline["Scripts pipeline\n(internals/scripts/)"]:::pipeline
    end

    %% Generated Application
    subgraph "Generated Application\n(public/ & src/)"
        pub["public/"]:::app
        srcApp["src/app/components/"]:::app
        srcPages["src/pages/"]:::app
        store["src/store/"]:::app
        locales["src/locales/"]:::app
        styles["src/styles/"]:::app
        utils["src/utils/"]:::app
        types["src/types/"]:::app
        setupTests["src/setupTests.ts"]:::app
        reportWebVitals["src/reportWebVitals.ts"]:::app
    end

    %% CI/CD & Release
    subgraph "CI/CD & Release"
        gha[".github/workflows/"]:::ci
        husky[".husky/"]:::ci
        commitlint["commitlint.config.js"]:::ci
        eslint[".eslintrc.js"]:::ci
        prettier[".prettierrc"]:::ci
        tsconfig["tsconfig.json"]:::ci
        versionrc[".versionrc.js"]:::ci
        npmRegistry["NPM Registry"]:::external
        deployTargets["Deployment Targets\n(AWS, Netlify, Heroku)"]:::external
    end

    %% Connections
    CLI --> createAppScript
    createAppScript --> startingTemplatePublic
    createAppScript --> startingTemplateSrc
    CLI --> cleanScript
    CLI --> npmPackageScript
    CLI --> verifyScript
    CLI --> plopfile
    CLI --> extractMessages

    startingTemplatePublic --> pub
    startingTemplateSrc --> srcApp
    startingTemplateSrc --> srcPages
    startingTemplateSrc --> store
    startingTemplateSrc --> locales
    startingTemplateSrc --> styles
    startingTemplateSrc --> utils
    startingTemplateSrc --> types
    startingTemplateSrc --> setupTests
    startingTemplateSrc --> reportWebVitals

    plopfile --> plopTemplates
    extractMessages --> extConfig
    extractMessages --> stringify
    scriptsPipeline --> verifyScript
    plopTemplates --> srcApp
    plopTemplates --> srcPages
    plopTemplates --> store
    extConfig --> locales
    stringify --> locales

    pub --> gha
    srcApp --> gha
    srcPages --> gha
    store --> gha
    locales --> gha
    styles --> gha
    utils --> gha
    types --> gha
    setupTests --> gha
    reportWebVitals --> gha

    gha --> npmRegistry
    gha --> deployTargets

    %% Click Events
    click extractMessages "https://github.com/punchbat/react-boilerplate-cra-template/tree/master/internals/extractMessages/"
    click plopfile "https://github.com/punchbat/react-boilerplate-cra-template/blob/master/internals/generators/plopfile.ts"
    click genComponent "https://github.com/punchbat/react-boilerplate-cra-template/tree/master/internals/generators/component/"
    click genSlice "https://github.com/punchbat/react-boilerplate-cra-template/tree/master/internals/generators/slice/"
    click createAppScript "https://github.com/punchbat/react-boilerplate-cra-template/blob/master/internals/scripts/create-cra-app.script.ts"
    click cleanScript "https://github.com/punchbat/react-boilerplate-cra-template/blob/master/internals/scripts/clean.ts"
    click npmPackageScript "https://github.com/punchbat/react-boilerplate-cra-template/blob/master/internals/scripts/create-npm-package.script.ts"
    click verifyScript "https://github.com/punchbat/react-boilerplate-cra-template/blob/master/internals/scripts/verify-startingTemplate-changes.ts"
    click startingTemplatePublic "https://github.com/punchbat/react-boilerplate-cra-template/tree/master/internals/startingTemplate/public/"
    click startingTemplateSrc "https://github.com/punchbat/react-boilerplate-cra-template/tree/master/internals/startingTemplate/src/"
    click extConfig "https://github.com/punchbat/react-boilerplate-cra-template/blob/master/internals/extractMessages/i18next-scanner.config.js"
    click stringify "https://github.com/punchbat/react-boilerplate-cra-template/blob/master/internals/extractMessages/stringfyTranslations.js"
    click plopTemplates "https://github.com/punchbat/react-boilerplate-cra-template/tree/master/internals/generators/"
    click scriptsPipeline "https://github.com/punchbat/react-boilerplate-cra-template/tree/master/internals/scripts/"
    click pub "https://github.com/punchbat/react-boilerplate-cra-template/tree/master/public/"
    click srcApp "https://github.com/punchbat/react-boilerplate-cra-template/tree/master/src/app/components/"
    click srcPages "https://github.com/punchbat/react-boilerplate-cra-template/tree/master/src/pages/"
    click store "https://github.com/punchbat/react-boilerplate-cra-template/tree/master/src/store/"
    click locales "https://github.com/punchbat/react-boilerplate-cra-template/tree/master/src/locales/"
    click styles "https://github.com/punchbat/react-boilerplate-cra-template/tree/master/src/styles/"
    click utils "https://github.com/punchbat/react-boilerplate-cra-template/tree/master/src/utils/"
    click types "https://github.com/punchbat/react-boilerplate-cra-template/tree/master/src/types/"
    click setupTests "https://github.com/punchbat/react-boilerplate-cra-template/blob/master/src/setupTests.ts"
    click reportWebVitals "https://github.com/punchbat/react-boilerplate-cra-template/blob/master/src/reportWebVitals.ts"
    click gha "https://github.com/punchbat/react-boilerplate-cra-template/tree/master/.github/workflows/"
    click husky "https://github.com/punchbat/react-boilerplate-cra-template/tree/master/.husky/"
    click commitlint "https://github.com/punchbat/react-boilerplate-cra-template/blob/master/commitlint.config.js"
    click eslint "https://github.com/punchbat/react-boilerplate-cra-template/blob/master/.eslintrc.js"
    click prettier "https://github.com/punchbat/react-boilerplate-cra-template/blob/master/.prettierrc"
    click tsconfig "https://github.com/punchbat/react-boilerplate-cra-template/blob/master/tsconfig.json"
    click versionrc "https://github.com/punchbat/react-boilerplate-cra-template/blob/master/.versionrc.js"

    %% Styles
    classDef developer fill:#D0E8FF,stroke:#1E90FF
    classDef package fill:#FFF2CC,stroke:#FFA500
    classDef pipeline fill:#FFE8C0,stroke:#FFA500
    classDef app fill:#D0FFD0,stroke:#32CD32
    classDef ci fill:#F0F0F0,stroke:#A9A9A9
    classDef external fill:#F0F0F0,stroke:#A9A9A9
```
