---
# System prepended metadata

title: System Context Access Management (Phase 4)

---

# System Context Access Management (Phase 4)

## Architecture Diagram

```plantuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Component.puml

title System Context Access Management - Architecture Diagram

Person(brand_admin, "Brand Admin")

System_Boundary(brand_web_system, "Brand Administration Web Application") {
    Container(brand_web, "Browser", "Software System", "All supported browser")
    Container(brand_app, "Brand Administration Web Application", "Nuxt.js", "Provides brand management functionalities to brand admin via their web browser")
}

System_Boundary(brand_mobile_system, "Brand Administration Mobile Application") {
    Container(brand_mobile, "Mobile Device", "Mobile System", "All supported mobile devices")
    Container(partner_app, "Brand Administration Mobile Application", "Flutter", "Provides brand management functionalities to brand admin via their web mobile app")
}

System_Boundary(api_endpoint, "API Endpoint") {
    Container(evm_scam, "evm-scam API", "Go", "Provides config management functionalities via HTTPS / REST / JSON API")
    Container(evm_brand, "evm-brand API", "Go", "Provides brand management functionalities via HTTPS / REST / JSON API")
}
System_Boundary(db, "Evermos Database") {
    ContainerDb(db_scam, "Database", "MySQL", "evm_scam schema")
}

Lay_L(brand_web_system, brand_mobile_system)

Rel(brand_admin, brand_web, "View dashboard", "Client Device")
Rel(brand_web, brand_app, "Access", "HTTPS")
Rel(brand_app, evm_brand, "Makes API calls to", "HTTPS / REST / JSON")
Rel(brand_app, evm_scam, "Makes API calls to", "HTTPS / REST / JSON")
Rel(brand_admin, brand_mobile, "View dashboard")
Rel(brand_mobile, partner_app, "Access", "HTTPS")
Rel(partner_app, evm_brand, "Makes API calls to", "HTTPS / REST / JSON")
Rel(partner_app, evm_scam, "Makes API calls to", "HTTPS / REST / JSON")
Rel_R(evm_brand, evm_scam, "Makes API calls to", "HTTPS / REST / JSON")
Rel(evm_scam, db_scam, "Reads from & Writes to", "TCP/IP")
```

## Architecture Diagram

```plantuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Component.puml

title Admin Dashboard - Architecture Diagram

Person(admin, "Admin")
System_Boundary(admin_web_system, "Evermos Administration Web Application") {
    Container(brand_web, "Browser", "Software System", "All supported browser")
    Container(admin_web_app, "Admin Dashboard", "Nuxt.js", "Provides management functionalities to admin via their web browser")
}
System_Boundary(api_endpoint, "API Endpoint") {
    Container(admin_api, "evermos-admin-be API", "PHP", "Provides admin management functionalities via HTTPS / REST / JSON API")

}
ContainerDb(db_evm, "Database", "MySQL", "evm schema")

Rel_R(admin, brand_web, "Register Brand", "Client Device")
Rel_R(brand_web, admin_web_app, "Access", "HTTPS")
Rel_R(admin_web_app, admin_api, "Makes API calls to", "HTTPS / REST / JSON")
Rel_R(admin_api, db_evm, "Reads from & Writes to", "TCP/IP")
```


## EVM Database Design - Existing System

```plantuml
hide circle
'skinparam linetype ortho

skinparam class {
    ArrowColor #FF7878
    BackgroundColor #FFF89A
    BorderColor #694E4E
}

title EVM Database Schema

entity "[evm] menu" as m {
    *id: bigint(20)
    --
    parentMenuId: bigint(20) <<FK>>
    slug: varchar(200)
    icon: varchar(250)
    url: text
    label: varchar(200)
    order: int(11)
    isVisible: smallint(6)   
    createdTime: datetime
    createdBy: bigint(20)
    updatedTime: datetime
    updatedBy: bigint(20)
    isActive: tinyint(1)
    isRemoved: tinyint(1)
    removedTime: datetime
    removedBy: bigint(20)
}

entity "[evm] menu_function" as mf {
    *id: bigint(20)
    --
    menuId: bigint(20) <<FK>>
    name: varchar(255)
    group: int(11)
    createdTime: datetime
    createdBy: bigint(20)
    updatedTime: datetime
    updatedBy: bigint(20)
    isActive: tinyint(1)
    isRemoved: tinyint(1)
    removedTime: datetime
    removedBy: bigint(20)
}

entity "[evm] role" as r {
    *id: bigint(20)
    --
    parentRoleId: bigint(20) <<FK>>
    name: text
    isParent: smallint(6)
    order: smallint(6)
    createdTime: datetime
    createdBy: bigint(20)
    updatedTime: datetime
    updatedBy: bigint(20)
    isActive: tinyint(1)
    isRemoved: tinyint(1)
    removedTime: datetime
    removedBy: bigint(20)
}

entity "[evm] role_menu" as rm {
    *id: bigint(20)
    --
    roleId: bigint(20) <<FK>>
    menuId: bigint(20) <<FK>>
    order: smallint(6)
    createdTime: datetime
    createdBy: bigint(20)
    updatedTime: datetime
    updatedBy: bigint(20)
    isActive: tinyint(1)
    isRemoved: tinyint(1)
    removedTime: datetime
    removedBy: bigint(20)
}
  
entity "[evm] user" as u {
    *id: bigint(20)
    --
    userType: int(11)
    userLevel: int(11)
    membershipStatus: tinyint(1)
    username: varchar(254)
    storeName: text
    uniqueId: varchar(10)
    name: varchar(100)
    .
    <<other fields>>
    .
    createdTime: datetime
    createdBy: bigint(20)
    updatedTime: datetime
    updatedBy: bigint(20)
    isActive: tinyint(1)
    isSuspended: int(1)
    isRemoved: tinyint(1)
    removedTime: datetime
    removedBy: bigint(20)
}

entity "[evm] user_role" as ur {
     *id: bigint(20)
    --
    roleId: bigint(20) <<FK>>
    userId: bigint(20) <<FK>>
    createdTime: datetime
    createdBy: bigint(20)
    updatedTime: datetime
    updatedBy: bigint(20)
    isActive: tinyint(1)
    isRemoved: tinyint(1)
    removedTime: datetime
    removedBy: bigint(20)
}

entity "[evm] user_function" as uf {
    *id: bigint(20)
    --
    userId: bigint(20) <<FK>>
    functionId: bigint(20) <<FK>>
    createdTime: datetime
    createdBy: bigint(20)
    updatedTime: datetime
    updatedBy: bigint(20)
    isActive: tinyint(1)
    isRemoved: tinyint(1)
    removedTime: datetime
    removedBy: bigint(20)
}

r||--|{ r
m||--|{ m
m ||--|{ mf
mf ||--|{ uf
r ||--|{ rm
m ||--|{ rm
u ||-left|{ ur
u ||--|{ uf
r ||--|{ ur


```

## EVM-SCAM Database Design - Existing System


```plantuml
hide circle
'skinparam linetype ortho

skinparam class {
    ArrowColor #FF7878
    BackgroundColor #FFF89A
    BorderColor #694E4E
}

title EVM-SCAM Phase 3 - Database Schema


package "C4 Level 1" <<Rectangle>> {
    entity "[evm_scam] app_system_context" as asc {
        *entity_id : char(36)
        --
        sys_ctx_code : varchar(50) <<unique>>
        sys_ctx_name : varchar(255)
        sys_ctx_description : text
        is_active : boolean
        created_at : varchar(36)
        created_by : timestamp
        updated_at : varchar(36)
        updated_by : timestamp
        is_deleted : boolean
        deleted_at : varchar(36)
        deleted_by : timestamp
    }
}

entity "[evm_scam] app_system_context_container" as ascc {
    *entity_id : char(36)
    --
    *container_id : char(36) <<FK>>
    *sys_ctx_id : char(36) <<FK>>
    is_active : boolean
    created_at : varchar(36)
    created_by : timestamp
    updated_at : varchar(36)
    updated_by : timestamp
    is_deleted : boolean
    deleted_at : varchar(36)
    deleted_by : timestamp
}

package "C4 Level 2" <<Rectangle>> {
    entity "[evm_scam] app_container" as ac {
        *entity_id : char(36)
        --
        *sys_ctx_id : char(36) <<FK>> (default\nsystem context)
        container_type : enum(web,mobile,api)
        container_code : varchar(50) <<unique>>
        container_name : varchar(255)
        container_description : text
        container_tech : varchar(50)
        repository_url : varchar(255)
        internal_url : varchar(255)
        is_active : boolean
        created_at : varchar(36)
        created_by : timestamp
        updated_at : varchar(36)
        updated_by : timestamp
        is_deleted : boolean
        deleted_at : varchar(36)
        deleted_by : timestamp
    }
}

entity "[evm-scam] acm_role" as ar {
    *entity_id : char(36)
    --
    parent_id: char(36) <<FK>>
    sys_ctx_id: char(36) <<FK>>
    code: varchar(50)
    name: varchar(255)
    description: text
    is_active: boolean
    created_at: varchar(36)
    created_by: timestamp
    updated_at: varchar(36)
    updated_by: timestamp
    is_deleted: boolean
    deleted_at: varchar(36)
    deleted_by: timestamp
}

entity "[evm-scam] acm_user_role" as aur {
    *entity_id : char(36)
    --
    role_id: char(36) <<FK>>
    user_id: char(36)
    channel: text
    is_active: boolean
    created_at: varchar(36)
    created_by: timestamp
    updated_at: varchar(36)
    updated_by: timestamp
    is_deleted: boolean
    deleted_at: varchar(36)
    deleted_by: timestamp
}


entity "[evm-scam] acm_role_menu" as arm {
    *entity_id : char(36)
    --
    role_id: char(36) <<FK>>
    menu_id: char(36) <<FK>>
    is_active: boolean
    created_at: varchar(36)
    created_by: timestamp
    updated_at: varchar(36)
    updated_by: timestamp
    is_deleted: boolean
    deleted_at: varchar(36)
    deleted_by: timestamp
}

entity "[evm_scam] app_container_ui_menu" as acum {
    *entity_id : char(36) <<generated>>
    --
    *parent_menu_id : char(36) <<FK>>
    *container_id : char(36) <<FK>>
    *tenant_id : char(36) <<FK>>
    *area_id : char(36) <<FK>>
    *default_layout_id : char(36) <<FK>>
    *menu_position_id : char(36) <<FK>>
    code : varchar(50)
    version : varchar(20)
    name : varchar(255)
    path : varchar(255)
    order_idx : varchar(255)
    description : varchar(255)
    restriction : enum(public, private)
    has_icon : boolean
    icon_type : varchar(100)
	icon : varchar(100)
    level : varchar(20)
	additional_setting : JSON
    checksum_point : varchar(255)
    is_active : boolean
    created_at : varchar(36)
    created_by : timestamp
    updated_at : varchar(36)
    updated_by : timestamp
    is_deleted : boolean
    deleted_at : varchar(36)
    deleted_by : timestamp
}

acum ||--|{ acum
ar ||--|{ ar
asc ||--|{ ar
asc ||-down-|{ ac
asc||--left|{ascc
ac||-left|{ascc
ar ||-left|{ aur
ar ||-right|{ arm
acum ||-left|{ arm
```



## EVM-SCAM Database Design - Proposed Solution


```plantuml
hide circle
'skinparam linetype ortho

skinparam class {
    ArrowColor #FF7878
    BackgroundColor #FFF89A
    BorderColor #694E4E
}

title EVM-SCAM Phase 4 - Database Schema


package "C4 Level 1" <<Rectangle>> {
    entity "[evm_scam] app_system_context" as asc {
        *entity_id : char(36)
        --
        sys_ctx_code : varchar(50) <<unique>>
        sys_ctx_name : varchar(255)
        sys_ctx_description : text
        is_active : boolean
        created_at : varchar(36)
        created_by : timestamp
        updated_at : varchar(36)
        updated_by : timestamp
        is_deleted : boolean
        deleted_at : varchar(36)
        deleted_by : timestamp
    }
}

entity "[evm_scam] app_system_context_container" as ascc {
    *entity_id : char(36)
    --
    *container_id : char(36) <<FK>>
    *sys_ctx_id : char(36) <<FK>>
    is_active : boolean
    created_at : varchar(36)
    created_by : timestamp
    updated_at : varchar(36)
    updated_by : timestamp
    is_deleted : boolean
    deleted_at : varchar(36)
    deleted_by : timestamp
}

package "C4 Level 2" <<Rectangle>> {
    entity "[evm_scam] app_container" as ac {
        *entity_id : char(36)
        --
        *sys_ctx_id : char(36) <<FK>> (default\nsystem context)
        container_type : enum(web,mobile,api)
        container_code : varchar(50) <<unique>>
        container_name : varchar(255)
        container_description : text
        container_tech : varchar(50)
        repository_url : varchar(255)
        internal_url : varchar(255)
        is_active : boolean
        created_at : varchar(36)
        created_by : timestamp
        updated_at : varchar(36)
        updated_by : timestamp
        is_deleted : boolean
        deleted_at : varchar(36)
        deleted_by : timestamp
    }
}

entity "[evm-scam] acm_role" as ar {
    *entity_id : char(36)
    --
    parent_id: char(36) <<FK>>
    sys_ctx_id: char(36) <<FK>>
    code: varchar(50)
    name: varchar(255)
    description: text
    is_active: boolean
    created_at: varchar(36)
    created_by: timestamp
    updated_at: varchar(36)
    updated_by: timestamp
    is_deleted: boolean
    deleted_at: varchar(36)
    deleted_by: timestamp
}

entity "[evm-scam] acm_user_role" as aur {
    *entity_id : char(36)
    --
    role_id: char(36) <<FK>>
    user_id: char(36)
    channel: text
    is_active: boolean
    created_at: varchar(36)
    created_by: timestamp
    updated_at: varchar(36)
    updated_by: timestamp
    is_deleted: boolean
    deleted_at: varchar(36)
    deleted_by: timestamp
}


entity "[evm-scam] acm_role_menu" as arm {
    *entity_id : char(36)
    --
    role_id: char(36) <<FK>>
    menu_id: char(36) <<FK>>
    is_active: boolean
    created_at: varchar(36)
    created_by: timestamp
    updated_at: varchar(36)
    updated_by: timestamp
    is_deleted: boolean
    deleted_at: varchar(36)
    deleted_by: timestamp
}

entity "[evm_scam] app_container_ui_menu" as acum {
    *entity_id : char(36) <<generated>>
    --
    *parent_menu_id : char(36) <<FK>>
    *container_id : char(36) <<FK>>
    *tenant_id : char(36) <<FK>>
    *area_id : char(36) <<FK>>
    *default_layout_id : char(36) <<FK>>
    *menu_position_id : char(36) <<FK>>
    code : varchar(50)
    version : varchar(20)
    name : varchar(255)
    path : varchar(255)
    order_idx : varchar(255)
    description : varchar(255)
    restriction : enum(public, private)
    has_icon : boolean
    icon_type : varchar(100)
	icon : varchar(100)
    level : varchar(20)
	additional_setting : JSON
    checksum_point : varchar(255)
    is_active : boolean
    created_at : varchar(36)
    created_by : timestamp
    updated_at : varchar(36)
    updated_by : timestamp
    is_deleted : boolean
    deleted_at : varchar(36)
    deleted_by : timestamp
}

package "C4 Level 3" <<Rectangle>> {
    entity "[evm_scam] app_container_component" as acc {
        *entity_id : char(36)
        --
        *container_id : char(36) <<FK>>
        *component_parent_id : char(36) <<FK>>
        code : varchar(50) <<unique>>
        name : varchar(255)
        description : text
        is_active : boolean
        created_at : varchar(36)
        created_by : timestamp
        updated_at : varchar(36)
        updated_by : timestamp
        is_deleted : boolean
        deleted_at : varchar(36)
        deleted_by : timestamp
    }
}

package "C4 Level 4" <<Rectangle>> {
    entity "[evm_scam] app_container_component_item" as acci {
        *entity_id : char(36)
        --
        *component_id : char(36) <<FK>>
        *operation_type_id : char(36) <<FK>>
        *privilege_access_type_id : char(36) <<FK>>
        code : varchar(50) <<unique>>
        name : varchar(255)
        identifier : varchar(255)
        description : text
        is_active : boolean
        created_at : varchar(36)
        created_by : timestamp
        updated_at : varchar(36)
        updated_by : timestamp
        is_deleted : boolean
        deleted_at : varchar(36)
        deleted_by : timestamp
    }
}

entity "[evm-scam] acm_privilege_access_type" as apat {
    *entity_id : char(36)
    --
    code : varchar(50) <<unique>>
    name : varchar(255)
    description : text
    is_active: boolean
    created_at: varchar(36)
    created_by: timestamp
    updated_at: varchar(36)
    updated_by: timestamp
    is_deleted: boolean
    deleted_at: varchar(36)
    deleted_by: timestamp
}

entity "[evm-scam] acm_operation_type" as aot {
    *entity_id : char(36)
    --
    code : varchar(50) <<unique>>
    name : varchar(255)
    description : text
    is_active: boolean
    created_at: varchar(36)
    created_by: timestamp
    updated_at: varchar(36)
    updated_by: timestamp
    is_deleted: boolean
    deleted_at: varchar(36)
    deleted_by: timestamp
}

entity "[evm-scam] casbin_rule" as acp {
    *id : int(10)
    --
    p_type: varchar(32)
    v0: varchar(255)
    v1: varchar(255)
    v2: varchar(255)
    v3: varchar(255)
    v4: varchar(255)
    v5: varchar(255)
}

acum ||--|{ acum
ar ||--|{ ar
asc ||--|{ ar
asc ||-down-|{ ac
asc||--left|{ascc
ac||-left|{ascc
ar ||-left|{ aur
ar ||-right|{ arm
acum ||-left|{ arm
acc ||--|{ acc
ac ||-down-|{ acc
acc ||-down-|{ acci
apat ||-up-|{ acci
aot ||-up-|{ acci
ar ||-down-|{ acp
acci ||-left-|{ acp
```

### Get User Permission

```plantuml
skinparam responseMessageBelowArrow true

title Get User Permission - Proposed Interaction Diagram

participant "client" as c
participant "evm-scam" as es
participant "evm-auth" as ea
database "redis" as r
database "evm_scam" as s

c -> es : get user permission
activate es

es -> ea : check client\nauthorization
activate ea

alt if client unauthorized
    ea -> es : error unauthorized
    es -> c : error unauthorized
end

return client detail


es -> s : get user role
activate s

return user role data

es -> r : get data from redis
activate r

alt if data found
    return user permission list

    es -> c : user permission list
end

es -> s : get user permission
activate s

alt if data not found
    return error data not found

    es -> c : error data not found
end

es -> s : get user permission
activate s

return user permission list
return user permission list
```
