# lezli01/casbin-cpp architecture

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

- Interactive diagram: https://gitdiagram.com/lezli01/casbin-cpp
- Repository: https://github.com/lezli01/casbin-cpp

## Overview

##### Main Components Identification

The system should be represented with these key components:

a) Core Components:
- Enforcer (Central component)
- Model Management
- Policy Management
- RBAC (Role-Based Access Control)
- ABAC (Attribute-Based Access Control)
- Effect System
- Matcher System

b) Supporting Components:
- Persistence Layer
- Watcher System
- Logger System
- IP Parser
- Configuration Management

##### Component Relationships

**[Client Application]**
- ↓
**[Enforcer Interface]**
- ↓
- [Enforcer] ←→ [Model Management]
- ↓              ↑
**[Policy Management] ←→ [Persistence Layer]**
- ↓
**[RBAC/ABAC Systems] ←→ [Role Manager]**
- ↓
**[Effect System] ←→ [Matcher System]**

##### Detailed Component Breakdown

For each major component, show its internal structure:

a) Enforcer:
**[Enforcer]**
- Basic Enforcer
- Cached Enforcer
- Synced Enforcer

b) Model Management:
**[Model Management]**
- Model Definition
- Policy Definition
- Request Definition
- Matchers

c) Persistence Layer:
**[Persistence]**
- File Adapter
- Filtered Adapter
- Batch Adapter

##### Integration Points

External integration points:
- Python Bindings
- File System Interface
- Watcher Interface
- Logger Interface

##### Data Flow

- Authorization Requests
- Policy Updates
- Cache Operations
- Watcher Notifications

##### Notes

Annotations for:
- Configuration Requirements
- Policy File Formats
- Model File Structure
- Supported Access Control Types

- The modular nature of the system
- Clear separation of concerns
- Plugin architecture for adapters
- Support for multiple access control models

Keep the abstraction level high enough to be understandable but detailed enough to show the sophisticated nature of the authorization system. Focus on showing how the different components work together to provide flexible access control policies.

This system design should reflect Casbin-CPP's ability to handle multiple access control models (ACL, RBAC, ABAC) and its extensible nature through adapters and watchers.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Application"]
        CI[Client Interface]
    end

    subgraph Core["Core Components"]
        EN["Enforcer"]:::core
        BE["Basic Enforcer"]:::core
        CE["Cached Enforcer"]:::core
        SE["Synced Enforcer"]:::core
        
        MM["Model Management"]:::core
        MD["Model Definition"]:::core
        PD["Policy Definition"]:::core
        RD["Request Definition"]:::core
        MT["Matchers"]:::core
        
        PM["Policy Management"]:::core
        
        RBAC["RBAC System"]:::core
        RM["Role Manager"]:::core
        
        ABAC["ABAC System"]:::core
        
        ES["Effect System"]:::core
        MS["Matcher System"]:::core
    end

    subgraph Support["Supporting Systems"]
        PL["Persistence Layer"]:::storage
        FA["File Adapter"]:::storage
        FIA["Filtered Adapter"]:::storage
        BA["Batch Adapter"]:::storage
        
        WS["Watcher System"]:::utility
        LS["Logger System"]:::utility
        IP["IP Parser"]:::utility
        CM["Config Management"]:::utility
    end

    %% Relationships
    CI --> EN
    EN --> BE & CE & SE
    EN <--> MM
    MM --> MD & PD & RD & MT
    EN --> PM
    PM <--> PL
    PM --> RBAC & ABAC
    RBAC <--> RM
    EN --> ES
    ES <--> MS
    
    PL --> FA & FIA & BA
    
    %% Click events
    click EN "https://github.com/lezli01/casbin-cpp/blob/master/casbin/enforcer.h"
    click CE "https://github.com/lezli01/casbin-cpp/blob/master/casbin/enforcer_cached.h"
    click SE "https://github.com/lezli01/casbin-cpp/blob/master/casbin/enforcer_synced.h"
    click MM "https://github.com/lezli01/casbin-cpp/blob/master/casbin/model/model.h"
    click RBAC "https://github.com/lezli01/casbin-cpp/blob/master/casbin/rbac/rbac.h"
    click RM "https://github.com/lezli01/casbin-cpp/blob/master/casbin/rbac/role_manager.h"
    click ABAC "https://github.com/lezli01/casbin-cpp/blob/master/casbin/abac_data.h"
    click ES "https://github.com/lezli01/casbin-cpp/blob/master/casbin/effect/effect.h"
    click PL "https://github.com/lezli01/casbin-cpp/blob/master/casbin/persist/adapter.h"
    click FA "https://github.com/lezli01/casbin-cpp/blob/master/casbin/persist/file_adapter/file_adapter.h"
    click FIA "https://github.com/lezli01/casbin-cpp/blob/master/casbin/persist/filtered_adapter.h"
    click BA "https://github.com/lezli01/casbin-cpp/blob/master/casbin/persist/batch_adapter.h"
    click WS "https://github.com/lezli01/casbin-cpp/blob/master/casbin/persist/watcher.h"
    click LS "https://github.com/lezli01/casbin-cpp/blob/master/casbin/log/Logger.h"
    click IP "https://github.com/lezli01/casbin-cpp/blob/master/casbin/ip_parser/parser/IP.h"
    click CM "https://github.com/lezli01/casbin-cpp/blob/master/casbin/config/config.h"

    %% Styles
    classDef core fill:#2374ab
    classDef storage fill:#ff7f50
    classDef utility fill:#95a5a6
    classDef external fill:#f1c40f

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Storage Components]:::storage
        L3[Utility Components]:::utility
        L4[External Systems]:::external
    end
```
