# senthilkumarv/purchasesample architecture

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

- Interactive diagram: https://gitdiagram.com/senthilkumarv/purchasesample
- Repository: https://github.com/senthilkumarv/purchasesample

## Overview

##### Project Type and Purpose
- This is a Microsoft BizTalk Server sample application that orchestrates a purchase flow.
- It includes message schemas, maps, orchestrations, a WCF service application, and a sample .NET client.

##### File Structure
- Top-level solution: PurchaseSample.sln
- Key projects / folders:
- PurchaseSchemas: XML schema definitions (.xsd) and generated classes for PurchaseRequest, PurchaseResponse, ErrorSchema.
- PurchaseMaps: BizTalk maps (.btm) to transform between schemas.
- PurchaseOrchestrations: BizTalk orchestrations (.odx) that implement the business process.
- PurchaseExternalServices: WCF-exposed endpoints for external purchase service ports.
- PurchaseServiceApplication: The WCF service host (MakePurchaseService.svc) that receives client calls.
- PurchaseLibrary: Shared .NET code (entities, validators, repository, business helper).
- WcfClient: Sample .NET console client that calls the BizTalk-exposed WCF service.
- DeployScripts: Build scripts for deployment.
- SampleData.sql: Placeholder for any database scripts if needed.

##### README
- Confirms this is a BizTalk orchestration sample for a purchase flow.

##### Main Components
a. WCF Client
- Reads .NET proxy under WcfClient/Service References.
- Sends PurchaseRequest via SOAP to the BizTalk WCF endpoint.
b. BizTalk Receive Port / WCF Adapter
- Hosted in PurchaseServiceApplication.
- Exposes MakePurchaseService.svc endpoint.
- Accepts and serializes incoming XML into BizTalk messages (using schemas from PurchaseSchemas).
c. Orchestration Layer
- PurchaseOrchestrations project.
- Implements the ProcessPurchase / PurchaseOrchestration flows.
- Invokes message validations, transformations, business rules.
d. Maps & Pipelines
- PurchaseMaps maps for Request→Orchestration internal format, and Orchestration output→Response.
e. Business Library
- PurchaseLibrary: domain entities (Customer, Product), validators, repository, helpers.
f. External Service Port(s)
- PurchaseExternalServices: a WCF service endpoint(s) representing the back-end fulfillment system.
- Uses schemas in PurchaseExternalServices/App_Data.
g. Data Store (optional)
- If PurchaseRepository uses a database, represent it as a Database component.
h. WCF Return Path
- Orchestration returns PurchaseResponse back out via the BizTalk send port to the client.

##### Architectural Patterns & Design Principles
- Message-based choreography with BizTalk MessageBox acting as the publish-subscribe broker.
- Separation of concerns:
- Schemas define message contracts
- Maps handle transformations
- Orchestrations coordinate process logic
- Libraries encapsulate business rules & persistence.
- Use of WCF adapters for inbound (receive) and outbound (send) communication.
- Exception handling via the ErrorSchema and ErrorPort messages.

##### Technologies & Frameworks to Call Out
- BizTalk Server (MessageBox, Orchestrations, Maps, Pipelines).
- WCF (for service contracts & endpoints).
- .NET Class Library (C#) for business logic.
- XML Schema (XSD) for message definitions.
- BTDF or custom DeployScripts for automated deployment.
- SQL Server (if PurchaseRepository persists data).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Client
    WcfClient["WCF Client\n(Program.cs)"]:::client
    click WcfClient "https://github.com/senthilkumarv/purchasesample/blob/master/WcfClient/Program.cs"

    %% BizTalk Receive Port
    RecPort["MakePurchaseService.svc Receive Port\n(WCF-Custom)"]:::adapter
    click RecPort "https://github.com/senthilkumarv/purchasesample/blob/master/PurchaseServiceApplication/MakePurchaseService.svc"

    %% BizTalk Application Boundary
    subgraph "BizTalk Application" 
        direction TB
        MsgBox["MessageBox\n(Publish/Subscribe Broker)"]:::broker

        subgraph Schemas
            direction TB
            SC1["PurchaseRequest.xsd"]:::schema
            click SC1 "https://github.com/senthilkumarv/purchasesample/blob/master/PurchaseSchemas/PurchaseRequest.xsd"
            SC1cs["PurchaseRequest.xsd.cs"]:::schema
            click SC1cs "https://github.com/senthilkumarv/purchasesample/blob/master/PurchaseSchemas/PurchaseRequest.xsd.cs"
            SC2["PurchaseResponse.xsd"]:::schema
            click SC2 "https://github.com/senthilkumarv/purchasesample/blob/master/PurchaseSchemas/PurchaseResponse.xsd"
            SC2cs["PurchaseResponse.xsd.cs"]:::schema
            click SC2cs "https://github.com/senthilkumarv/purchasesample/blob/master/PurchaseSchemas/PurchaseResponse.xsd.cs"
            SC3["ErrorSchema.xsd"]:::schema
            click SC3 "https://github.com/senthilkumarv/purchasesample/blob/master/PurchaseSchemas/ErrorSchema.xsd"
            SC3cs["ErrorSchema.xsd.cs"]:::schema
            click SC3cs "https://github.com/senthilkumarv/purchasesample/blob/master/PurchaseSchemas/ErrorSchema.xsd.cs"
        end

        subgraph Maps
            direction TB
            MP1["PurchaseFlowMap"]:::map
            click MP1 "https://github.com/senthilkumarv/purchasesample/blob/master/PurchaseMaps/PurchaseFlowMap.btm"
            MP2["PurchaseErrorMap"]:::map
            click MP2 "https://github.com/senthilkumarv/purchasesample/blob/master/PurchaseMaps/PurchaseErrorMap.btm"
        end

        subgraph Orchestrations
            direction TB
            OR1["PurchaseOrchestration.odx"]:::orchestration
            click OR1 "https://github.com/senthilkumarv/purchasesample/blob/master/PurchaseOrchestrations/PurchaseOrchestartion.odx"
            OR2["ProcessPurchase.odx"]:::orchestration
            click OR2 "https://github.com/senthilkumarv/purchasesample/blob/master/PurchaseOrchestrations/ProcessPurchase.odx"
        end

        subgraph "Business Library"
            direction TB
            BL["PurchaseLibrary"]:::library
            click BL "https://github.com/senthilkumarv/purchasesample/blob/master/PurchaseLibrary/PurchaseHelper.csproj"
        end

        SendPort["WCF Send Adapter\n(Send Port)"]:::adapter
    end

    %% External Service and Data Store
    ExtSvc["External Fulfillment Service\n(WCF Stub)"]:::external
    click ExtSvc "https://github.com/senthilkumarv/purchasesample/blob/master/PurchaseExternalServices/PurchaseOrchestrations_PurchaseOrchestartion_PurchasePort.svc"

    DB["PurchaseDB"]:::db

    %% Data Flow
    WcfClient -->|1. SOAP Request| RecPort
    RecPort -->|2. Publish Message| MsgBox
    MsgBox -->|3. Subscription| OR1
    OR1 -->|4. Transform Request| MP1
    MP1 --> OR1
    OR1 -->|5. Invoke Business Logic| BL
    BL --> OR1
    OR1 -->|6. Call External Service| ExtSvc
    ExtSvc -->|7. Response| OR1
    OR1 -->|Transform Response| MP1
    MP1 --> OR1
    OR1 -->|8. Send Response| SendPort
    SendPort --> WcfClient

    %% Database Interaction (optional)
    OR1 -->|Read/Write| DB

    %% Legend
    subgraph Legend
        direction TB
        L1["Blue: BizTalk Artifacts"]:::schema
        L2["Green: Database"]:::db
        L3["Grey: .NET Libraries"]:::library
        L4["Orange: External Services"]:::external
        L5["Adapter: Receive/Send Ports"]:::adapter
    end

    classDef client fill:#f0f0f0,stroke:#333,stroke-width:1px
    classDef adapter fill:#fdebd0,stroke:#d35400,stroke-width:1px
    classDef broker fill:#d6eaf8,stroke:#2874a6,stroke-width:1px
    classDef schema fill:#d6eaf8,stroke:#21618c,stroke-width:1px
    classDef map fill:#aed6f1,stroke:#1f618d,stroke-width:1px
    classDef orchestration fill:#85c1e9,stroke:#1a5276,stroke-width:1px
    classDef library fill:#d5d8dc,stroke:#566573,stroke-width:1px
    classDef external fill:#f9e79f,stroke:#b9770e,stroke-width:1px
    classDef db fill:#a9dfbf,stroke:#196f3d,stroke-width:1px
```
