# r-cz/iam-tools architecture

> Architecture diagram of the GitHub repository r-cz/iam-tools, 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/r-cz/iam-tools
- Repository: https://github.com/r-cz/iam-tools

## Overview

##### Main Components
a. Frontend Application:
- Built with React (using Vite as the build tool) that composes pages and components from the “src” folder.
- Feature modules (such as “tokenInspector” and “oidcExplorer” within src/features) for specific IAM tools.
- Shared UI components (in src/components/ui), layouts (src/components/layout), navigation (src/components/navigation), and theming (src/components/theme).
- Custom hooks and utilities (src/hooks, src/lib, src/types) which encapsulate reusable logic.
b. Backend/Server Components:
- The functions directory contains API endpoints, including the CORS proxy and JWKS resolution endpoints. These endpoints provide services—such as allowing the frontend to work with external APIs that do not support CORS.
- Middleware and routing definitions (in functions/_middleware.ts and functions/_routes.json) to map API paths.
c. External Services:
- External identity providers providing .well-known endpoints and JWKS URIs.
d. Development/Testing Infrastructure:
- GitHub workflows (in .github) for CI processes (Bun tests, CodeQL).
- Test files (in src/tests) wrapping the component, feature, hooks, and utility tests.
- Deployment processes via Cloudflare Pages as outlined in the README.

##### Relationships and Data Flow
- The frontend (React application) interacts with the backend endpoints (under functions API) especially for the CORS proxy and token validation processes.
- Within the frontend, different feature modules communicate with shared libraries (src/lib, src/hooks) and UI components.
- The build, test, and deployment layers should be represented as supporting elements rather than core runtime components.

##### Architectural Patterns and Design Principles
- Feature-based organization: The project clearly separates functionality into features (e.g., tokenInspector, oidcExplorer) and shared components (e.g., common UI elements).
- Separation of concerns: The clear division between API functions (backend logic) and UI components (frontend) reinforces a modular approach.
- CORS Proxy Pattern: Illustrate how requests are proxied from the frontend to external APIs to mitigate CORS issues.
- Use of modern development practices: Fast iterative testing using Bun’s test runner, dependency management via Bun, and CI with GitHub Actions.

##### Relevant Technologies, Frameworks, and Libraries
- Frontend: React, Vite, TypeScript, Tailwind CSS, shadcn/ui, React Router.
- Backend: Node/TypeScript functions for the CORS proxy and token-related endpoints.
- Testing: Bun Test, React Testing Library.
- Deployment: Cloudflare Pages.
- DevOps: GitHub Actions for CI/CD and CodeQL for security auditing.

- Frontend (React/Vite):
- Components: Organized into modules such as “Layout”, “Navigation”, “UI”, “Theme”, “Page Components”.
- Features: Modules like “Token Inspector” and “OIDC Explorer” illustrate specific IAM tools.
- Shared utilities and custom hooks for app logic.
- Backend/API (Functions):
- API Endpoints: Represent the CORS proxy endpoint and JWKS resolution endpoint.
- Middleware: Explicitly indicate the use of _middleware for request handling.
- External Services:
- Deployment/DevOps Elements:
- GitHub Actions: Workflows for testing and code analysis.
- Cloudflare Pages: Deployment destination and workflow triggers on push to the main branch.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["React Frontend"] 
        TI["Token Inspector Feature Module"]
        OE["OIDC Explorer Feature Module"]
        UI["Shared UI Components"]
        LAYOUT["Layout Components"]
        NAV["Navigation Components"]
        THEME["Theming Components"]
        HOOKS["Custom Hooks & Utilities"]
    end

    %% Backend/API Layer
    subgraph "Backend/API Layer"
        CP["CORS Proxy API Endpoint"]
        JW["JWKS Resolution Endpoint"]
        MR["Middleware & Routing"]
    end

    %% External Services
    subgraph "External Services"
        EIP["External Identity Providers"]
    end

    %% DevOps & Deployment
    subgraph "DevOps & Deployment"
        CI["CI/CD Workflows"]
        CF["Cloudflare Pages Deployment"]
    end

    %% Frontend Internal Connections
    FE --> TI
    FE --> OE
    FE --> UI
    FE --> LAYOUT
    FE --> NAV
    FE --> THEME
    FE --> HOOKS

    %% Frontend to Backend API Calls
    FE -->|"calls_API"| CP
    FE -->|"calls_API"| JW

    %% Feature Module Specific API Interactions
    TI -->|"validates_token"| CP
    OE -->|"explores_oidc"| JW
    TI --> HOOKS
    OE --> HOOKS
    TI --> UI
    OE --> UI

    %% Backend Routing
    MR -->|"routes_to"| CP
    MR -->|"routes_to"| JW

    %% API Proxy to External Services
    CP -->|"proxies_to"| EIP
    EIP -->|"responds_to"| CP

    %% DevOps Deployment Connection
    CI -->|"triggers_deployment"| CF

    %% Click Events
    click FE "https://github.com/r-cz/iam-tools/tree/main/src/"
    click TI "https://github.com/r-cz/iam-tools/tree/main/src/features/tokenInspector"
    click OE "https://github.com/r-cz/iam-tools/tree/main/src/features/oidcExplorer"
    click UI "https://github.com/r-cz/iam-tools/tree/main/src/components/ui"
    click LAYOUT "https://github.com/r-cz/iam-tools/tree/main/src/components/layout"
    click NAV "https://github.com/r-cz/iam-tools/tree/main/src/components/navigation"
    click THEME "https://github.com/r-cz/iam-tools/tree/main/src/components/theme"
    click HOOKS "https://github.com/r-cz/iam-tools/tree/main/src/hooks and src/lib"
    click CP "https://github.com/r-cz/iam-tools/blob/main/functions/api/cors-proxy/[[path]].ts"
    click JW "https://github.com/r-cz/iam-tools/blob/main/functions/api/jwks/index.ts"
    click MR "https://github.com/r-cz/iam-tools/blob/main/functions/_middleware.ts"
    click CI "https://github.com/r-cz/iam-tools/tree/main/.github/workflows"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef backend fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef external fill:#e0e0e0,stroke:#757575,stroke-width:2px;
    classDef devops fill:#ffe0b2,stroke:#ef6c00,stroke-width:2px;

    class FE,TI,OE,UI,LAYOUT,NAV,THEME,HOOKS frontend;
    class CP,JW,MR backend;
    class EIP external;
    class CI,CF devops;
```
