# kaminaly/react-pug-react-scripts architecture

> Architecture diagram of the GitHub repository kaminaly/react-pug-react-scripts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kaminaly/react-pug-react-scripts
- Repository: https://github.com/kaminaly/react-pug-react-scripts

## Overview

##### Main Components
- CLI/Entry Point: Show the “bin” folder (especially the react-scripts.js file) that serves as the main executable for developers. It kick-starts the application lifecycle.
- Configuration: Include a “config” component that bundles environment settings, webpack configurations (webpack.config.js and webpackDevServer.config.js), Jest configurations (and its subfiles like babelTransform.js, cssTransform.js, fileTransform.js), and other module/path settings. This represents the customization layer that integrates react-pug.
- Scripts: Represent the “scripts” directory which contains build.js, start.js, test.js, eject.js, and supporting utility modules. These scripts control building, development, testing, and eject operations.
- Test Fixtures: Add a component for “fixtures” (specifically the kitchensink example) that includes test projects complete with environment files, integration tests, source files (React components, features for syntax support, webpack asset tests) to ensure the customization works as expected.
- Templates: Show both “template” and “template-typescript” directories. These provide starter projects that users will get when they create a new app using this custom react-scripts.
- Library/Type Definitions: A component for the “lib” directory, which houses type definitions such as react-app.d.ts, helps clarify any TypeScript-specific extensions or interfaces.

##### Relationships and Data Flow
- A user (developer) uses the CLI tool (via npx create-react-app with the special scripts version) to bootstrap a project.
- This command triggers the “bin/react-scripts.js” which, using the configurations from the “config” directory, sets up the environment.
- Depending on the developer’s actions (starting, testing, building, ejecting), corresponding scripts (inside the “scripts” folder) are called.
- During the build and runtime process, webpack and Babel configurations (from “config/webpack.config.js” and Babel transforms) apply transformations such as converting Pug templates through babel-plugin-transform-react-pug.
- Test and integration files (in “fixtures”) ensure these processes work as intended, while the “template” directories provide the initial structure for projects created with this tool.

##### Architectural Patterns and Key Technologies
- The separation of configuration, scripts, templates, and test fixtures demonstrates modular architecture. This division mirrors the design in the original create-react-app while adding a new transformation layer.
- That the customization revolves around integrating a Babel plugin (babel-plugin-transform-react-pug) to support Pug in React alongside typical React app building.
- How environment variables (using various .env files in fixtures) and testing setups (Jest in “config/jest” and integration tests) are organized.
- Mention that there is special handling for TypeScript projects with dedicated templates (template-typescript) and type definitions (in “lib”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Layer: User Interaction
    U("Developer"):::cli
    CLI("CLI (react-scripts.js)"):::cli

    U -->|"invokes"| CLI

    %% Middle Layer: Configuration and Scripts
    subgraph "Configuration"
        Conf("config"):::config
        WC("webpack.config.js"):::config
        DSC("webpackDevServer.config.js"):::config
        JC("Jest Config"):::config
        Conf --> WC
        Conf --> DSC
        Conf --> JC
    end

    subgraph "Scripts"
        SCR("scripts"):::scripts
        BLD("build.js"):::scripts
        STR("start.js"):::scripts
        TST("test.js"):::scripts
        EJT("eject.js"):::scripts
        UT("utils"):::scripts
        SCR --> BLD
        SCR --> STR
        SCR --> TST
        SCR --> EJT
        SCR --> UT
    end

    CLI -->|"loads"| Conf
    CLI -->|"triggers"| SCR

    %% Bottom Layer: Project Resources
    subgraph "Project Resources"
        TPL("Template (JavaScript)"):::templates
        TPT("Template (TypeScript)"):::templates
        FX("Fixtures (kitchensink)"):::fixtures
        LIB("Library (react-app.d.ts)"):::lib
    end

    CLI -->|"scaffolds"| TPL
    CLI -->|"scaffolds"| TPT
    CLI -->|"tests with"| FX
    CLI -->|"uses"| LIB

    %% Click Events
    click CLI "https://github.com/kaminaly/react-pug-react-scripts/blob/master/bin/react-scripts.js"
    click Conf "https://github.com/kaminaly/react-pug-react-scripts/tree/master/config"
    click WC "https://github.com/kaminaly/react-pug-react-scripts/blob/master/config/webpack.config.js"
    click DSC "https://github.com/kaminaly/react-pug-react-scripts/blob/master/config/webpackDevServer.config.js"
    click JC "https://github.com/kaminaly/react-pug-react-scripts/tree/master/config/jest"
    click SCR "https://github.com/kaminaly/react-pug-react-scripts/tree/master/scripts"
    click BLD "https://github.com/kaminaly/react-pug-react-scripts/blob/master/scripts/build.js"
    click STR "https://github.com/kaminaly/react-pug-react-scripts/blob/master/scripts/start.js"
    click TST "https://github.com/kaminaly/react-pug-react-scripts/blob/master/scripts/test.js"
    click EJT "https://github.com/kaminaly/react-pug-react-scripts/blob/master/scripts/eject.js"
    click UT "https://github.com/kaminaly/react-pug-react-scripts/tree/master/scripts/utils"
    click FX "https://github.com/kaminaly/react-pug-react-scripts/tree/master/fixtures/kitchensink"
    click TPL "https://github.com/kaminaly/react-pug-react-scripts/tree/master/template"
    click TPT "https://github.com/kaminaly/react-pug-react-scripts/tree/master/template-typescript"
    click LIB "https://github.com/kaminaly/react-pug-react-scripts/blob/master/lib/react-app.d.ts"

    %% Styles
    classDef cli fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef config fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef scripts fill:#F0E68C,stroke:#000,stroke-width:2px;
    classDef fixtures fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef templates fill:#FFC0CB,stroke:#000,stroke-width:2px;
    classDef lib fill:#D8BFD8,stroke:#000,stroke-width:2px;
```
