# andrejfg/msal-dinamico architecture

> Architecture diagram of the GitHub repository andrejfg/msal-dinamico, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/andrejfg/msal-dinamico
- Repository: https://github.com/andrejfg/msal-dinamico

## Overview

##### Project type and purpose
- This is a full-stack, server-rendered web application built with Next.js (App Router v14) and React, focused on integrating Azure AD authentication via MSAL.
- Key use cases: user sign-in/sign-out, role-based page protection (admin only), and token retrieval for calling custom APIs or Microsoft Graph.

##### File structure
- **app/**: Next.js App Router pages and layouts (SSR)
- app/layout.tsx – global layout, wraps all pages
- app/page.tsx – public landing page
- app/adminonlypage/page.tsx – protected “admin only” page
- app/gettokentest/page.tsx – page to display acquired token
- app/globals.css – global Tailwind CSS styles
- **components/**: React UI components (SignInButton, SignOutButton, UnauthorizedMessage, UserAvatar, etc.)
- **hooks/**: custom React hooks (useCopyToClipboard)
- **msal/**: encapsulates all MSAL setup and helpers
- MsalConfigProvider.tsx, MyMsalProvider.tsx – context providers for MSAL
- msal.ts / authConfig.js – client & auth configuration
- tokenFetcher.ts – utility to acquire tokens programmatically
- msalGraph.ts, userHelper.ts – wrappers for calling Microsoft Graph and user utilities
- **config files**: next.config.js, tsconfig.json, tailwind.config.ts, postcss.config.js
- **others**: .env.local for NEXT_PUBLIC_USER_CLAIMS_ADMIN, package.json, .eslintrc.json

##### Insights from the README
- Tech stack: Next.js v14, React 18, @azure/msal-browser v3.6.0, msal-react v2.0.8, Tailwind CSS
- Purpose: streamline Azure AD auth in an SSR React app
- Workflow: user logs in via MSAL → receives tokens → app checks claims for authorization → optionally calls MS Graph or a custom API using acquired tokens

## Diagram (Mermaid)

```mermaid
graph TD
    %% Browser / Client Layer
    subgraph "Browser / Client"
        UIComponents["UI Components<br/>(SignInButton, SignOutButton, SignInSignOutButton,<br/>UnauthorizedMessage, UserAvatar)"]:::blue
        MyMsalProvider["MyMsalProvider"]:::blue
        UIComponents --> MyMsalProvider
    end

    %% Next.js SSR Server Layer
    subgraph "Next.js SSR Server"
        Layout["app/layout.tsx"]:::green
        PublicPage["app/page.tsx<br/>(Public Landing)"]:::green
        AdminPage["app/adminonlypage/page.tsx<br/>(Admin Only)"]:::green
        TokenTestPage["app/gettokentest/page.tsx<br/>(Token Test)"]:::green
        Layout --> PublicPage
        Layout --> AdminPage
        Layout --> TokenTestPage
    end

    %% MSAL Context & Utilities Layer
    subgraph "MSAL Layer"
        MsalConfigProvider["msal/MsalConfigProvider.tsx"]:::orange
        MsalConfigSetup["msal/MsalConfigSetup.tsx"]:::orange
        MsalBrowser["msal/msal.ts"]:::orange
        TokenFetcher["msal/tokenFetcher.ts"]:::orange
        MsalGraph["msal/msalGraph.ts"]:::orange
        UserHelper["msal/userHelper.ts"]:::orange
        MsalConfigProvider --> MsalConfigSetup
        MsalConfigSetup --> MsalBrowser
        Layout --> MsalConfigProvider
        MyMsalProvider --> MsalConfigProvider
    end

    %% External Services Layer
    subgraph "External Services"
        AzureAD["Azure AD<br/>(Auth & Token Endpoint)"]:::gray
        GraphAPI["Microsoft Graph API"]:::gray
        CustomAPI["Custom Backend API"]:::gray
        MyMsalProvider -->|“Auth Request”| AzureAD
        AzureAD -->|“ID & Access Tokens”| MyMsalProvider
        TokenFetcher -->|“Bearer Token”| GraphAPI
        TokenFetcher -->|“Bearer Token”| CustomAPI
    end

    %% Configuration & Styles
    subgraph "Configuration & Styles"
        GlobalsCSS["app/globals.css"]:::gray
        TailwindConfig["tailwind.config.ts"]:::gray
        PostCSS["postcss.config.js"]:::gray
        Env[".env.local<br/>(NEXT_PUBLIC_USER_CLAIMS_ADMIN)"]:::gray
        NextConfig["next.config.js"]:::gray
        TSConfig["tsconfig.json"]:::gray
        ESLint[".eslintrc.json"]:::gray
        GitIgnore[".gitignore"]:::gray
        PackageJSON["package.json"]:::gray
        PackageLock["package-lock.json"]:::gray
        README["README.md"]:::gray
        License["LICENSE"]:::gray
    end

    %% Role-based Access Control
    Env --> AdminPage

    %% Click Events - UI Components
    click UIComponents "https://github.com/andrejfg/msal-dinamico/blob/master/components/SignInButton.tsx"
    click UIComponents "https://github.com/andrejfg/msal-dinamico/blob/master/components/SignOutButton.tsx"
    click UIComponents "https://github.com/andrejfg/msal-dinamico/blob/master/components/SignInSignOutButton.tsx"
    click UIComponents "https://github.com/andrejfg/msal-dinamico/blob/master/components/UnauthorizedMessage.tsx"
    click UIComponents "https://github.com/andrejfg/msal-dinamico/blob/master/components/UserAvatar.tsx"

    %% Click Events - Next.js App Router
    click Layout "https://github.com/andrejfg/msal-dinamico/blob/master/app/layout.tsx"
    click PublicPage "https://github.com/andrejfg/msal-dinamico/blob/master/app/page.tsx"
    click AdminPage "https://github.com/andrejfg/msal-dinamico/blob/master/app/adminonlypage/page.tsx"
    click TokenTestPage "https://github.com/andrejfg/msal-dinamico/blob/master/app/gettokentest/page.tsx"

    %% Click Events - MSAL
    click MsalConfigProvider "https://github.com/andrejfg/msal-dinamico/blob/master/msal/MsalConfigProvider.tsx"
    click MsalConfigSetup "https://github.com/andrejfg/msal-dinamico/blob/master/msal/MsalConfigSetup.tsx"
    click MyMsalProvider "https://github.com/andrejfg/msal-dinamico/blob/master/msal/MyMsalProvider.tsx"
    click MsalBrowser "https://github.com/andrejfg/msal-dinamico/blob/master/msal/msal.ts"
    click TokenFetcher "https://github.com/andrejfg/msal-dinamico/blob/master/msal/tokenFetcher.ts"
    click MsalGraph "https://github.com/andrejfg/msal-dinamico/blob/master/msal/msalGraph.ts"
    click UserHelper "https://github.com/andrejfg/msal-dinamico/blob/master/msal/userHelper.ts"

    %% Click Events - Hooks
    click Hooks "https://github.com/andrejfg/msal-dinamico/blob/master/hooks/useCopyToClipcoard.ts"

    %% Click Events - Config & Styles
    click GlobalsCSS "https://github.com/andrejfg/msal-dinamico/blob/master/app/globals.css"
    click TailwindConfig "https://github.com/andrejfg/msal-dinamico/blob/master/tailwind.config.ts"
    click PostCSS "https://github.com/andrejfg/msal-dinamico/blob/master/postcss.config.js"
    click NextConfig "https://github.com/andrejfg/msal-dinamico/blob/master/next.config.js"
    click TSConfig "https://github.com/andrejfg/msal-dinamico/blob/master/tsconfig.json"
    click ESLint "https://github.com/andrejfg/msal-dinamico/blob/master/.eslintrc.json"
    click GitIgnore "https://github.com/andrejfg/msal-dinamico/blob/master/.gitignore"
    click PackageJSON "https://github.com/andrejfg/msal-dinamico/blob/master/package.json"
    click PackageLock "https://github.com/andrejfg/msal-dinamico/blob/master/package-lock.json"
    click README "https://github.com/andrejfg/msal-dinamico/blob/master/README.md"
    click License "https://github.com/andrejfg/msal-dinamico/tree/master/LICENSE"

    %% Styles
    classDef blue fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef green fill:#90EE90,stroke:#333,stroke-width:1px
    classDef orange fill:#FFA500,stroke:#333,stroke-width:1px
    classDef gray fill:#D3D3D3,stroke:#333,stroke-width:1px
```
