# webdevsimplified/my-own-react-router architecture

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

- Interactive diagram: https://gitdiagram.com/webdevsimplified/my-own-react-router
- Repository: https://github.com/webdevsimplified/my-own-react-router

## Overview

##### Project Type and Purpose
- This is a single‑page application (SPA) built with React and TypeScript, bundled by Vite.
- Features client‑side routing (custom router in src/router), HMR for development, and a file‑based pages system under src/pages.

##### Main Components
a. Development Environment
- Vite Dev Server
- React Fast Refresh plugin (Babel or SWC)
- ESLint (optional linting service)
b. Build Pipeline
- Vite bundler (rollup under the hood)
- TypeScript compiler (tsconfig.app.json)
c. Runtime (Browser)
- index.html (entry HTML)
- main.tsx (React root)
- Router subsystem (RouterProvider, routeParser, defineRoute)
- Page components under src/pages
- Shared layout components (src/pages/layout.tsx)
d. Configuration & Metadata
- package.json / package-lock.json
- tsconfig.json / tsconfig.node.json / tsconfig.app.json
- vite.config.ts
- eslint.config.js

##### Relationships and Data Flow
- During development:
Developer edits files → Vite watches FS → TypeScript + React plugin transpile → HMR pushes updates to Browser
- On build:
Vite reads vite.config.ts → applies plugins → bundles TSX → outputs static assets → served by any HTTP server
- At runtime in Browser:
index.html loads bundled JS → main.tsx mounts React tree → RouterProvider reads URL → routeParser selects Page component → renders Page via Outlet / Link

##### Architectural Patterns and Design Principles
- SPA with client‑side routing
- Component‑based hierarchy (pages, layouts, router components)
- File‑based routing convention (folder structure under src/pages)
- Plugin‑based build system (Vite plugins for React)

a. Developer Environment (left)
b. Build Pipeline (center)
c. Browser Runtime (right)
2. In “Developer Environment”:
- Block: Editor / File System → ESLint (optional)
3. In “Build Pipeline”:
- Blocks: TypeScript Compiler, React Plugin, Vite Bundler → Output assets (JS/CSS)
4. In “Browser Runtime”:
- index.html loads → main.tsx
- RouterProvider uses routeParser → renders Pages under src/pages
- Components: Link, Outlet for navigation

## Diagram (Mermaid)

```mermaid
graph LR
    subgraph "Developer Environment"
        EditorFS["Editor / File System"]:::config
        ESLint["ESLint"]:::tools
        ViteDev["Vite Dev Server"]:::tools
        EditorFS --> ESLint
        ESLint --> ViteDev
    end

    subgraph "Build Pipeline"
        TSApp["TypeScript Compiler\n(tsconfig.app.json)"]:::tools
        TSBase["TypeScript Compiler\n(tsconfig.json)"]:::tools
        TSNode["TypeScript Compiler\n(tsconfig.node.json)"]:::tools
        ReactPlugin["React Fast Refresh Plugin"]:::tools
        ViteBundle["Vite Bundler"]:::tools
        Output["Static Assets\n(JS/CSS)"]:::runtime
        TSApp --> ViteBundle
        TSBase --> ViteBundle
        TSNode --> ViteBundle
        ReactPlugin --> ViteBundle
        ViteBundle --> Output
    end

    subgraph "Browser Runtime"
        IndexHTML["index.html"]:::runtime
        MainTSX["main.tsx"]:::runtime
        RouterProv["RouterProvider"]:::runtime
        RouteParser["routeParser"]:::runtime
        DefineRoute["defineRoute"]:::runtime
        LinkComp["Link"]:::runtime
        OutletComp["Outlet"]:::runtime
        RoutesEntry["routes.tsx"]:::runtime
        GlobalLayout["layout.tsx"]:::runtime
        HomePage["home.tsx"]:::runtime
        AboutLayout["about/layout.tsx"]:::runtime
        AboutID["about/[id].tsx"]:::runtime
        AboutChild["about/child.tsx"]:::runtime
        ContactDetails["contact/details.tsx"]:::runtime

        Output --> IndexHTML
        IndexHTML --> MainTSX
        MainTSX --> RouterProv
        RouterProv --> RouteParser
        RouterProv --> DefineRoute
        RouterProv --> RoutesEntry
        RouterProv --> OutletComp
        RouterProv --> LinkComp
        OutletComp --> HomePage
        OutletComp --> AboutLayout
        AboutLayout --> AboutID
        AboutLayout --> AboutChild
        OutletComp --> ContactDetails
        RoutesEntry --> HomePage
        RoutesEntry --> AboutLayout
        RoutesEntry --> ContactDetails
        GlobalLayout --> OutletComp
    end

    subgraph "Configuration & Metadata"
        PKG["package.json"]:::config
        PKGLock["package-lock.json"]:::config
        ESLintCfg["eslint.config.js"]:::config
        ViteCfg["vite.config.ts"]:::config
        TSAppFile["tsconfig.app.json"]:::config
        TSBaseFile["tsconfig.json"]:::config
        TSNodeFile["tsconfig.node.json"]:::config
        PKG --> ViteDev
        PKGLock --> ViteDev
        ESLintCfg --> ESLint
        ViteCfg --> ViteDev
        ViteCfg --> ViteBundle
        TSAppFile --> TSApp
        TSBaseFile --> TSBase
        TSNodeFile --> TSNode
    end

    classDef tools fill:#bbdefb,stroke:#1e88e5;
    classDef config fill:#e0e0e0,stroke:#9e9e9e;
    classDef runtime fill:#c8e6c9,stroke:#388e3c;

    click ViteDev "https://github.com/webdevsimplified/my-own-react-router/blob/main/vite.config.ts"
    click ReactPlugin "https://github.com/webdevsimplified/my-own-react-router/blob/main/vite.config.ts"
    click ESLint "https://github.com/webdevsimplified/my-own-react-router/blob/main/eslint.config.js"
    click ViteBundle "https://github.com/webdevsimplified/my-own-react-router/blob/main/vite.config.ts"
    click TSApp "https://github.com/webdevsimplified/my-own-react-router/blob/main/tsconfig.app.json"
    click TSBase "https://github.com/webdevsimplified/my-own-react-router/blob/main/tsconfig.json"
    click TSNode "https://github.com/webdevsimplified/my-own-react-router/blob/main/tsconfig.node.json"
    click IndexHTML "https://github.com/webdevsimplified/my-own-react-router/blob/main/index.html"
    click MainTSX "https://github.com/webdevsimplified/my-own-react-router/blob/main/src/main.tsx"
    click RouterProv "https://github.com/webdevsimplified/my-own-react-router/blob/main/src/router/RouterProvider.tsx"
    click RouteParser "https://github.com/webdevsimplified/my-own-react-router/blob/main/src/router/routeParser.ts"
    click DefineRoute "https://github.com/webdevsimplified/my-own-react-router/blob/main/src/router/defineRoute.ts"
    click LinkComp "https://github.com/webdevsimplified/my-own-react-router/blob/main/src/router/Link.tsx"
    click OutletComp "https://github.com/webdevsimplified/my-own-react-router/blob/main/src/router/Outlet.tsx"
    click TSAppFile "https://github.com/webdevsimplified/my-own-react-router/blob/main/tsconfig.app.json"
    click TSBaseFile "https://github.com/webdevsimplified/my-own-react-router/blob/main/tsconfig.json"
    click TSNodeFile "https://github.com/webdevsimplified/my-own-react-router/blob/main/tsconfig.node.json"
    click RoutesEntry "https://github.com/webdevsimplified/my-own-react-router/blob/main/src/routes.tsx"
    click HomePage "https://github.com/webdevsimplified/my-own-react-router/blob/main/src/pages/home.tsx"
    click AboutLayout "https://github.com/webdevsimplified/my-own-react-router/blob/main/src/pages/about/layout.tsx"
    click AboutID "https://github.com/webdevsimplified/my-own-react-router/blob/main/src/pages/about/[id].tsx"
    click AboutChild "https://github.com/webdevsimplified/my-own-react-router/blob/main/src/pages/about/child.tsx"
    click ContactDetails "https://github.com/webdevsimplified/my-own-react-router/blob/main/src/pages/contact/details.tsx"
    click GlobalLayout "https://github.com/webdevsimplified/my-own-react-router/blob/main/src/pages/layout.tsx"
    click ViteCfg "https://github.com/webdevsimplified/my-own-react-router/blob/main/vite.config.ts"
    click PKG "https://github.com/webdevsimplified/my-own-react-router/blob/main/package.json"
    click PKGLock "https://github.com/webdevsimplified/my-own-react-router/blob/main/package-lock.json"
    click ESLintCfg "https://github.com/webdevsimplified/my-own-react-router/blob/main/eslint.config.js"
```
