# azure-samples/js-e2e-web-app-easy-auth-app-to-app architecture

> Architecture diagram of the GitHub repository azure-samples/js-e2e-web-app-easy-auth-app-to-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/azure-samples/js-e2e-web-app-easy-auth-app-to-app
- Repository: https://github.com/azure-samples/js-e2e-web-app-easy-auth-app-to-app

## Overview

##### Main Components
- Frontend App Service: Represent the frontend folder which contains the Express.js application with view templates, error handling logic (error.js), and modules for managing refresh tokens and remote profile access.
- Backend App Service: Represent the backend folder, which includes core Express.js server files (server.js and index.js), modules for sorting JSON data (sortJson.js), authentication modules, and graph-related commands for securing service-to-service calls.
- External Services / Endpoints: Optionally include external endpoints such as the token issuance flow, service-to-service token exchange, and any remote APIs requested on behalf of the signed-in user.

##### Relationships and Interactions
- Backend to Azure AD: If applicable, highlight that the backend verifies access tokens or may call out to AAD for token validation and additional user details.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Emphasize the clear split between the frontend and backend systems.
- Security and Token Management: Note the implementation of access token flows for both client-side and server-side operations.
- Modular Design: Indicate that helper functions (such as sortJson.js in both folders) are reused to keep the components lightweight and not monolithic.

##### Relevant Technologies, Frameworks, or Libraries
- Express.js: Both in frontend and backend for handling HTTP requests.
- EJS Templates: In the frontend for rendering dynamic pages.
- Azure App Service: Hosting platform with built-in support for authentication/authorization.
- Azure Active Directory: As the identity provider.
- Node.js: Underlying runtime mentioned indirectly by package.json files and JavaScript usage.
- Additional Scripts: Note how shell scripts (access-token.sh, app-creation.sh) support deployment or configuration tasks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    User["User"]:::user
    AzureAD["Azure AD"]:::azure
    ExternalAPI["External APIs"]:::external

    %% Frontend App Service Subgraph
    subgraph "Frontend App Service"
        F_Service["Frontend App Service"]:::frontend
        F_Server["Express Server (server.js)"]:::frontend
        F_Views["View Templates (views)"]:::frontend
        F_Refresh["Refresh Token Module (refreshToken.js)"]:::frontend
        F_Remote["Remote Profile Module (remoteProfile.js)"]:::frontend
        F_Error["Error Handling (error.js)"]:::frontend
    end

    %% Backend App Service Subgraph
    subgraph "Backend App Service"
        B_Service["Backend App Service"]:::backend
        B_Index["Index File (index.js)"]:::backend
        B_Server["Express Server (server.js)"]:::backend
        B_Sort["JSON Sorting Module (sortJson.js)"]:::backend
        B_Auth["Auth Module (auth.js)"]:::backend
        B_Graph["Graph Module (graph.js)"]:::backend
    end

    %% Internal Frontend Relationships
    F_Service --> F_Server
    F_Server --> F_Views
    F_Server --> F_Refresh
    F_Server --> F_Remote
    F_Server --> F_Error

    %% Internal Backend Relationships
    B_Service --> B_Index
    B_Service --> B_Server
    B_Index --> B_Sort
    B_Index --> B_Auth
    B_Index --> B_Graph
    B_Auth --> B_Graph

    %% External Interactions
    User --> F_Service
    F_Service --> AzureAD
    AzureAD --> F_Service
    F_Service --> B_Service
    B_Service --> AzureAD
    F_Remote --> ExternalAPI
    B_Graph --> ExternalAPI

    %% Click Events for Frontend Components
    click F_Service "https://github.com/azure-samples/js-e2e-web-app-easy-auth-app-to-app/tree/main/frontend/"
    click F_Server "https://github.com/azure-samples/js-e2e-web-app-easy-auth-app-to-app/blob/main/frontend/src/server.js"
    click F_Views "https://github.com/azure-samples/js-e2e-web-app-easy-auth-app-to-app/tree/main/frontend/src/views"
    click F_Refresh "https://github.com/azure-samples/js-e2e-web-app-easy-auth-app-to-app/blob/main/frontend/src/refreshToken.js"
    click F_Remote "https://github.com/azure-samples/js-e2e-web-app-easy-auth-app-to-app/blob/main/frontend/src/remoteProfile.js"
    click F_Error "https://github.com/azure-samples/js-e2e-web-app-easy-auth-app-to-app/blob/main/frontend/src/error.js"

    %% Click Events for Backend Components
    click B_Service "https://github.com/azure-samples/js-e2e-web-app-easy-auth-app-to-app/tree/main/backend/"
    click B_Index "https://github.com/azure-samples/js-e2e-web-app-easy-auth-app-to-app/blob/main/backend/src/index.js"
    click B_Server "https://github.com/azure-samples/js-e2e-web-app-easy-auth-app-to-app/blob/main/backend/src/server.js"
    click B_Sort "https://github.com/azure-samples/js-e2e-web-app-easy-auth-app-to-app/blob/main/backend/src/sortJson.js"
    click B_Auth "https://github.com/azure-samples/js-e2e-web-app-easy-auth-app-to-app/blob/main/backend/src/with-graph/auth.js"
    click B_Graph "https://github.com/azure-samples/js-e2e-web-app-easy-auth-app-to-app/blob/main/backend/src/with-graph/graph.js"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef azure fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef user fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef external fill:#e2e3e5,stroke:#333,stroke-width:2px;
```
