# sidarth164/custom-activity-deskapi-node architecture

> Architecture diagram of the GitHub repository sidarth164/custom-activity-deskapi-node, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sidarth164/custom-activity-deskapi-node
- Repository: https://github.com/sidarth164/custom-activity-deskapi-node

## Overview

##### Project type and purpose
- This is a Node.js + Express “app extension” for Salesforce Marketing Cloud’s Journey Builder.
- It provides two custom activities (“Create Case” and “Update Case”) that appear in the JB canvas, let users configure them via a small SPA (HTML/CSS/JS under public/ixn/activities), and execute HTTP callbacks to external services (Desk.com API).

##### File structure
- Top level
- app.js – Express server, mounts routes and static asset middleware
- Procfile – Heroku web process
- lib/jwtDecoder.js – helper to decode and validate SFMC JWT tokens
- routes/
­ activityCreate.js – POST handler for Create Case execution
­ activityUpdate.js – POST handler for Update Case execution
­ activityUtils.js – Desk.com API helper (auth, request building)
­ index.js – authentication, CSRF-token and static route setup
- public/ixn/activities/{create-case,update-case}/
­ index.html, JS, CSS, config.json – the configuration UIs loaded in JB
- No internal database; all state is passed as inArguments/outArguments.

##### README for additional insights
- The README describes the Journey Builder lifecycle:
- Edit time: JB loads config.json and static assets from your app to let the user define inputs.
- Activation time: Marketing Cloud fires REST calls to your /execute endpoints with a JWT.
- Your server: decodes token, extracts arguments, calls Desk.com API, returns status and outArguments.
- Dependencies: Express, node-jwt, request or similar HTTP library.

##### Components & interactions
1. Journey Builder UI (Browser)
2. Marketing Cloud Interaction Service (Event trigger & REST invoker)
3. Your Node.js App on Heroku (Express server)
- Static-asset server (serves public/ixn/*)
- Route handlers
– Activity Create (/ixn/activities/create-case)
– Activity Update (/ixn/activities/update-case)
- JWT Decoder (lib/jwtDecoder.js)
- Desk.com API client (routes/activityUtils.js)
- SFMC Auth client (in app.js for token requests to auth.exacttargetapis.com)
4. Desk.com REST API
1. JB UI → GET config.json + index.html (to render the config dialog)
2. User fills form → POST saved config back to JB UI (no server call)
3. User activates Journey → Marketing Cloud issues POST /execute to your Node app with JWT + inArguments
4. Node app → decode JWT → validate session → extract inArguments
5. Node app → (optional) request new SFMC bearer token if needed
6. Node app → HTTP call to Desk.com REST API (create or update case)
7. Desk.com API → HTTP response → Node app formats outArguments → returns to MC service
8. Marketing Cloud logs result, passes outArguments to downstream activities
c. Architectural patterns
- RESTful API back end + static front end (SPA)
- Middleware for authentication (JWT)
- Modular route structure for each activity
- External service integration (Desk.com, SFMC Auth)
d. Key technologies
- Node.js, Express
- JWT (lib/jwtDecoder.js)
- HTML5/RequireJS/CSS for the config UI
- Desk.com REST API

##### Detail & coverage
- JWT Decoder and activityUtils as separate functional blocks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    JBUI(["JB Canvas UI"]):::external
    MCEvent(["MC Interaction Service"]):::external
    SFMCAuth(["SFMC Auth Service\nauth.exacttargetapis.com"]):::external
    DeskAPI(["Desk.com REST API"]):::external

    %% Frontend Configuration UIs
    subgraph "Frontend (Configuration UI)"
        direction TB
        subgraph "Create Case UI"
            CC_HTML[/index.html/]:::static
            CC_JS1[/js/CreateCase.js/]:::static
            CC_JS2[/js/main.js/]:::static
            CC_CSS[/css/styles.css/]:::static
            CC_JSON[/config.json/]:::static
        end
        subgraph "Update Case UI"
            UC_HTML[/index.html/]:::static
            UC_JS1[/js/UpdateCase.js/]:::static
            UC_JS2[/js/main.js/]:::static
            UC_CSS[/css/styles.css/]:::static
            UC_JSON[/config.json/]:::static
        end
    end

    %% Backend Services
    subgraph "Backend (Node.js App on Heroku)"
        direction TB
        AppJS(["app.js\n(Express Server Entry)"]):::backend
        Procfile(["Procfile\n(Heroku Procfile)"]):::backend
        StaticSrv(["Static Asset Server\n(public/ixn)"]):::backend
        JwtDec(["JWT Decoder\n(lib/jwtDecoder.js)"]):::backend
        RoutesIdx(["Main Routes & Middleware\n(routes/index.js)"]):::backend
        ActCreate(["Activity Create Handler\n(routes/activityCreate.js)"]):::backend
        ActUpdate(["Activity Update Handler\n(routes/activityUpdate.js)"]):::backend
        ActUtils(["Desk.com & SFMC Auth Helper\n(routes/activityUtils.js)"]):::backend
    end

    %% Edit-Time Flow
    JBUI -->|"GET /config.json & index.html"| StaticSrv
    StaticSrv --> CC_JSON
    StaticSrv --> CC_HTML
    StaticSrv --> UC_JSON
    StaticSrv --> UC_HTML

    %% Activation-Time Flow
    MCEvent -->|"POST /ixn/activities/create-case"| ActCreate
    MCEvent -->|"POST /ixn/activities/update-case"| ActUpdate
    ActCreate --> JwtDec
    ActUpdate --> JwtDec
    ActCreate -->|"may request token"| SFMCAuth
    ActUpdate -->|"may request token"| SFMCAuth
    ActCreate --> ActUtils
    ActUpdate --> ActUtils
    ActUtils --> DeskAPI
    ActCreate --> MCEvent
    ActUpdate --> MCEvent

    %% Static UI detail connections
    CC_HTML --> StaticSrv
    CC_JS1 --> StaticSrv
    CC_JS2 --> StaticSrv
    CC_CSS --> StaticSrv
    CC_JSON --> StaticSrv

    UC_HTML --> StaticSrv
    UC_JS1 --> StaticSrv
    UC_JS2 --> StaticSrv
    UC_CSS --> StaticSrv
    UC_JSON --> StaticSrv

    %% Click Events
    click AppJS "https://github.com/sidarth164/custom-activity-deskapi-node/blob/master/app.js"
    click Procfile "https://github.com/sidarth164/custom-activity-deskapi-node/tree/master/Procfile"
    click JwtDec "https://github.com/sidarth164/custom-activity-deskapi-node/blob/master/lib/jwtDecoder.js"
    click RoutesIdx "https://github.com/sidarth164/custom-activity-deskapi-node/blob/master/routes/index.js"
    click ActCreate "https://github.com/sidarth164/custom-activity-deskapi-node/blob/master/routes/activityCreate.js"
    click ActUpdate "https://github.com/sidarth164/custom-activity-deskapi-node/blob/master/routes/activityUpdate.js"
    click ActUtils "https://github.com/sidarth164/custom-activity-deskapi-node/blob/master/routes/activityUtils.js"
    click StaticSrv "https://github.com/sidarth164/custom-activity-deskapi-node/tree/master/public/ixn"
    click CC_HTML "https://github.com/sidarth164/custom-activity-deskapi-node/blob/master/public/ixn/activities/create-case/index.html"
    click CC_JS1 "https://github.com/sidarth164/custom-activity-deskapi-node/blob/master/public/ixn/activities/create-case/js/CreateCase.js"
    click CC_JS2 "https://github.com/sidarth164/custom-activity-deskapi-node/blob/master/public/ixn/activities/create-case/js/main.js"
    click CC_CSS "https://github.com/sidarth164/custom-activity-deskapi-node/blob/master/public/ixn/activities/create-case/css/styles.css"
    click CC_JSON "https://github.com/sidarth164/custom-activity-deskapi-node/blob/master/public/ixn/activities/create-case/config.json"
    click UC_HTML "https://github.com/sidarth164/custom-activity-deskapi-node/blob/master/public/ixn/activities/update-case/index.html"
    click UC_JS1 "https://github.com/sidarth164/custom-activity-deskapi-node/blob/master/public/ixn/activities/update-case/js/UpdateCase.js"
    click UC_JS2 "https://github.com/sidarth164/custom-activity-deskapi-node/blob/master/public/ixn/activities/update-case/js/main.js"
    click UC_CSS "https://github.com/sidarth164/custom-activity-deskapi-node/blob/master/public/ixn/activities/update-case/css/styles.css"
    click UC_JSON "https://github.com/sidarth164/custom-activity-deskapi-node/blob/master/public/ixn/activities/update-case/config.json"

    %% Styles
    classDef backend fill:#cce5ff,stroke:#004085;
    classDef external fill:#d4edda,stroke:#155724;
    classDef static fill:#fff3cd,stroke:#856404,shape:parallelogram;
```
