# gokitcloud/ginkit architecture

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

- Interactive diagram: https://gitdiagram.com/gokitcloud/ginkit
- Repository: https://github.com/gokitcloud/ginkit

## Overview

##### Main Components

a) Core Framework Layer:
- Gin Integration (base layer)
- Ginkit Core Engine (represented by engine.go)
- Request/Response Handler

b) Authentication & Security Components:
- SAML Authentication (saml.go)
- JWT Authentication (authjwt.go, jwtauth.go)
- OAuth Support (oauth.go)
- Session Management (sessions.go)
- SSL Handling (ssl.go)
- RBAC (Role-Based Access Control) (rbac.go)

c) Template & Static Content:
- Template Engine (template.go, templates.go)
- Static Content Handler (static.go)

d) Utility Components:
- Proxy Handler (proxy.go)
- Metrics Collection (metrics.go)
- Helper Functions (helpers.go)
- Parameter Processing (params.go)

**┌─────────────────────────────────────────────┐**
- Client Layer                  │
- ┘
- ↕
**┌─────────────────────────────────────────────┐**
- SSL Handler                   │
- ┘
- ↕
**┌─────────────────────────────────────────────┐**
- Authentication Layer             │
- ┬─────────────┬────────────────┤
- SAML Auth  │  JWT Auth   │  OAuth         │
- ┴─────────────┴────────────────┘
- ↕
**┌─────────────────────────────────────────────┐**
- Core Engine                   │
- ┬─────────────┬────────────────┤
- Routing   │   RBAC      │    Sessions    │
- ┴─────────────┴────────────────┘
- ↕
**┌─────────────────────────────────────────────┐**
- Processing Layer                 │
- ┬─────────────┬────────────────┤
- Templates  │   Proxy     │    Static      │
- ┴─────────────┴────────────────┘
- ↕
**┌─────────────────────────────────────────────┐**
- Gin Framework                 │
- ┘

##### Important Elements to Highlight

a) Data Flow:
- Request flow from client through the various layers
- Where authentication checks occur
- Template rendering process
- Proxy request handling

b) Integration Points:
- How Ginkit extends Gin's functionality
- Points where custom handlers can be added
- Integration with external auth providers

##### Notes for Implementation

- Keep the main flow clear and centered
- Sample configuration points
- Error handling paths
- Where metrics are collected

Remember to maintain a balance between showing enough detail to understand the system's architecture while keeping it clean and readable. The examples directory structure suggests multiple implementation patterns, so include a small section showing common usage patterns based on the example configurations provided.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CL[Client Layer]
    end

    subgraph Security
        SSL["SSL Handler"]:::security
        click SSL "https://github.com/gokitcloud/ginkit/blob/main/ssl.go"
    end

    subgraph AuthLayer["Authentication Layer"]
        SAML["SAML Auth"]:::auth
        JWT["JWT Auth"]:::auth
        OAuth["OAuth"]:::auth
        BaseAuth["Base Auth"]:::auth
        click SAML "https://github.com/gokitcloud/ginkit/blob/main/saml.go"
        click JWT "https://github.com/gokitcloud/ginkit/blob/main/authjwt.go"
        click OAuth "https://github.com/gokitcloud/ginkit/blob/main/oauth.go"
        click BaseAuth "https://github.com/gokitcloud/ginkit/blob/main/auth.go"
    end

    subgraph CoreEngine["Core Engine Layer"]
        Engine["Ginkit Engine"]:::core
        RBAC["RBAC"]:::core
        Sessions["Sessions"]:::core
        Groups["Groups"]:::core
        click Engine "https://github.com/gokitcloud/ginkit/blob/main/engine.go"
        click RBAC "https://github.com/gokitcloud/ginkit/blob/main/rbac.go"
        click Sessions "https://github.com/gokitcloud/ginkit/blob/main/sessions.go"
        click Groups "https://github.com/gokitcloud/ginkit/blob/main/group.go"
    end

    subgraph Processing["Processing Layer"]
        Templates["Template Engine"]:::processing
        Proxy["Proxy Handler"]:::processing
        Static["Static Content"]:::processing
        Params["Parameter Processing"]:::processing
        click Templates "https://github.com/gokitcloud/ginkit/blob/main/template.go"
        click Proxy "https://github.com/gokitcloud/ginkit/blob/main/proxy.go"
        click Static "https://github.com/gokitcloud/ginkit/blob/main/static.go"
        click Params "https://github.com/gokitcloud/ginkit/blob/main/params.go"
    end

    subgraph Utilities["Utility Layer"]
        Metrics["Metrics Collection"]:::utility
        Helpers["Helper Functions"]:::utility
        click Metrics "https://github.com/gokitcloud/ginkit/blob/main/metrics.go"
        click Helpers "https://github.com/gokitcloud/ginkit/blob/main/helpers.go"
    end

    subgraph Base["Base Framework"]
        Gin["Gin Framework"]:::external
    end

    %% Connections
    CL --> SSL
    SSL --> |Request Flow| AuthLayer
    SAML & JWT & OAuth & BaseAuth --> Engine
    Engine --> RBAC
    Engine --> Sessions
    Engine --> Groups
    RBAC & Sessions & Groups --> Processing
    Templates & Proxy & Static & Params --> Gin
    
    %% Utility Connections
    Metrics -.- AuthLayer
    Metrics -.- CoreEngine
    Metrics -.- Processing
    Helpers -.- AuthLayer
    Helpers -.- CoreEngine
    Helpers -.- Processing

    %% Styles
    classDef security fill:#90EE90,stroke:#333,stroke-width:2px
    classDef auth fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef core fill:#4169E1,stroke:#333,stroke-width:2px,color:#fff
    classDef processing fill:#FFA500,stroke:#333,stroke-width:2px
    classDef utility fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1["Security Component"]:::security
        L2["Authentication Component"]:::auth
        L3["Core Component"]:::core
        L4["Processing Component"]:::processing
        L5["Utility Component"]:::utility
        L6["External Component"]:::external
    end
```
