# instill-ai/mgmt-backend architecture

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

- Interactive diagram: https://gitdiagram.com/instill-ai/mgmt-backend
- Repository: https://github.com/instill-ai/mgmt-backend

## Overview

##### Main Components

a. Service Layer (Top Level):
- Public API Gateway (gRPC/REST)
- Private API Gateway (gRPC/REST)
- Health Check Service
- Management Service

b. Core Components (Middle Layer):
- Handler Layer (pkg/handler)
- Public Handler
- Private Handler
- Service Layer (pkg/service)
- Metric Service
- Cache Service
- Repository Layer (pkg/repository)
- InfluxDB Integration
- ACL Layer (pkg/acl)
- Worker Component (pkg/worker)

c. Infrastructure Layer (Bottom Level):
- Database Systems
- SQL Database (evidenced by migrations)
- InfluxDB (for metrics)
- Cache System
- External Services (pkg/external)

##### Component Relationships

- External clients → Public/Private API Gateways
- API Gateways → Handler Layer
- Handler Layer → Service Layer
- Service Layer → Repository Layer
- Repository Layer → Databases
- Worker Component ↔ Service Layer
- Middleware interceptors connecting across layers

##### Additional Elements

Supporting components:
- Configuration management (config/)
- Migration system (cmd/migration)
- Health check endpoints
- Metrics collection points
- Error handling flow

**[Client Layer]**
- ↓
**[API Gateway Layer]**
- ↓
**[Handler/Middleware Layer]**
- ↓
**[Service Layer]**
- ↓
**[Repository Layer]**
- ↓
**[Infrastructure Layer]**

##### Technical Details to Highlight

- gRPC/REST dual protocol support
- Protobuf service definitions
- Database migration patterns
- Caching mechanisms
- Metrics and monitoring
- Authentication/Authorization flow

For this specific project, emphasize:
##### The observability and monitoring setup

This will create a comprehensive yet clear representation of the management backend's architecture that accurately reflects its implementation.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        EC[External Clients]:::client
        IC[Internal Clients]:::client
    end

    subgraph "API Gateway Layer"
        PAG[Public API Gateway]:::api
        PrAG[Private API Gateway]:::api
        HCS[Health Check Service]:::service
    end

    subgraph "Handler & Middleware Layer"
        HL[Handler Layer]:::handler
        PubH[Public Handler]:::handler
        PriH[Private Handler]:::handler
        ML[Middleware Layer]:::middleware
    end

    subgraph "Service Layer"
        SL[Service Layer]:::service
        MS[Metrics Service]:::service
        CS[Cache Service]:::service
    end

    subgraph "Core Components"
        ACL[ACL Layer]:::security
        WC[Worker Component]:::worker
        OT[OpenTelemetry]:::monitoring
    end

    subgraph "Repository Layer"
        RL[Repository Layer]:::repo
        IDB[InfluxDB Integration]:::repo
    end

    subgraph "Infrastructure Layer"
        SQL[(SQL Database)]:::database
        Influx[(InfluxDB)]:::database
        Cache[(Cache System)]:::cache
        ES[External Services]:::external
    end

    subgraph "Support Systems"
        Config[Configuration]:::config
        Mig[Migration System]:::config
        DM[Data Models]:::model
    end

    EC --> PAG
    IC --> PrAG
    PAG --> PubH
    PrAG --> PriH
    
    PubH --> HL
    PriH --> HL
    HL --> ML
    ML --> SL
    
    SL --> MS
    SL --> CS
    SL --> WC
    SL --> ACL
    
    MS --> RL
    CS --> Cache
    RL --> SQL
    RL --> IDB
    IDB --> Influx
    
    WC --> ES
    OT -.-> SL
    Config -.-> SL
    DM -.-> SL
    Mig -.-> SQL

    %% Click Events
    click PAG "https://github.com/instill-ai/mgmt-backend/blob/main/pkg/handler/publichandler.go"
    click PrAG "https://github.com/instill-ai/mgmt-backend/blob/main/pkg/handler/privatehandler.go"
    click HL "https://github.com/instill-ai/mgmt-backend/tree/main/pkg/handler/"
    click SL "https://github.com/instill-ai/mgmt-backend/tree/main/pkg/service/"
    click RL "https://github.com/instill-ai/mgmt-backend/tree/main/pkg/repository/"
    click ACL "https://github.com/instill-ai/mgmt-backend/tree/main/pkg/acl/"
    click WC "https://github.com/instill-ai/mgmt-backend/tree/main/pkg/worker/"
    click IDB "https://github.com/instill-ai/mgmt-backend/blob/main/pkg/repository/influx.go"
    click CS "https://github.com/instill-ai/mgmt-backend/blob/main/pkg/service/cache.go"
    click ES "https://github.com/instill-ai/mgmt-backend/tree/main/pkg/external/"
    click OT "https://github.com/instill-ai/mgmt-backend/tree/main/pkg/logger/otel/"
    click ML "https://github.com/instill-ai/mgmt-backend/tree/main/pkg/middleware/"
    click DM "https://github.com/instill-ai/mgmt-backend/tree/main/pkg/datamodel/"
    click Config "https://github.com/instill-ai/mgmt-backend/tree/main/config/"
    click Mig "https://github.com/instill-ai/mgmt-backend/tree/main/cmd/migration/"
    click MS "https://github.com/instill-ai/mgmt-backend/blob/main/pkg/service/metric.go"
    click HCS "https://github.com/instill-ai/mgmt-backend/tree/main/integration-test/proto/common/healthcheck/"

    %% Styles
    classDef client fill:#E1F5FE,stroke:#01579B
    classDef api fill:#B3E5FC,stroke:#0288D1
    classDef handler fill:#81D4FA,stroke:#0277BD
    classDef service fill:#4FC3F7,stroke:#01579B
    classDef middleware fill:#29B6F6,stroke:#01579B
    classDef repo fill:#03A9F4,stroke:#01579B
    classDef database fill:#039BE5,stroke:#01579B
    classDef cache fill:#0288D1,stroke:#01579B
    classDef security fill:#FF8A80,stroke:#D50000
    classDef monitoring fill:#B388FF,stroke:#651FFF
    classDef worker fill:#82B1FF,stroke:#2962FF
    classDef external fill:#80D8FF,stroke:#0091EA
    classDef config fill:#84FFFF,stroke:#00B8D4
    classDef model fill:#A7FFEB,stroke:#00BFA5
```
