Skip to content

ArchitectureΒΆ

This page provides an overview of InfraKitchen's system architecture and how the components work together.


πŸ—οΈ High-Level ArchitectureΒΆ

InfraKitchen follows a modern web application architecture with separated frontend, backend, and infrastructure layers.

InfraKitchen Architecture

ComponentsΒΆ

  • Frontend (React/TypeScript) - User interface for managing infrastructure
  • Backend (Python/FastAPI) - REST API and business logic
  • PostgreSQL - Relational database for storing infrastructure state
  • RabbitMQ - Message broker for asynchronous task processing
  • Worker Processes - Execute infrastructure provisioning tasks
  • OpenTofu/Terraform - Infrastructure-as-Code execution engine

πŸ”„ Request FlowΒΆ

1. User Creates a ResourceΒΆ

sequenceDiagram
    participant User
    participant Frontend
    participant Backend
    participant Database
    participant RabbitMQ

    User->>Frontend: Fill resource form
    Frontend->>Backend: POST /api/v1/resources
    Backend->>Database: Create resource record
    Backend->>Frontend: Return resource (state: provision)
    Frontend->>User: Show resource created

2. User Provisions the ResourceΒΆ

sequenceDiagram
    participant User
    participant Frontend
    participant Backend
    participant RabbitMQ
    participant Worker
    participant OpenTofu
    participant Cloud

    User->>Frontend: Click "Provision"
    Frontend->>Backend: POST /api/v1/resources/{id}/provision
    Backend->>RabbitMQ: Queue provisioning task
    Backend->>Frontend: Return task queued

    Worker->>RabbitMQ: Pick up task
    Worker->>OpenTofu: Execute tofu apply
    OpenTofu->>Cloud: Create infrastructure
    Cloud->>OpenTofu: Return outputs
    OpenTofu->>Worker: Apply complete
    Worker->>Backend: Update resource (state: provisioned)
    Backend->>Frontend: WebSocket update
    Frontend->>User: Show provisioned

🧩 Backend Module Relations¢

InfraKitchen's backend is organized into distinct modules with clear responsibilities:

Backend Modules

Module StructureΒΆ

Text Only
server/src/
β”œβ”€β”€ application/          # Application layer
β”‚   β”œβ”€β”€ resources/       # Resource management
β”‚   β”œβ”€β”€ templates/       # Template management
β”‚   β”œβ”€β”€ integrations/    # Integration management
β”‚   β”œβ”€β”€ workspaces/      # Workspace sync
β”‚   └── ...
β”œβ”€β”€ core/                # Core utilities
β”‚   β”œβ”€β”€ adapters/        # External service adapters
β”‚   β”œβ”€β”€ config.py        # Configuration
β”‚   β”œβ”€β”€ database.py      # Database connection
β”‚   └── errors.py        # Custom exceptions
β”‚   └── ...
└── fixtures/            # Demo data

Key LayersΒΆ

  1. View Layer (*_view.py)

    • FastAPI route handlers
    • Request/response validation
    • Authentication/authorization
  2. Service Layer (*_service.py)

    • Business logic
    • Orchestration between modules
    • Transaction management
  3. CRUD Layer (*_crud.py)

    • Database operations
    • Query building
    • Data access patterns
  4. Task Layer (*_task.py)

    • Asynchronous operations
    • Long-running processes
    • Background jobs
  5. Model Layer (*_model.py)

    • SQLAlchemy ORM models
    • Pydantic schemas
    • Data structures

πŸ” Security ArchitectureΒΆ

Authentication FlowΒΆ

flowchart LR
    User[User] -->|Login| OAuth[OAuth Provider]
    OAuth -->|Token| Backend[Backend API]
    Backend -->|JWT| User
    User -->|JWT in Header| Backend

Supported Methods:

  • OAuth 2.0 (GitHub, Microsoft)
  • Backstage integration
  • Service accounts (API tokens)
  • Guest access (development)

Secrets ManagementΒΆ

  • Encryption at Rest - Integration credentials encrypted using Fernet
  • Environment Variables - Runtime credentials via env vars
  • No Secrets in Logs - Sensitive data masked
  • Audit Trail - All changes logged

πŸ”„ State MachineΒΆ

Resources follow a strict state machine to ensure consistency.

States:

State Meaning
provision Created, not yet provisioned
provisioned Successfully provisioned
destroy Marked for destruction
destroyed Successfully destroyed

Statuses:

Status Meaning
ready Ready for next operation
queued Waiting in execution queue
in_progress Currently executing
done Successfully completed
error Failed with error
approval_pending Awaiting owner approval
pending Waiting for prerequisite
rejected Approval was rejected
unknown Status cannot be determined