# libopenstorage/grpc-framework architecture

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

- Interactive diagram: https://gitdiagram.com/libopenstorage/grpc-framework
- Repository: https://github.com/libopenstorage/grpc-framework

## Overview

##### Main Components

a. Core Framework Components:
- gRPC Server Layer
- REST Gateway Layer
- Authentication/Authorization System
- Rate Limiter
- Interceptors Layer

b. Supporting Components:
- Protocol Buffer Compiler Integration
- Documentation Generator
- Client SDK Components
- Security Components

##### Component Relationships

**┌─────────────────────────────────────────────────────────────┐**
- Client Applications                      │
- ┬─────────────────────────┬──────────────────┘

- ▼                         ▼
**┌────────────────────┐         ┌──────────────────┐**
- gRPC Client     │         │   REST Client    │
- ┬───────┘         └────────┬─────────┘

- ▼                          ▼
**┌─────────────────────────────────────────────────────────────┐**
- Framework Core                           │
- ┌─────────────┐  ┌──────────────┐  ┌──────────────────┐  │
- Security  │  │              │  │  Rate Limiter    │  │
- Layer     │◄─┤  Interceptor ├─►│    Service      │  │
- (Auth/TLS)  │  │    Chain     │  │                 │  │
- ┘  └──────┬───────┘  └──────────────────┘  │
- ▲                 │                    ▲           │
- ▼                    │           │
- ┌─────────────┐  ┌──────────────┐    ┌──────────────┐   │
- Ownership  │  │  gRPC Server │    │ REST Gateway │   │
- Control   │◄─┤    Core      ├───►│   (Auto-gen) │   │
- ┘  └──────────────┘    └──────────────┘   │
- ┘

- ▼
**┌─────────────────────────────────────────────────────────────┐**
- User Implementation                         │
- (Service definitions and business logic)               │
- ┘

##### Important Elements to Highlight

a. Security Features:
- Authentication (pkg/auth)
- Authorization (pkg/auth/role)
- TLS Support
- Ownership Management (pkg/auth/ownership)

b. Core Features:
- Protocol Buffer Integration
- Automatic REST Gateway Generation
- Rate Limiting
- Correlation ID Management (pkg/correlation)
- Interceptor Chain

c. Client Integration:
- gRPC Client Support
- Credential Injection (pkg/grpc/client/creds_injector)
- Default Context Management

##### Implementation Details

- Relationship between the proto files and generated code
- Where interceptors can be injected
- Automatic REST gateway generation process
- Security middleware chain

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Clients
        GC[gRPC Client]:::client
        RC[REST Client]:::client
    end

    subgraph "Framework Core"
        direction TB
        subgraph "Security Layer"
            direction TB
            Auth[Authentication/Authorization]:::security
            TLS[TLS/Security]:::security
            Own[Ownership Control]:::security
        end

        subgraph "Core Services"
            direction TB
            IC[Interceptor Chain]:::core
            RL[Rate Limiter]:::core
            Meta[Metadata Management]:::core
            Corr[Correlation System]:::core
        end

        subgraph "Server Layer"
            direction TB
            GRPC[gRPC Server]:::server
            REST[REST Gateway]:::server
        end
    end

    subgraph "Implementation Layer"
        UserSvc[User Services]:::impl
        Proto[Proto Definitions]:::impl
    end

    GC --> IC
    RC --> REST
    IC --> Auth
    IC --> RL
    IC --> GRPC
    GRPC --> REST
    GRPC --> UserSvc
    Auth --> Own
    Auth --> TLS
    IC --> Meta
    IC --> Corr

    %% Click Events
    click GRPC "https://github.com/libopenstorage/grpc-framework/blob/master/server/grpc_framework_server.go"
    click REST "https://github.com/libopenstorage/grpc-framework/blob/master/server/rest_gateway.go"
    click Auth "https://github.com/libopenstorage/grpc-framework/blob/master/pkg/auth/auth.go"
    click RL "https://github.com/libopenstorage/grpc-framework/blob/master/server/ratelimiter.go"
    click IC "https://github.com/libopenstorage/grpc-framework/blob/master/server/server_interceptors.go"
    click GC "https://github.com/libopenstorage/grpc-framework/blob/master/pkg/grpc/client/client.go"
    click Own "https://github.com/libopenstorage/grpc-framework/blob/master/pkg/auth/ownership/ownership.go"
    click Meta "https://github.com/libopenstorage/grpc-framework/blob/master/pkg/grpc/metadata/metadata.go"
    click Corr "https://github.com/libopenstorage/grpc-framework/blob/master/pkg/correlation/context.go"

    %% Styling
    classDef client fill:#FFA500,stroke:#333,stroke-width:2px
    classDef security fill:#90EE90,stroke:#333,stroke-width:2px
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef server fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef impl fill:#F0F8FF,stroke:#333,stroke-width:2px
```
