# pydicom/pynetdicom architecture

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

- Interactive diagram: https://gitdiagram.com/pydicom/pynetdicom
- Repository: https://github.com/pydicom/pynetdicom

## Overview

##### Main Components

a. Application Layer
- AE (Application Entity) at the top level as the main interface
- Built-in applications (echoscp, echoscu, findscu, etc.)
- Service class implementations (SCU and SCP services)

b. DIMSE Protocol Layer
- DIMSE-C and DIMSE-N message handling
- Service class operations (C-ECHO, C-FIND, C-STORE, etc.)
- Event handling system

c. Network Layer
- DICOM Upper Layer (DUL) protocol
- PDU (Protocol Data Unit) handling
- Association management
- Presentation context handling

##### Component Relationships

a. External Interfaces
- Connection points for DICOM clients and servers
- Network communication paths
- Integration with pydicom for dataset handling

b. Internal Communication
- Event flow between components
- Data paths between layers
- Association lifecycle management

##### Specific Implementation Details

**Top Level:**
**[Application Entity (AE)]**

- [Service Classes]
- SCU Services
- SCP Services

- [DIMSE Services]
- DIMSE-C (C-ECHO, C-FIND, etc.)
- DIMSE-N (N-EVENT-REPORT, N-GET, etc.)

- [Network Layer]
- Association Management
- PDU Handling
- Transport Services

- [Event System]
- Event Handlers
- Event Dispatching

##### Additional Elements

Include:
- Version information
- External dependency relationships (pydicom)
- Security components (TLS/SSL handling)

##### Flow Indicators

Show:
- Association establishment flow
- DIMSE message routing
- Event propagation paths
- Data flow between components

##### Technical Details

Annotations for:
- Supported DICOM services
- Protocol specifications
- Network ports and interfaces
- Security mechanisms
- Error handling paths

##### Implementation Notes

Create callouts for:
- Critical configuration points
- Performance considerations
- Extensibility points
- Common integration patterns

##### Documentation References

References to:
- API documentation locations
- Configuration guides
- Service class specifications
- DICOM standard references

This system design should be created using a professional diagramming tool that supports UML or similar notation, with careful attention to maintaining clarity while showing the complex interactions between components.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Application Layer"
        AE["Application Entity (AE)"]
        ServiceClasses["Service Classes"]
        BuiltInApps["Built-in Applications"]
        
        subgraph "Service Class Components"
            SCU["SCU Services"]
            SCP["SCP Services"]
            SOPClasses["SOP Classes"]
        end
        
        subgraph "Applications"
            EchoSCP["Echo SCP"]
            EchoSCU["Echo SCU"]
            FindSCU["Find SCU"]
            StoreSCU["Store SCU"]
            StoreSCP["Store SCP"]
        end
    end
    
    subgraph "DIMSE Layer"
        DIMSE["DIMSE Protocol"]
        DIMSEMessages["DIMSE Messages"]
        DIMSEPrimitives["DIMSE Primitives"]
    end
    
    subgraph "Network Layer"
        DUL["DUL Provider"]
        PDU["PDU Handling"]
        PDUItems["PDU Items"]
        Association["Association Management"]
        Transport["Transport Services"]
        PresentationContext["Presentation Context"]
        StateMachine["State Machine"]
    end
    
    subgraph "Event System"
        EventHandler["Event Handler"]
        EventDispatch["Event Dispatcher"]
    end
    
    %% Relationships
    AE --> ServiceClasses
    AE --> BuiltInApps
    ServiceClasses --> SCU
    ServiceClasses --> SCP
    ServiceClasses --> SOPClasses
    
    BuiltInApps --> EchoSCP
    BuiltInApps --> EchoSCU
    BuiltInApps --> FindSCU
    BuiltInApps --> StoreSCU
    BuiltInApps --> StoreSCP
    
    SCU --> DIMSE
    SCP --> DIMSE
    DIMSE --> DIMSEMessages
    DIMSE --> DIMSEPrimitives
    
    DIMSEMessages --> DUL
    DUL --> PDU
    PDU --> PDUItems
    DUL --> Association
    Association --> Transport
    Association --> PresentationContext
    Association --> StateMachine
    
    AE --> EventHandler
    EventHandler --> EventDispatch
    
    %% Styling
    classDef core fill:#a8d1f0
    classDef network fill:#90EE90
    classDef event fill:#FFE5B4
    classDef dimse fill:#FFB6C1
    
    class AE,ServiceClasses,BuiltInApps core
    class DUL,PDU,PDUItems,Association,Transport,PresentationContext,StateMachine network
    class EventHandler,EventDispatch event
    class DIMSE,DIMSEMessages,DIMSEPrimitives dimse
    
    %% Click Events
    click AE "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/ae.py"
    click ServiceClasses "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/service_class.py"
    click EchoSCP "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/apps/echoscp/echoscp.py"
    click EchoSCU "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/apps/echoscu/echoscu.py"
    click FindSCU "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/apps/findscu/findscu.py"
    click StoreSCU "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/apps/storescu/storescu.py"
    click StoreSCP "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/apps/storescp/storescp.py"
    click DIMSE "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/dimse.py"
    click DIMSEMessages "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/dimse_messages.py"
    click DIMSEPrimitives "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/dimse_primitives.py"
    click DUL "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/dul.py"
    click PDU "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/pdu.py"
    click PDUItems "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/pdu_items.py"
    click Association "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/association.py"
    click EventHandler "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/events.py"
    click PresentationContext "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/presentation.py"
    click SOPClasses "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/sop_class.py"
    click Transport "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/transport.py"
    click StateMachine "https://github.com/pydicom/pynetdicom/blob/main/pynetdicom/fsm.py"
```
