# moumit-b/bu-senior-design-emd-serono architecture

> Architecture diagram of the GitHub repository moumit-b/bu-senior-design-emd-serono, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/moumit-b/bu-senior-design-emd-serono
- Repository: https://github.com/moumit-b/bu-senior-design-emd-serono

## Overview

1. **Overall shape**
   This repo is a **multi-agent research platform** for pharma competitive intelligence. It has two major runtime halves:
   - a **Python Streamlit application** in `streamlit-app/` for chat, reports, governance, persistence, and orchestration
   - a set of **MCP tool servers** in `servers/` that expose external biomedical and knowledge data sources

2. **Primary user-facing entry point**
   The main application is the **Streamlit UI** (`streamlit-app/app.py`). It provides:
   - conversational research chat
   - report generation
   - governance/audit views
   - tool usage metrics
   - session history and saved reports

3. **Agent orchestration layer**
   The application routes user requests through an **agent orchestrator** stack in `streamlit-app/orchestration/` and `streamlit-app/agents/`.
   - `MCPAgent`-style chat loops select tools, execute them, and iterate with LLM feedback
   - `ReportAgent` coordinates the structured CI report workflow
   - specialized domain agents split responsibilities across chemical, clinical, literature, gene, data, and report tasks

4. **Data acquisition boundary: MCP servers**
   External data access is intentionally isolated behind **MCP servers** in `servers/`. These are the system’s main integration boundary to biomedical sources:
   - `pubchem-augmented` / `pubchem`: chemistry and properties
   - `bio` / biomcp-related tooling: PubMed, ClinicalTrials.gov, OpenFDA, gene/variant sources
   - `literature`, `medrxiv`, `biorxiv`: publication and preprint search
   - `opentargets`, `stringdb`: target biology and interaction networks
   - `web_knowledge`: general biomedical knowledge sources
   - `data_analysis`: analysis and derived computations

5. **Report-generation pipeline**
   Report creation is a distinct subsystem under `streamlit-app/reporting/`.
   - The app infers the target drug/asset from chat context
   - `ReportAgent` generates an **18-section EMD-format CI report**
   - Sections are built in parallel batches, with domain agents gathering evidence first
   - The report is then compiled and exported as **Markdown or PDF**

6. **Governance and control plane**
   All tool use passes through a **governance layer** in `streamlit-app/governance/`.
   This layer enforces:
   - rate limiting
   - compliance checks
   - audit logging
   - service registry / controlled access
   - gateway mediation for tool calls
   This is the main architectural boundary between LLM-driven requests and external execution.

7. **Persistence and session state**
   Persistent state is managed in `streamlit-app/context/` and related models.
   - chat sessions and messages are stored per user
   - generated reports are saved and tied to sessions
   - the default persistent backend is **Supabase**
   - there is a **SQLite fallback** for local operation when Supabase is unavailable

8. **Context and retrieval support**
   The app includes a separate context subsystem for maintaining continuity across sessions:
   - session database handling
   - vector store / chat vector store
   - memory retriever
   This suggests the chat system is not stateless; it can reuse prior conversation and session knowledge.

9. **LLM abstraction**
   `streamlit-app/utils/llm_factory.py` and config files indicate a **provider abstraction** for multiple model backends:
   - Anthropic Claude as default
   - Azure OpenAI or AWS Bedrock for enterprise environments
   - local Ollama for offline or no-key setups
   This makes the orchestration layer model-agnostic.

10. **Metrics and observability**
    `streamlit-app/metrics/` tracks tool usage, which feeds the UI’s metrics tab.
    This is important for architecture because the system isn’t just generating answers; it also records which MCP tools were invoked during a session, making the workflow auditable and analyzable.

11. **Supporting scripts and platform-specific setup**
    The repository includes deployment and startup aids:
    - `install.py`
    - `run.sh` / `run.bat`
    - environment templates and setup docs
    - SSL certificates and Merck-specific startup guidance
    These indicate the app is designed to run in both local and enterprise network contexts.

12. **Legacy/advanced orchestration material**
    The `docs/` and `streamlit-app/demo_dual_orchestration.py` files show that the repo contains documentation and examples for **dual orchestration** and **context forge** concepts. Those are relevant as architectural references, but the live system is centered on the Streamlit app plus MCP tool servers.

13. **Key architectural flow**
    A practical architecture diagram should show this data path:
    **User → Streamlit UI → agent/orchestration layer → governance gateway → MCP servers / external data sources → synthesized answer or report → persistent storage and metrics**
    The report path is similar, but fans out to multiple specialized agents before compilation and export.

14. **Important boundaries to draw**
    The clearest diagram boundaries are:
    - **presentation layer**: Streamlit UI
    - **orchestration layer**: agents, report assembly, session management
    - **control plane**: governance, audit, rate limits
    - **tool layer**: MCP servers
    - **storage layer**: Supabase / SQLite / vector store
    - **output layer**: chat responses, markdown/PDF reports, metrics views

Main entry points: [`streamlit-app/agents/chemical_agent.py`](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/agents/chemical_agent.py) (Domain Agents), [`streamlit-app/app.py`](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/app.py) (Streamlit App), [`streamlit-app/governance/gateway.py`](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/governance/gateway.py) (Gateway), [`streamlit-app/orchestration/session_manager.py`](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/orchestration/session_manager.py) (Session Manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation"]
  node_app_ui["Streamlit App<br/>ui entrypoint<br/>[app.py]"]
  node_chat_history_ui["Chat History<br/>ui component<br/>[chat_history.py]"]
  node_report_panel_ui["Report Panel<br/>ui component<br/>[report_panel.py]"]
  node_metrics_tab_ui["Metrics Tab<br/>ui component"]
  node_governance_tab_ui["Governance Tab<br/>ui component<br/>[governance_tab.py]"]
end

subgraph group_orchestration["Orchestration"]
  node_agent_orchestrator["Agent Router<br/>orchestrator"]
  node_mcp_orchestrator["MCP Orchestrator<br/>tool coordinator"]
  node_session_manager[("Session Manager<br/>session service<br/>[session_manager.py]")]
  node_tool_composer["Tool Composer<br/>tool planner<br/>[tool_composer.py]"]
  node_report_agent["Report Agent<br/>report workflow<br/>[report_agent.py]"]
  node_base_agent["Base Agent<br/>agent base<br/>[base_agent.py]"]
  node_domain_agents{{"Domain Agents<br/>agent set<br/>[chemical_agent.py]"}}
end

subgraph group_control["Control Plane"]
  node_gateway["Gateway<br/>[gateway.py]"]
  node_rate_limiter["Rate Limiter<br/>policy<br/>[rate_limiter.py]"]
  node_compliance_engine["Compliance<br/>policy"]
  node_audit_logger["Audit Log<br/>[audit_logger.py]"]
  node_service_registry["Service Registry"]
end

subgraph group_state["State"]
  node_session_db[("Session DB<br/>persistence<br/>[session_db.py]")]
  node_vector_store[("Vector Store<br/>retrieval store<br/>[vector_store.py]")]
  node_memory_retriever["Memory Retriever<br/>retrieval service"]
  node_db_models["Data Models<br/>persistence models<br/>[db_models.py]"]
end

subgraph group_tools["MCP Tools"]
  node_pubchem_server["PubChem<br/>mcp server<br/>[index.js]"]
  node_bio_server["Bio MCP<br/>mcp server<br/>[run_biomcp.py]"]
  node_literature_server["Literature<br/>mcp server<br/>[index.js]"]
  node_target_server["Target Biology<br/>mcp server<br/>[index.js]"]
  node_knowledge_server["Web Knowledge<br/>mcp server<br/>[index.js]"]
  node_analysis_server["Data Analysis<br/>mcp server<br/>[index.js]"]
  node_preprint_server["Preprints<br/>mcp server<br/>[index.js]"]
end

node_app_ui -->|"chat requests"| node_agent_orchestrator
node_app_ui -->|"report action"| node_report_agent
node_app_ui -->|"browse history"| node_chat_history_ui
node_app_ui -->|"view reports"| node_report_panel_ui
node_app_ui -->|"view metrics"| node_metrics_tab_ui
node_app_ui -->|"view governance"| node_governance_tab_ui
node_agent_orchestrator -->|"agent loop"| node_base_agent
node_agent_orchestrator -->|"delegate tasks"| node_domain_agents
node_agent_orchestrator -->|"tool planning"| node_mcp_orchestrator
node_mcp_orchestrator -->|"compose calls"| node_tool_composer
node_mcp_orchestrator -->|"execute via gateway"| node_gateway
node_report_agent -->|"evidence sweep"| node_domain_agents
node_report_agent -->|"research tools"| node_mcp_orchestrator
node_gateway -->|"limit"| node_rate_limiter
node_gateway -->|"check"| node_compliance_engine
node_gateway -->|"log"| node_audit_logger
node_gateway -->|"resolve"| node_service_registry
node_session_manager -->|"persist"| node_session_db
node_session_manager -->|"remember"| node_vector_store
node_memory_retriever -->|"query memory"| node_vector_store
node_session_manager -->|"context fetch"| node_memory_retriever
node_session_manager -->|"map state"| node_db_models
node_domain_agents -->|"chemistry"| node_pubchem_server
node_domain_agents -->|"biomed search"| node_bio_server
node_domain_agents -->|"literature"| node_literature_server
node_domain_agents -->|"targets"| node_target_server
node_domain_agents -->|"knowledge"| node_knowledge_server
node_domain_agents -->|"analysis"| node_analysis_server
node_domain_agents -->|"preprints"| node_preprint_server
node_report_agent -->|"save report"| node_session_db
node_report_panel_ui -->|"load report"| node_session_db
node_metrics_tab_ui -->|"usage data"| node_audit_logger
node_governance_tab_ui -->|"audit view"| node_audit_logger

click node_app_ui "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/app.py"
click node_chat_history_ui "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/ui/chat_history.py"
click node_report_panel_ui "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/ui/report_panel.py"
click node_metrics_tab_ui "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/ui/tool_metrics_tab.py"
click node_governance_tab_ui "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/ui/governance_tab.py"
click node_agent_orchestrator "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/orchestration/agent_orchestrator.py"
click node_mcp_orchestrator "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/orchestration/mcp_orchestrator.py"
click node_session_manager "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/orchestration/session_manager.py"
click node_tool_composer "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/orchestration/tool_composer.py"
click node_report_agent "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/agents/report_agent.py"
click node_base_agent "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/agents/base_agent.py"
click node_domain_agents "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/agents/chemical_agent.py"
click node_gateway "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/governance/gateway.py"
click node_rate_limiter "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/governance/rate_limiter.py"
click node_compliance_engine "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/governance/compliance_engine.py"
click node_audit_logger "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/governance/audit_logger.py"
click node_service_registry "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/governance/service_registry.py"
click node_session_db "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/context/session_db.py"
click node_vector_store "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/context/vector_store.py"
click node_memory_retriever "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/context/memory_retriever.py"
click node_db_models "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/context/db_models.py"
click node_pubchem_server "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/servers/pubchem/index.js"
click node_bio_server "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/servers/bio/run_biomcp.py"
click node_literature_server "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/servers/literature/index.js"
click node_target_server "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/servers/opentargets/index.js"
click node_knowledge_server "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/servers/web_knowledge/index.js"
click node_analysis_server "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/servers/data_analysis/index.js"
click node_preprint_server "https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/servers/biorxiv/index.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app_ui,node_chat_history_ui,node_report_panel_ui,node_metrics_tab_ui,node_governance_tab_ui toneBlue
class node_agent_orchestrator,node_mcp_orchestrator,node_session_manager,node_tool_composer,node_report_agent,node_base_agent,node_domain_agents toneAmber
class node_gateway,node_rate_limiter,node_compliance_engine,node_audit_logger,node_service_registry toneMint
class node_session_db,node_vector_store,node_memory_retriever,node_db_models toneRose
class node_pubchem_server,node_bio_server,node_literature_server,node_target_server,node_knowledge_server,node_analysis_server,node_preprint_server toneIndigo
```

## Components

### Presentation

Streamlit user interface and visible app surfaces

- [Streamlit App](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/app.py): ui entrypoint · Primary chat and reporting interface · `streamlit-app/app.py`
- [Chat History](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/ui/chat_history.py): ui component · Session and conversation browsing · `streamlit-app/ui/chat_history.py`
- [Report Panel](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/ui/report_panel.py): ui component · Report viewing and export controls · `streamlit-app/ui/report_panel.py`
- [Metrics Tab](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/ui/tool_metrics_tab.py): ui component · Tool usage and observability views · `streamlit-app/ui/tool_metrics_tab.py`
- [Governance Tab](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/ui/governance_tab.py): ui component · Audit and compliance visibility · `streamlit-app/ui/governance_tab.py`

### Orchestration

Agent routing, report assembly, and session coordination

- [Agent Router](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/orchestration/agent_orchestrator.py): orchestrator · Routes chat requests into agent workflows · `streamlit-app/orchestration/agent_orchestrator.py`
- [MCP Orchestrator](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/orchestration/mcp_orchestrator.py): tool coordinator · Composes and dispatches tool calls · `streamlit-app/orchestration/mcp_orchestrator.py`
- [Session Manager](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/orchestration/session_manager.py): session service · Coordinates session lifecycle and continuity · `streamlit-app/orchestration/session_manager.py`
- [Tool Composer](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/orchestration/tool_composer.py): tool planner · Builds composed tool workflows · `streamlit-app/orchestration/tool_composer.py`
- [Report Agent](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/agents/report_agent.py): report workflow · Drives structured CI report generation · `streamlit-app/agents/report_agent.py`
- [Base Agent](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/agents/base_agent.py): agent base · Shared agent behavior and common loop · `streamlit-app/agents/base_agent.py`
- [Domain Agents](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/agents/chemical_agent.py): agent set · Chemical, clinical, literature, gene, and data specialists · `streamlit-app/agents/chemical_agent.py`

### Control Plane

Governance, compliance, and tool access control

- [Gateway](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/governance/gateway.py): governance gateway · Mediates all tool execution · `streamlit-app/governance/gateway.py`
- [Rate Limiter](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/governance/rate_limiter.py): policy · Controls request and tool-call throughput · `streamlit-app/governance/rate_limiter.py`
- [Compliance](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/governance/compliance_engine.py): policy · Checks requests against policy rules · `streamlit-app/governance/compliance_engine.py`
- [Audit Log](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/governance/audit_logger.py): audit · Records governed tool use and actions · `streamlit-app/governance/audit_logger.py`
- [Service Registry](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/governance/service_registry.py): registry · Controlled catalog of available services · `streamlit-app/governance/service_registry.py`

### State

Persistence, memory, and retrieval support

- [Session DB](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/context/session_db.py): persistence · Stores chats, sessions, and report state · `streamlit-app/context/session_db.py`
- [Vector Store](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/context/vector_store.py): retrieval store · Persistent semantic memory for chat continuity · `streamlit-app/context/vector_store.py`
- [Memory Retriever](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/context/memory_retriever.py): retrieval service · Fetches prior context and related session memory · `streamlit-app/context/memory_retriever.py`
- [Data Models](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/streamlit-app/context/db_models.py): persistence models · Shared session and storage schema objects · `streamlit-app/context/db_models.py`

### MCP Tools

External data and analysis servers exposed through MCP

- [PubChem](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/servers/pubchem/index.js): mcp server · Chemical properties and compound lookup · `servers/pubchem/index.js`
- [Bio MCP](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/servers/bio/run_biomcp.py): mcp server · PubMed, clinical, and biomedical retrieval tools · `servers/bio/run_biomcp.py`
- [Literature](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/servers/literature/index.js): mcp server · Publication search and literature access · `servers/literature/index.js`
- [Target Biology](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/servers/opentargets/index.js): mcp server · OpenTargets and STRING-based target context · `servers/opentargets/index.js`
- [Web Knowledge](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/servers/web_knowledge/index.js): mcp server · General biomedical knowledge retrieval · `servers/web_knowledge/index.js`
- [Data Analysis](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/servers/data_analysis/index.js): mcp server · Derived computations and analysis tools · `servers/data_analysis/index.js`
- [Preprints](https://github.com/moumit-b/bu-senior-design-emd-serono/blob/main/servers/biorxiv/index.js): mcp server · bioRxiv and medRxiv search services · `servers/biorxiv/index.js`

## Connections

- Streamlit App → Agent Router: chat requests · User prompts enter the agent routing layer
- Streamlit App → Report Agent: report action · Report generation is initiated from the UI
- Streamlit App → Chat History: browse history · UI surfaces prior sessions and messages
- Streamlit App → Report Panel: view reports · UI displays generated reports and exports
- Streamlit App → Metrics Tab: view metrics · UI shows tool usage and observability data
- Streamlit App → Governance Tab: view governance · UI exposes audit and compliance status
- Agent Router → Base Agent: agent loop · Orchestration shares common agent behavior
- Agent Router → Domain Agents: delegate tasks · Specialized agents handle domain-specific evidence gathering
- Agent Router → MCP Orchestrator: tool planning · Agent workflows invoke composed tool execution
- MCP Orchestrator → Tool Composer: compose calls · Tool sequences are assembled before dispatch
- MCP Orchestrator → Gateway: execute via gateway · All external execution passes through governance
- Report Agent → Domain Agents: evidence sweep · Report sections gather evidence from specialist agents
- Report Agent → MCP Orchestrator: research tools · Report generation uses the same governed tool path
- Gateway → Rate Limiter: limit · Governance enforces throughput controls
- Gateway → Compliance: check · Requests are screened for policy compliance
- Gateway → Audit Log: log · Tool access and actions are recorded
- Gateway → Service Registry: resolve · Only registered services are reachable
- Session Manager → Session DB: persist · Sessions and messages are stored durably
- Session Manager → Vector Store: remember · Conversation memory is embedded for retrieval
- Memory Retriever → Vector Store: query memory · Retrieval pulls prior context from the store
- Session Manager → Memory Retriever: context fetch · Session handling can restore prior context
- Session Manager → Data Models: map state · Persistence uses shared data models
- Domain Agents → PubChem: chemistry · Chemical analysis uses PubChem data
- Domain Agents → Bio MCP: biomed search · Clinical and biomedical queries use Bio MCP
- Domain Agents → Literature: literature · Evidence gathering reaches literature search services
- Domain Agents → Target Biology: targets · Target biology and interaction data support research
- Domain Agents → Web Knowledge: knowledge · General knowledge sources supplement research
- Domain Agents → Data Analysis: analysis · Derived computations support synthesis
- Domain Agents → Preprints: preprints · Preprint sources feed literature review
- Report Agent → Session DB: save report · Generated reports are tied back to sessions
- Report Panel → Session DB: load report · Saved reports are retrieved for display
- Metrics Tab → Audit Log: usage data · Tool tracking feeds observability views
- Governance Tab → Audit Log: audit view · Governance tab surfaces audit records
