Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

SJ Share is a Shiny web application for St. Jude Shared Resources to manage email communications with researchers. The app allows authorized staff to look up SRM (Shared Resource Management) order information and send templated emails to requestors and PIs based on order status and service type.

## Running the Application

### Local Development
```R
# Run the app from R console or RStudio
shiny::runApp()
```

The app will start on the default Shiny port (typically 8080).

### Dependencies
All required packages are loaded in `global.R`. Install missing packages with:
```R
install.packages(c("shiny", "shinyjs", "shinycustomloader", "shinyWidgets",
"RJSONIO", "DT", "shinyMCE", "RSQLite", "bslib", "shinylogs",
"emayili", "shinyvalidate", "shinyalert", "httr", "jsonlite",
"dplyr", "stringr", "xml2", "hwriter"))
```

## Architecture

### File Structure

The application follows standard Shiny architecture with three main files:

- **global.R**: Package loading and global configuration (max upload size: 30MB)
- **server.R**: Server-side logic, API interactions, email handling, and reactive behaviors
- **ui.R**: User interface definition using bslib's page_navbar layout with sidebar

### Key Components

#### Authentication & Authorization
- User authentication via ShinyProxy (`session$user`)
- Department-based access control stored in SQLite database (`authControl.db`)
- User metadata fetched from internal API: `http://splpgsf02.stjude.org:5000/api/users/`
- Access permissions determined by `dept` field in `access` table

#### SRM API Integration
- Base URL: `https://apis-research.stjude.org/srmapi/`
- Authentication via environment variables: `SRM_AUTH` and `SRM_API_TOKEN`
- Main endpoint: `/bbq/order/{orderNumber}` - retrieves order details
- CAGE-specific endpoint: `/cageStaleData` - retrieves stale data for genome engineering orders

#### Email Template System
Templates are stored in department-specific folders under `www/Templates/{DepartmentName}/`:
- `.html` files contain email body with token placeholders
- `.subj` files contain subject line templates
- Special case: "Center for Spatial Omics" users (Plumm group from Developmental Neurobiology)

Available tokens for templates:
- `SRMorderNumber` - SRM order number
- `srmService` - Service name
- `requestorFirstName` - First name of person who ordered
- `piFirstName` - PI's first name
- `userFirstName` - Current user's first name
- CAGE-specific: `cageCellLine`, `cageTargetGene`, `cageObjective`, `cageLead`

#### Department-Specific Features

**Hartwell Center:**
- Invalid plate submission handling with reasons checklist
- Automatic attachment of submission guidelines PDF
- Plate return emails with SRC image attachment

**Center for Advanced Genome Engineering (CAGE):**
- Status update dropdown for project stages
- Integration with CAGE stale data API

#### Email Sending
- Uses `emayili` package via SMTP (smtp.stjude.org:25)
- Currently hardcoded to send to Daniel.Darnell@stjude.org (testing mode)
- Production mode would send to requestorEmail with CC options
- Supports file attachments up to 30MB

### Reactive Flow

1. User selects email template and enters SRM order number
2. Click "Lookup SRM" triggers API call to validate order and fetch metadata
3. Token replacement occurs in both subject and body
4. TinyMCE editor displays populated email for review/editing
5. "Send Email" button triggers email via SMTP
6. Success/error alerts with automatic page reload

### State Management

Key reactive triggers:
- `lookupTrigger` - increments when SRM lookup button clicked
- `sendTrigger` - increments when send email button clicked
- `template_files` - reactiveFileReader monitors template directory for changes every 2 seconds

Page reload function (`pageReload()`) resets all UI elements and reactive values to initial state.

## Environment Variables Required

```bash
SRM_AUTH=<authorization_header>
SRM_API_TOKEN=<api_token>
HC_DB_USER=<database_user>
HC_DB_PASS=<database_password>
```

## Database Schema

`authControl.db` contains `access` table with:
- `dept` (TEXT) - Department name
- `srmService` (TEXT) - Comma-separated list of allowed SRM services

## Logging

Session activity logged via `shinylogs` package to `logs/` directory in JSON format.

## Important Behavioral Notes

- Session reconnection is disabled (`session$allowReconnect(FALSE)`)
- Invalid SRM lookups trigger alerts and automatic page reload
- Unauthorized service access triggers error alert without page reload until acknowledged
- File uploads stored in `www/{SRM}_{template}_{date}_{user}/` folders
- Dark mode toggle available in navbar