# opsmill/infrahub architecture

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

- Interactive diagram: https://gitdiagram.com/opsmill/infrahub
- Repository: https://github.com/opsmill/infrahub

## Overview

##### Main Components Architecture

a) Frontend Layer:
- React-based web application (in /frontend/app)
- Component library (/frontend/packages/ui)
- GraphQL client interface
- Plugin system (/frontend/packages/plugins)

b) Backend Layer:
- FastAPI-based API server (/backend/infrahub/api)
- GraphQL server (/backend/infrahub/graphql)
- Core business logic (/backend/infrahub/core)
- Authentication system (/backend/infrahub/auth)

c) Data Storage:
- Graph database (supports Neo4j and Memgraph)
- Object storage for artifacts
- Git integration for version control

##### Key Subsystems

a) Schema Management:
- Schema validation
- Migration handling
- Version control integration

b) Version Control:
- Branch management
- Diff calculation
- Merge operations
- Conflict resolution

c) Resource Management:
- IPAM (IP Address Management)
- Resource pools
- Allocation tracking

##### Integration Points

External integration points:

- Git repositories
- Message queues (NATS/RabbitMQ)
- Object storage systems
- Authentication providers (OIDC/OAuth2)

##### Data Flow

Main data flows:

a) User Operations:
- UI → GraphQL API → Core Logic → Database
- Version Control Operations → Git Integration → Core Logic
- Resource Allocation Requests → Resource Manager → Database

b) Background Operations:
- Schema Validation
- Diff Calculation
- Merge Operations
- Task Processing

##### Deployment View

A deployment perspective showing:

- API Server containers
- Worker nodes
- Database instances
- Message queue services
- Git agent services

##### Cross-Cutting Concerns

Shared services:

- Authentication & Authorization
- Event handling
- Task scheduling
- Logging & Monitoring
- Message bus

##### Layer organization
- Present in clear horizontal layers
- Cross-cutting concerns vertically
- Related components together

Remember to maintain a balance between detail and clarity, focusing on the architectural decisions that matter most for understanding the system's structure and behavior.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        FA[Frontend App]
        CL[Component Library]
        PS[Plugin System]
        GC[GraphQL Client]
        FA --> GC
        FA --> CL
        FA --> PS
    end

    subgraph Backend
        API[FastAPI Server]
        GS[GraphQL Server]
        BL[Core Business Logic]
        Auth[Authentication System]
        API --> GS
        GS --> BL
        API --> Auth
    end

    subgraph "Data Storage"
        DB[(Graph Database)]
        OS[(Object Storage)]
        Git[("Git Storage")]
    end

    subgraph "Schema Management"
        SV[Schema Validation]
        MH[Migration Handler]
        VC[Version Control]
    end

    subgraph "Resource Management"
        IPAM[IP Management]
        RP[Resource Pools]
        AT[Allocation Tracker]
    end

    subgraph "Cross-Cutting Services"
        MB[Message Bus]
        TP[Task Processor]
        Log[Logging System]
    end

    GC --> API
    BL --> DB
    BL --> OS
    BL --> Git
    BL --> SV
    BL --> MH
    BL --> VC
    BL --> IPAM
    BL --> RP
    BL --> AT
    BL --> MB
    MB --> TP
    TP --> Log

    %% Click events for component mapping
    click FA "https://github.com/opsmill/infrahub/tree/stable/frontend/app/src"
    click CL "https://github.com/opsmill/infrahub/tree/stable/frontend/packages/ui"
    click PS "https://github.com/opsmill/infrahub/tree/stable/frontend/packages/plugins"
    click GC "https://github.com/opsmill/infrahub/tree/stable/frontend/app/src/graphql"
    click API "https://github.com/opsmill/infrahub/tree/stable/backend/infrahub/api"
    click GS "https://github.com/opsmill/infrahub/tree/stable/backend/infrahub/graphql"
    click BL "https://github.com/opsmill/infrahub/tree/stable/backend/infrahub/core"
    click Auth "https://github.com/opsmill/infrahub/blob/stable/backend/infrahub/auth.py"
    click SV "https://github.com/opsmill/infrahub/tree/stable/backend/infrahub/core/schema"
    click MH "https://github.com/opsmill/infrahub/tree/stable/backend/infrahub/core/migrations"
    click VC "https://github.com/opsmill/infrahub/tree/stable/backend/infrahub/git"
    click IPAM "https://github.com/opsmill/infrahub/tree/stable/backend/infrahub/core/node/resource_manager"
    click RP "https://github.com/opsmill/infrahub/tree/stable/backend/infrahub/pools"
    click TP "https://github.com/opsmill/infrahub/tree/stable/backend/infrahub/core/task"
    click MB "https://github.com/opsmill/infrahub/tree/stable/backend/infrahub/message_bus"
    click OS "https://github.com/opsmill/infrahub/blob/stable/backend/infrahub/storage.py"

    classDef frontend fill:#2374ab
    classDef backend fill:#2a9d8f
    classDef storage fill:#e9c46a
    classDef management fill:#f4a261
    classDef service fill:#8338ec

    class FA,CL,PS,GC frontend
    class API,GS,BL,Auth backend
    class DB,OS,Git storage
    class SV,MH,VC,IPAM,RP,AT management
    class MB,TP,Log service
```
