# tencentblueking/bk-audit architecture

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

- Interactive diagram: https://gitdiagram.com/tencentblueking/bk-audit
- Repository: https://github.com/tencentblueking/bk-audit

## Overview

##### Main Components
- Frontend Application – Represented by the src/frontend directory. Note that it includes a complete Vue.js SPA (with components, views, router, hooks, etc.), static assets, and build configurations (Dockerfile, package.json).
- Backend Application – Housed in the src/backend directory. This is a Django application that is divided into various submodules:
– API Layer: Under “src/backend/api”, there are multiple API endpoints (for audit, bk_iam, bk_log, bk_monitor, etc.) that interface with different system functions.
– Modular Apps: The “src/backend/apps” directory contains many domain-specific modules (audit, feature, itsm, meta, notice, permission, sops, user_manage, etc.). Each module encapsulates business logic for its respective area.
– Core Components & Utilities: Located in “src/backend/core” and “src/backend/config”, these handle caching, logging, middleware, SQL building, utilities, and environment configurations.
– Third-Party Integrations: The “src/backend/blueking” directory shows integration with BlueKing specific functionality like components and API calls.
- Infrastructure & Deployment: Dockerfiles for both backend and frontend are provided along with configuration files like .djangoignore, .flake8, and CI/CD workflows (under .github/workflows), indicating containerized deployment and automated tests.
- Data Stores and External Systems (Implicit): Although not directly visible in the file tree, components for caching (in “core/cache”), logging, message queuing (e.g., Kafka in “src/backend/core/kafka”), and integrations with BlueKing IAM and other systems suggest connections to databases, Redis/Memcache, message brokers, etc.

##### Relationships and Interactions
- Modular Backend Interactions: Within the backend layer, illustrate how the API endpoints interact with specific apps (audit, permission, meta, etc.). Show how the “core” utilities (logging, cache, middleware) are used by these modules.
- Services Communication: Show how the separate “services” (puller, web) interact with the core backend and database components. For instance, the puller service might fetch or process audit logs, while the web service likely handles user-facing audit visualizations and results.

##### Architectural Patterns and Design Principles
- Layered Architecture: Clearly differentiate between the client layer (frontend), application layer (backend APIs, modular applications, and services), and infrastructure/data stores.
- Modularization: Highlight that the backend is highly modular (with separate apps for different domains such as audit, permission, meta, and notice) and may follow principles akin to a microservices/microkernel architecture even though it may be deployed as a monolithic Django app.
- Extensibility and Integration: The system is designed to integrate with other BlueKing projects (e.g., BK-CMDB, BK-CI, BK-PaaS) so mark clear extension points and integration channels.

##### Technologies and Frameworks
- Backend: Django (Python), with Docker-based deployment, use of middleware, custom SQL builders, and other utility libraries present in “core” and “config”.
- Frontend: Likely a Vue.js SPA (using .vue files, TypeScript, ESLint, and Vite for bundling) with modern JavaScript tooling.
- DevOps: CI/CD is managed with GitHub Actions workflows, and the project includes pre-commit hooks and configuration files for linting and style guidelines.
- External: Although not explicitly listed in the file tree, integration with Kafka, Redis, and BlueKing microservices are inferred from the folder names and external documentation links.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    U["User (Browser)"]:::user

    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Frontend (Vue.js SPA)"]:::frontend
        FE_Docker["Dockerfile (Frontend)"]:::deployment
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE["Backend (Django)"]:::backend
        API["API Layer (Endpoints)"]:::backend
        APPS["Modular Apps"]:::backend
        CORE["Core Components & Utilities"]:::backend
        CONFIG["Environment & Configuration"]:::backend
        BLUEKING["Third-Party Integrations"]:::integration

        subgraph "Services"
            PULLER["Puller Service"]:::service
            WEBSERVICE["Web Service"]:::service
        end

        BE_Docker["Dockerfile (Backend)"]:::deployment
        CICD["CI/CD Workflows"]:::deployment
    end

    %% External Systems
    subgraph "External Systems"
        BK_IAM["BlueKing IAM"]:::external
        DB["Database"]:::external
        KAFKA["Message Broker (Kafka/Redis)"]:::external
    end

    %% Connections
    U -->|"uses"| FE
    FE -->|"calls"| API
    API -->|"delegates"| APPS
    APPS -->|"utilizes"| CORE
    APPS -->|"reads"| CONFIG
    API -->|"integrates"| BLUEKING
    WEBSERVICE -->|"handles"| API
    PULLER -->|"processes_logs"| DB
    APPS -->|"updates"| DB
    API -->|"publishes"| KAFKA
    FE -->|"authenticates"| BK_IAM
    BLUEKING -->|"interfaces_with"| BK_IAM

    %% Deployment links (dashed)
    FE --- FE_Docker
    BE --- BE_Docker
    CICD --- FE_Docker
    CICD --- BE_Docker

    %% Class Definitions
    classDef frontend fill:#a0d8f1,stroke:#036,stroke-width:2px;
    classDef backend fill:#f1a0a0,stroke:#c00,stroke-width:2px;
    classDef service fill:#a0f1a0,stroke:#0c0,stroke-width:2px;
    classDef integration fill:#f1d8a0,stroke:#cc0,stroke-width:2px;
    classDef deployment fill:#d8a0f1,stroke:#60f,stroke-width:2px;
    classDef external fill:#f1f1a0,stroke:#cc0,stroke-width:2px;
    classDef user fill:#a0f1f1,stroke:#0cc,stroke-width:2px;

    %% Click Events
    click FE "https://github.com/tencentblueking/bk-audit/tree/main/src/frontend"
    click BE "https://github.com/tencentblueking/bk-audit/tree/main/src/backend"
    click API "https://github.com/tencentblueking/bk-audit/tree/main/src/backend/api"
    click APPS "https://github.com/tencentblueking/bk-audit/tree/main/src/backend/apps"
    click CORE "https://github.com/tencentblueking/bk-audit/tree/main/src/backend/core"
    click CONFIG "https://github.com/tencentblueking/bk-audit/tree/main/src/backend/config"
    click BLUEKING "https://github.com/tencentblueking/bk-audit/tree/main/src/backend/blueking"
    click PULLER "https://github.com/tencentblueking/bk-audit/tree/main/src/backend/services/puller"
    click WEBSERVICE "https://github.com/tencentblueking/bk-audit/tree/main/src/backend/services/web"
    click FE_Docker "https://github.com/tencentblueking/bk-audit/tree/main/src/frontend/Dockerfile"
    click BE_Docker "https://github.com/tencentblueking/bk-audit/tree/main/src/backend/Dockerfile"
    click CICD "https://github.com/tencentblueking/bk-audit/tree/main/.github/workflows"
```
