# alexandrebruno/ocr.aivision architecture

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

- Interactive diagram: https://gitdiagram.com/alexandrebruno/ocr.aivision
- Repository: https://github.com/alexandrebruno/ocr.aivision

## Overview

##### Main Components
- API Layer (Presentation):
- OCR.AIVision.Api project as the entry point for external requests.
- Endpoints (e.g., OCREndpoints.cs) defining routes such as POST /OCR/ProcessarImagemDeStringBase64 and /OCR/ProcessarImagemDeArquivo.
- That this layer uses Minimal API concepts and acts as the interface for client interactions.

- Application Layer (Business Logic):
- OCR.AIVision.Application project which handles dependency injection (ServiceConfig.cs), helper functions, and service implementations (OCRService.cs).
- Role of interfaces (IOCRService.cs) to abstract business logic.

- Domain Layer:
- OCR.AIVision.Domain project containing the core entities (OCRRequest and OCRResponse) and configuration files (oci.config).
- Role in modeling the problem domain and encapsulating core business rules.

- External Integrations:
- External services like Oracle AI Vision, accessed via the OCI.DotNetSDK libraries (OCI.DotNetSDK.Aivision and OCI.DotNetSDK.Common).
- Configuration files necessary for Oracle authentication (oci.pem and oci.config) and application settings (appsettings.json).

##### Relationships and Interactions
- Client requests hit the API endpoint, which then delegates calls to the Application layer.
- The Application layer implements business logic and calls into the Domain layer as needed (e.g., mapping OCRRequest/Response).
- The Application layer communicates with Oracle AI Vision via the SDK, sending images (base64 encoded or file uploads) for processing.
- How responses with objects like OCRResponse (including the CorrelationId) are passed back through the layers to the client.

##### Architectural Patterns and Principles
- DDD: Demonstrate separation between the Domain (pure business model), the Application (services and orchestration), and the API (interface).
- Minimal API: Reflect that the API layer is designed with minimal overhead.
- Dependency Injection: Mention the Injections/ServiceConfig.cs in the Application layer that wires up the services.

##### Relevant Technologies, Frameworks, and Libraries
- .NET 8 and Minimal API framework for building lightweight HTTP services.
- Oracle AI Vision SDKs (OCI.DotNetSDK.Aivision, OCI.DotNetSDK.Common) for integrating with external image processing.
- Docker for containerized deployment.
- The configuration management via appsettings.json and Oracle’s config files (oci.config, oci.pem).

##### Final Detailed Steps
- Next, detail the Domain layer with essential entities and domain rules.
- Finally, connect everything to external Oracle services indicating dependency on OCI SDK libraries.
- And don’t forget to show the Docker container at the outer perimeter if discussing deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    Client["Client"]:::client

    %% Deployment
    subgraph "Deployment"
        DOCKER["Dockerfile"]:::container
    end

    %% API Layer (Presentation)
    subgraph "API Layer (Presentation)"
        API["OCR.AIVision.Api"]:::api
        API_Program["Program.cs"]:::api
        API_Endpoints["OCREndpoints.cs (Endpoints)"]:::api
        API_Appsettings["appsettings.json"]:::api
        API_AppsettingsDev["appsettings.Development.json"]:::api
        API_OCIPem["oci.pem"]:::api
    end

    %% Application Layer (Business Logic)
    subgraph "Application Layer (Business Logic)"
        APP_Inj["ServiceConfig.cs"]:::application
        APP_Helper["Helper.cs"]:::application
        APP_OCRService["OCRService.cs"]:::application
        APP_Interface["IOCRService.cs"]:::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        DOM_Request["OCRRequest.cs"]:::domain
        DOM_Response["OCRResponse.cs"]:::domain
        DOM_OciConfig["oci.config"]:::domain
    end

    %% External Integration
    External["Oracle AI Vision Service"]:::external

    %% Connections
    Client -->|"HTTP_Request"| API_Endpoints
    API_Program -->|"initializes"| API_Endpoints
    API_Appsettings -->|"loads_config"| API_Program
    API_AppsettingsDev -->|"loads_config"| API_Program
    API_OCIPem -->|"provides_credentials"| API

    %% API to Application
    API_Endpoints -->|"delegates"| APP_OCRService

    %% Internal Application relationships
    APP_Inj -->|"injects"| APP_OCRService
    APP_Helper -->|"assists"| APP_OCRService
    APP_Interface -->|"defines_contract"| APP_OCRService

    %% Application to Domain and External
    APP_OCRService -->|"mapsRequest"| DOM_Request
    DOM_Request -->|"processes_to"| DOM_Response
    DOM_Response -->|"returnsMapping"| APP_OCRService
    APP_OCRService -->|"calls"| External
    External -->|"returnsResult"| APP_OCRService

    %% Response Flow back to Client
    APP_OCRService -->|"sendsResponse"| API_Endpoints
    API_Endpoints -->|"returnsResponse"| Client

    %% Docker hosting
    DOCKER -->|"hosts"| API

    %% Styling
    classDef api fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef application fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef domain fill:#F08080,stroke:#333,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef container fill:#FFA500,stroke:#333,stroke-width:2px;
    classDef client fill:#DDA0DD,stroke:#333,stroke-width:2px;

    %% Click Events for API Layer
    click API_Program "https://github.com/alexandrebruno/ocr.aivision/blob/main/OCR.AIVision.Api/Program.cs"
    click API_Endpoints "https://github.com/alexandrebruno/ocr.aivision/blob/main/OCR.AIVision.Api/Endpoints/OCREndpoints.cs"
    click API_Appsettings "https://github.com/alexandrebruno/ocr.aivision/blob/main/OCR.AIVision.Api/appsettings.json"
    click API_AppsettingsDev "https://github.com/alexandrebruno/ocr.aivision/blob/main/OCR.AIVision.Api/appsettings.Development.json"
    click API_OCIPem "https://github.com/alexandrebruno/ocr.aivision/blob/main/OCR.AIVision.Api/oci.pem"

    %% Click Events for Application Layer
    click APP_Inj "https://github.com/alexandrebruno/ocr.aivision/blob/main/OCR.AIVision.Application/Configuration/Injections/ServiceConfig.cs"
    click APP_Helper "https://github.com/alexandrebruno/ocr.aivision/blob/main/OCR.AIVision.Application/Helpers/Helper.cs"
    click APP_OCRService "https://github.com/alexandrebruno/ocr.aivision/blob/main/OCR.AIVision.Application/Service/OCRService.cs"
    click APP_Interface "https://github.com/alexandrebruno/ocr.aivision/blob/main/OCR.AIVision.Application/Interface/Service/IOCRService.cs"

    %% Click Events for Domain Layer
    click DOM_Request "https://github.com/alexandrebruno/ocr.aivision/blob/main/OCR.AIVision.Domain/Entities/Request/OCRRequest.cs"
    click DOM_Response "https://github.com/alexandrebruno/ocr.aivision/blob/main/OCR.AIVision.Domain/Entities/Response/OCRResponse.cs"
    click DOM_OciConfig "https://github.com/alexandrebruno/ocr.aivision/blob/main/OCR.AIVision.Domain/OCI/oci.config"

    %% Click Event for Dockerfile
    click DOCKER "https://github.com/alexandrebruno/ocr.aivision/tree/main/Dockerfile"
```
