# edhic1/kernel_ksu_next_lancelot architecture

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

- Interactive diagram: https://gitdiagram.com/edhic1/kernel_ksu_next_lancelot
- Repository: https://github.com/edhic1/kernel_ksu_next_lancelot

## Overview

##### Project Type and Purpose
- Type: Open-source build automation tool (CI/CD pipeline) for compiling and packaging a custom Android kernel (Redmi 9 “lancelot”), integrating KernelSU/SukiSU and multiple patches.
- Purpose: On each push or release, automatically checkout sources, apply patches, configure, compile with custom Clang/GCC, package into AnyKernel3 ZIP and boot image, and upload artifacts to GitHub Releases.

a. GitHub Repository
– Contains:
- .github/workflows/build-kernel.yml (workflow definition)
- config.env (user‐configurable environment settings)
- patches/ (collection of patch files)
- guide/ (documentation and images; optional)
b. GitHub Actions Runner (Hosted VM)
– Stages:
1. Trigger (on push/tag)
2. Checkout kernel source & submodules
3. Load config.env
4. Fetch external toolchains & scripts:
- Custom Clang repo (proton-clang)
- AnyKernel3 repository or zip
- KernelSU source/tag
5. Apply patches (from patches/)
6. Kernel configuration (defconfig + overlayfs, SU options)
7. Compile (clang/gcc toolchain)
8. Package outputs:
- Image.gz-dtb
- AnyKernel3-<build>.zip
9. Upload artifacts & draft GitHub Release
c. External Services
– GitHub Releases API (artifact hosting)
– Telegram community link (support channel)
– External repos:
- Kernel source (configured via KERNEL_SOURCE)
- KernelSU/SukiSU upstream
- AnyKernel3 upstream

##### Architectural Patterns & Principles
- CI/CD Pipeline: well-defined sequential steps
- Declarative configuration: config.env drives behavior; patches folder is an extension point
- Separation of concerns: build definitions (YAML), code (kernel source), config (env), patches

##### Technologies/Frameworks
- GitHub Actions (workflow engine)
- Bash/shell scripts inside build-kernel.yml
- Clang/GCC cross-compiler toolchains
- Git (source management)
- AnyKernel3 (packager for recovery flashable ZIP)

##### Essential Elements
- Labels: e.g., “.github/workflows/build-kernel.yml,” “config.env,” “patches/”
- Annotations for conditional or configurable steps (e.g., “if ENABLE_KERNELSU=true”)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer Trigger
    Dev["Developer"]:::external
    Dev -->|"push/tag"| Trigger

    %% Build Pipeline
    subgraph "Build Pipeline"
        direction TB
        Trigger["Trigger (on push/tag)"]:::ci
        Checkout["Checkout Source & Submodules"]:::ci
        LoadEnv["Load config.env"]:::ci
        FetchTools["Fetch Toolchains & Scripts"]:::ci
        ApplyPatches["Apply Patches (from patches/)"]:::ci
        Configure["Kernel Configuration"]:::ci
        Compile["Compile (Clang/GCC)"]:::ci
        Package["Package Outputs"]:::ci
        Upload["Upload Artifacts & Draft Release"]:::ci

        Trigger --> Checkout
        Checkout --> LoadEnv
        LoadEnv --> FetchTools
        FetchTools --> ApplyPatches
        ApplyPatches --> Configure
        Configure --> Compile
        Compile --> Package
        Package --> Upload
    end

    %% Repository Components
    subgraph "GitHub Repository"
        direction TB
        RepoRoot["README.md"]:::code
        Workflow[".github/workflows/build-kernel.yml"]:::code
        Env["config.env"]:::code
        PatchesDir["patches/"]:::code
        GuideDir["guide/"]:::code
        GuideImages["guide/images/"]:::code

        RepoRoot --> Workflow
        RepoRoot --> Env
        RepoRoot --> PatchesDir
        RepoRoot --> GuideDir
        GuideDir --> GuideImages
    end

    %% External Dependencies
    subgraph "External Services & Repos"
        direction TB
        GHReleases["GitHub Releases API"]:::external
        Telegram["Telegram Community"]:::external
        KernelSrc["Kernel Source Repo"]:::external
        KernelSU["KernelSU/SukiSU Repo"]:::external
        AnyKernel["AnyKernel3 Repo/Zip"]:::external
        ClangRepo["proton-clang Repo"]:::external

        FetchTools --> KernelSrc
        FetchTools --> KernelSU
        FetchTools --> AnyKernel
        FetchTools --> ClangRepo
        Upload --> GHReleases
    end

    %% User Flash Flow
    User["User/Recovery or Fastboot"]:::external
    User -->|"download artifacts"| GHReleases
    User -->|"flash device"| Package

    %% Connections between Repo and Pipeline
    Workflow --> Trigger
    Env --> LoadEnv
    PatchesDir --> ApplyPatches

    %% Click Events
    click Workflow "https://github.com/edhic1/kernel_ksu_next_lancelot/blob/main/.github/workflows/build-kernel.yml"
    click RepoRoot "https://github.com/edhic1/kernel_ksu_next_lancelot/blob/main/README.md"
    click Env "https://github.com/edhic1/kernel_ksu_next_lancelot/blob/main/config.env"
    click PatchesDir "https://github.com/edhic1/kernel_ksu_next_lancelot/tree/main/patches/"
    click GuideDir "https://github.com/edhic1/kernel_ksu_next_lancelot/tree/main/guide/"
    click GuideImages "https://github.com/edhic1/kernel_ksu_next_lancelot/tree/main/guide/images/"

    %% Example patch files
    click FIX_APATCH "https://github.com/edhic1/kernel_ksu_next_lancelot/blob/main/patches/FIX_APATCH_OPENELA.patch"
    click KSU_HOOKS "https://github.com/edhic1/kernel_ksu_next_lancelot/blob/main/patches/KSU_HOOKS_PATCH.patch"
    click KSU_REVERT "https://github.com/edhic1/kernel_ksu_next_lancelot/blob/main/patches/KSU_REVERT.patch"
    click OLD_ANDROID "https://github.com/edhic1/kernel_ksu_next_lancelot/blob/main/patches/OLD_ANDROID_SUPPORT.patch"
    click REVERT_ADD_CRED "https://github.com/edhic1/kernel_ksu_next_lancelot/blob/main/patches/REVERT_ADD_GET_CRED_RCU.patch"
    click SUSFS "https://github.com/edhic1/kernel_ksu_next_lancelot/blob/main/patches/SUSFS.patch"

    %% Styles
    classDef code fill:#E0F7FA,stroke:#0288D1,color:#01579B;
    classDef ci fill:#C8E6C9,stroke:#2E7D32,color:#1B5E20;
    classDef external fill:#FFE0B2,stroke:#EF6C00,color:#E65100;
```
