# ahmedelzaria/medsender-challenge architecture

> Architecture diagram of the GitHub repository ahmedelzaria/medsender-challenge, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ahmedelzaria/medsender-challenge
- Repository: https://github.com/ahmedelzaria/medsender-challenge

## Overview

##### Main Components

a) External Services Layer:
- OpenAI API (GPT-4o-mini)
- Llama Parse API

b) Application Core:
- FastAPI Web Server
- File Processing Pipeline
- Validation System
- Document Processing System
- Model Integration Layer

c) Storage/Temporary Components:
- Temporary File Storage for PDF processing

##### Key Architectural Patterns to Highlight

a) The Composite Validator Pattern:
- How multiple validators (size, extension, MIME) can be combined
- Inheritance hierarchy from BaseValidator

b) The Processor Pattern:
- BaseProcessor and its PDF implementation
- Leave room for future processor types

c) The Model Handler Pattern:
- OpenAI model integration
- Extension points for future models

**1. Input Layer:**
- [PDF Document] → [FastAPI Endpoint]

**2. Validation Layer (use a composite pattern visualization):**
- SizeValidator
- ExtensionValidator
- MimeValidator
- Connected through CompositeValidator

**3. Processing Pipeline:**
- [PDF Processor] → [Llama Parse] → [Text Extraction] → [OpenAI Processing]

**4. Output Layer:**
- [Structured JSON Response]

##### Important Relationships

- The validation chain showing how multiple validators work together
- The processing pipeline's sequential flow
- Error handling paths returning to the client
- External API integration points

##### Specific Implementation Details

- The app/processors directory structure showing extensibility
- The app/validators hierarchy
- The app/models integration point
- The prompts system integration

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        PDF[PDF Document]
        API[FastAPI Endpoint]:::api
    end

    subgraph Validation
        CV[Composite Validator]:::validator
        SV[Size Validator]:::validator
        EV[Extension Validator]:::validator
        MV[MIME Validator]:::validator
    end

    subgraph Processing
        BP[Base Processor]:::processor
        PP[PDF Processor]:::processor
        LP[Llama Parse]:::external
        TE[Text Extraction]:::processor
        OAI[OpenAI GPT-4]:::external
    end

    subgraph Output
        JSON[Structured JSON Response]
    end

    %% Relationships
    PDF --> API
    API --> CV
    CV --> SV
    CV --> EV
    CV --> MV
    CV --> BP
    BP --> PP
    PP --> LP
    LP --> TE
    TE --> OAI
    OAI --> JSON

    %% Error Paths
    CV -- Validation Error --> API
    PP -- Processing Error --> API
    LP -- Parse Error --> API
    OAI -- Model Error --> API

    %% Styling
    classDef api fill:#9cf,stroke:#333
    classDef validator fill:#ffd700,stroke:#333
    classDef processor fill:#90EE90,stroke:#333
    classDef external fill:#ff9999,stroke:#333

    %% Click Events
    click API "https://github.com/AHMEDELZARIA/medsender-challenge/blob/main/app/main.py"
    click CV "https://github.com/AHMEDELZARIA/medsender-challenge/blob/main/app/validators/composite_validator.py"
    click SV "https://github.com/AHMEDELZARIA/medsender-challenge/blob/main/app/validators/size_validator.py"
    click EV "https://github.com/AHMEDELZARIA/medsender-challenge/blob/main/app/validators/extention_validator.py"
    click MV "https://github.com/AHMEDELZARIA/medsender-challenge/blob/main/app/validators/mime_validator.py"
    click BP "https://github.com/AHMEDELZARIA/medsender-challenge/blob/main/app/processors/base_processor.py"
    click PP "https://github.com/AHMEDELZARIA/medsender-challenge/blob/main/app/processors/pdf_processor.py"
    click LP "https://github.com/AHMEDELZARIA/medsender-challenge/blob/main/app/prompts/llama_parser_prompt.txt"
    click OAI "https://github.com/AHMEDELZARIA/medsender-challenge/blob/main/app/prompts/open_ai_prompt.txt"

    %% Legend
    subgraph Legend
        L1[API Component]:::api
        L2[Validator Component]:::validator
        L3[Processor Component]:::processor
        L4[External Service]:::external
    end
```
