# nrwl/nx-examples architecture

> Architecture diagram of the GitHub repository nrwl/nx-examples, 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/nrwl/nx-examples
- Repository: https://github.com/nrwl/nx-examples

## Overview

##### Project Type and Purpose
- This is an Nx‐managed monorepo containing multiple frontend applications (a React “cart” app and an Angular “products” app), end-to-end test suites for each, and a rich set of shared libraries for features (cart page, home page, product detail page), state management, UI components, assets, styling, and tooling.
- It’s designed to enable rapid development of multiple user-facing SPAs with shared code, unified testing, and centralized build/configuration via Nx.

##### File Structure Analysis
- Top-level “apps” folder
- apps/cart – React SPA
- apps/products – Angular SPA
- apps/cart-e2e & apps/products-e2e – Cypress E2E suites
- Top-level “libs” folder grouping:
- Feature libs: libs/cart/cart-page, libs/products/home-page, libs/products/product-detail-page
- Shared feature code: libs/shared/cart/state, libs/shared/product/data, state, types, ui
- Shared UI/helpers: libs/shared/header, libs/shared/styles, libs/shared/jsxify, libs/shared/assets, libs/shared/e2e-utils
- CI/CD scripts under .circleci and tools/scripts/deploy.ts
- Centralized TypeScript, ESLint, Prettier, Babel, and Jest configs

##### Key Insights from README
- Uses Nx to orchestrate builds, tests, and dependency graph generation
- Applications are generated via @nx/react and @nx/angular plugins
- Supports incremental and cached builds/tests (Nx Cloud)
- Encourages sharing code via libraries

a. Main Components
- React Cart App
- Angular Products App
- E2E Test Runner (Cypress)
- Shared Libraries (grouped by domain and concern)
- CI/CD Pipeline (CircleCI + Nx Cloud)
- Tooling Scripts (deploy.ts)
b. Interactions & Dependencies
- Apps import feature libs (cart-page, home-page, product-detail-page) and shared libs (state, UI, types, assets, styles)
- Shared state libs expose Redux/NgRx modules consumed by apps
- Shared UI libs (header, product-price) used across both apps
- E2E projects run tests against the dev or deployed endpoints of the SPAs
- CI/CD pipeline triggers “nx build”, “nx test”, “nx e2e” and uses tooling scripts to deploy artifacts
c. Architectural Patterns & Principles
- Monorepo modularity: clear separation of apps vs. libraries
- Feature-driven libraries: each page/component is its own lib for reuse
- Shared cross-cutting concerns: state management, UI primitives, styling
- Nx dependency graph enforces acyclic dependencies
- CI/CD with computation caching for fast incremental builds
d. Technologies & Frameworks
- React + TypeScript + Webpack for cart
- Angular + TypeScript for products
- Jest for unit tests
- Cypress for end-to-end tests
- Nx dev tools, Babel, ESLint, Prettier

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Workspace Config
    NxConfig["nx.json, tsconfig.base.json"]:::config

    %% CI/CD Pipeline
    pipeline["CircleCI & Nx Cloud"]:::ci
    script["deploy.ts"]:::tool

    %% Applications
    subgraph "Applications"
        CartApp["React Cart App"]:::app
        ProductsApp["Angular Products App"]:::app
    end

    %% E2E Test Suites
    subgraph "E2E Test Suites"
        CartE2E["Cart E2E (Cypress)"]:::e2e
        ProductsE2E["Products E2E (Cypress)"]:::e2e
    end

    %% Feature Libraries
    subgraph "Feature Libraries" 
        CartPage["Cart Page Lib"]:::lib
        HomePage["Home Page Lib"]:::lib
        DetailPage["Product Detail Page Lib"]:::lib
    end

    %% Shared Libraries
    subgraph "Shared Libraries"
        subgraph "Cart Domain"
            SharedCartState["Shared Cart State"]:::state
        end
        subgraph "Product Domain"
            SharedProductData["Shared Product Data"]:::data
            SharedProductState["Shared Product State"]:::state
            SharedProductTypes["Shared Product Types"]:::types
            SharedProductUI["Shared Product UI"]:::lib
        end
        subgraph "Cross-Cutting Concerns"
            Header["Shared Header UI"]:::lib
            JSXify["Shared JSXify Utils"]:::lib
            Styles["Shared Styles"]:::lib
            Assets["Shared Assets"]:::lib
            E2EUtils["Shared E2E Utils"]:::lib
        end
    end

    %% Dependencies
    NxConfig -->|governs| pipeline
    NxConfig -->|defines workspace| CartApp
    NxConfig -->|defines workspace| ProductsApp

    pipeline -->|build/test/e2e| CartApp
    pipeline -->|build/test/e2e| ProductsApp
    pipeline -->|run tests| CartE2E
    pipeline -->|run tests| ProductsE2E
    pipeline -->|trigger deploy| script

    script -->|deploy artifacts| CartApp
    script -->|deploy artifacts| ProductsApp

    CartApp -->|imports| CartPage
    CartApp -->|imports| SharedCartState
    CartApp -->|imports| Header
    CartApp -->|imports| JSXify
    CartApp -->|imports| Styles
    CartApp -->|imports| Assets

    ProductsApp -->|imports| HomePage
    ProductsApp -->|imports| DetailPage
    ProductsApp -->|imports| SharedProductData
    ProductsApp -->|imports| SharedProductState
    ProductsApp -->|imports| SharedProductTypes
    ProductsApp -->|imports| SharedProductUI
    ProductsApp -->|imports| Header
    ProductsApp -->|imports| Styles
    ProductsApp -->|imports| Assets

    CartE2E -->|tests| CartApp
    ProductsE2E -->|tests| ProductsApp

    %% Click Events
    click CartApp "https://github.com/nrwl/nx-examples/tree/master/apps/cart"
    click ProductsApp "https://github.com/nrwl/nx-examples/tree/master/apps/products"
    click CartE2E "https://github.com/nrwl/nx-examples/tree/master/apps/cart-e2e"
    click ProductsE2E "https://github.com/nrwl/nx-examples/tree/master/apps/products-e2e"
    click CartPage "https://github.com/nrwl/nx-examples/tree/master/libs/cart/cart-page"
    click HomePage "https://github.com/nrwl/nx-examples/tree/master/libs/products/home-page"
    click DetailPage "https://github.com/nrwl/nx-examples/tree/master/libs/products/product-detail-page"
    click SharedCartState "https://github.com/nrwl/nx-examples/tree/master/libs/shared/cart/state"
    click SharedProductData "https://github.com/nrwl/nx-examples/tree/master/libs/shared/product/data"
    click SharedProductState "https://github.com/nrwl/nx-examples/tree/master/libs/shared/product/state"
    click SharedProductTypes "https://github.com/nrwl/nx-examples/tree/master/libs/shared/product/types"
    click SharedProductUI "https://github.com/nrwl/nx-examples/tree/master/libs/shared/product/ui"
    click Header "https://github.com/nrwl/nx-examples/tree/master/libs/shared/header"
    click JSXify "https://github.com/nrwl/nx-examples/tree/master/libs/shared/jsxify"
    click Styles "https://github.com/nrwl/nx-examples/tree/master/libs/shared/styles"
    click Assets "https://github.com/nrwl/nx-examples/tree/master/libs/shared/assets"
    click E2EUtils "https://github.com/nrwl/nx-examples/tree/master/libs/shared/e2e-utils"
    click pipeline "https://github.com/nrwl/nx-examples/blob/master/.circleci/config.yml"
    click script "https://github.com/nrwl/nx-examples/blob/master/tools/scripts/deploy.ts"
    click NxConfig "https://github.com/nrwl/nx-examples/blob/master/nx.json, tsconfig.base.json"

    %% Styles
    classDef app fill:#cce5ff,stroke:#005cbf,stroke-width:1px;
    classDef lib fill:#d4edda,stroke:#155724,stroke-width:1px,shape:ellipse;
    classDef state fill:#fff3cd,stroke:#856404,stroke-width:1px,shape:cylinder;
    classDef data fill:#fff3cd,stroke:#856404,stroke-width:1px,shape:cylinder;
    classDef types fill:#d4edda,stroke:#155724,stroke-width:1px,shape:ellipse;
    classDef config fill:#e2e3e5,stroke:#6c757d,stroke-width:1px,style:dashed;
    classDef ci fill:#f5c6cb,stroke:#721c24,stroke-width:1px,shape:hexagon;
    classDef tool fill:#e2e3e5,stroke:#6c757d,stroke-width:1px;
    classDef e2e fill:#ffeeba,stroke:#856404,stroke-width:1px;
```
