---
# System prepended metadata

title: Untitled

---

## Architecture Diagram

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

title Transaction Notifications - Architecture Diagram

Person(brand_admin, "Brand / Stockiest 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", "Software System", "All supported device")
    Container(brand_mobile_app, "Brand Administration Mobile Application", "Flutter", "Provides brand management functionalities to brand admin via their mobile application")
}

System_Boundary(api_endpoint, "API Endpoint") {
    Container(evm_brand, "evm-brand API", "Golang", "Provides brand management functionalities via HTTPS / REST / JSON API")
    Container(evm_disbursement, "evm-disbursement API", "Golang", "Provides notifications functionalities via HTTPS / REST / JSON API")
    Container(external_flip_service, "external-flip-service API", "", "Provides notifications functionalities via HTTPS / REST / JSON API")
}

ContainerDb(db_evm, "Database", "MySQL", "evm schema")
ContainerDb(db_evm_disbursement, "Database", "MySQL", "evm_disbursement schema")

Rel(brand_admin, brand_web, "Withdraw Balance", "Client Device")
Rel(brand_admin, brand_mobile, "Withdraw Balance", "Client Device")
Rel_R(brand_web, brand_app, "Access", "HTTPS")
Rel_L(brand_mobile, brand_mobile_app, "Access", "HTTPS")

Rel(brand_app, evm_brand, "Makes API calls to", "HTTPS / REST / JSON")
Rel(brand_mobile_app, evm_brand, "Makes API calls to", "HTTPS / REST / JSON")

Rel_R(evm_brand, evm_disbursement, "Makes API calls to", "HTTPS / REST / JSON")
Rel(evm_brand, db_evm,  "Reads from & Writes to", "TCP/IP")
Rel(evm_disbursement, db_evm_disbursement, "Reads from & Writes to", "TCP/IP")
Rel_R(evm_disbursement, external_flip_service,"Makes API calls to", "HTTPS / REST / JSON")
```

## Database Design

```plantuml
hide circle
'skinparam linetype ortho

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

title Database Schema

entity "[evm] brand" as b {
    *id: bigint(20)
    --
    brandParentId: bigint(20) <<FK>>
    warehouseShelfId: bigint(20) <<FK>>
    warehouseZoneId: bigint(20) <<FK>>
    partnershipId: bigint(20) <<FK>>
    code: varchar(20)
    slug: text
    name: varchar(100)
    type: enum
    logoUrl: text
    coverImageUrl: text
    commissionPercentage: float
    commissionPrice: float
    vendorCommissionPercentage: float
    vendorCommissionPrice: float
    courierFee: bigint(20)
    picName: varchar(255)
    picPhone: varchar(255)
    picAddress: varchar(255)
    stockLocation: int(11)
    ...
    createdTime: datetime
    updatedTime: datetime
    updatedBy: bigint(20)
    isActive: boolean
    isRemoved: boolean
}


entity "[evm] brand_bank" as b_bank {
    *id: bigint(20)
    --
    brandId: bigint(20) <<FK>>
    bankId: bigint(20)
    bankCode: char(5)
    bankName: varchar(100)
    accountName: varchar(150)
    accountNumber: varchar(75)
    createdTime: timestamp
    createdBy: bigint(20)
    updatedTime: timestamp
    updatedBy: bigint(20)
    removedTime: timestamp
    removedBy: bigint(20)
   
}

entity "[disbursement] disbursement" as disbursement {
    *id: varchar(36)
    --
    account_name: varchar(100)
    account_number: varchar(20)
    amount: decimal(5)
    reference_id: varchar(30) <<FK>>
    bank_name: varchar(150)
    channel_bank_code: varchar(30) <<FK>>
    ...
    created_at: timestamp
    created_by: varchar(36)
    updated_at: timestamp
    updated_by: varchar(36)
   
}

entity "[disbursement] disbursement_bank" as disbursement_bank {
    *id: varchar(36)
    --
    channel: varchar(100)
    bank_code: varchar(10)
    channel_bank_code: varchar(30)
    channel_bank_name: varchar(30)
    bank_name: varchar(150)
    channel_bank_code: varchar(30)
    ...
    created_at: timestamp
    created_by: varchar(36)
    updated_at: timestamp
    updated_by: varchar(36)
   
}


b ||--|{ b_bank
b ||--|{ disbursement
disbursement_bank ||--|{ disbursement
```

## evm-brand

### Brand Create Withdrawal

```plantuml
skinparam responseMessageBelowArrow true

title  Existing Interaction Diagram

participant "client" as c
participant "evm-brand" as eb
participant "evm-disbursement" as ed
database "evm" as evm
database "disbursement" as d
database "flip-service" as fs

c -> eb : process create withdrawal
activate eb

alt if client unauthorized
    eb -> c : error unauthorized
end

eb -> evm : get & check brand_balance
activate evm
return brand_balance data

eb->ed : get & check withdrawal limit
activate ed
ed->d : get data withdrawal limit
activate d
return withdrawal limit data
return withdrawal limit data

eb -> evm : update brand balance

eb -> ed : create disbursement
activate ed
ed -> fs : process disbursement
activate fs
return disbursement_data
ed -> d : insert disbursement data
activate d
return disbursement data
return disbursement data
return disbursement data
```

```plantuml
skinparam responseMessageBelowArrow true

title  Proposed Interaction Diagram

participant "client" as c
participant "evm-brand" as eb
participant "evm-disbursement" as ed
database "evm" as evm
database "disbursement" as d
database "flip-service" as fs

c -> eb : process create withdrawal
activate eb

alt if client unauthorized
    eb -> c : error unauthorized
end

eb -> evm : get & check brand_balance
activate evm
return brand_balance data

eb -> ed : bank account number validation
activate ed
ed -> fs : check general bank + account number
activate fs
return account number validation data
return account number validation data


eb->ed : get & check withdrawal limit
activate ed
ed->d : get data withdrawal limit
activate d
return withdrawal limit data
return withdrawal limit data

eb -> evm : update brand balance

eb -> ed : create disbursement
activate ed
ed -> fs : process disbursement
activate fs
return disbursement_data
ed -> d : insert disbursement data
activate d
return disbursement data
return disbursement data
return disbursement data
```

## evm-disbursement

### Create Disbursement

```plantuml
skinparam responseMessageBelowArrow true

title  Existing Interaction Diagram

participant "client" as c
participant "evm-disbursement" as ed
database "disbursement" as d
database "flip-service" as fs

c -> ed : process create disbursement
activate ed

alt if client unauthorized
    ed -> c : error unauthorized
end


ed -> fs : process disbursement
activate fs
return disbursement_data
ed -> d : insert disbursement data
activate d
return disbursement data
return disbursement data
```

```plantuml
skinparam responseMessageBelowArrow true

title  Proposed Interaction Diagram

participant "client" as c
participant "evm-disbursement" as ed
database "disbursement" as d
database "flip-service" as fs

c -> ed : process create disbursement
activate ed

alt if client unauthorized
    ed -> c : error unauthorized
end

ed -> fs : check general bank + bank account number validation
activate fs
return account number validation data


ed -> fs : process disbursement
activate fs
return disbursement_data
ed -> d : insert disbursement data
activate d
return disbursement data
return disbursement data
```