# MRT
General Class Diagram
```mermaid
classDiagram
class TrxASource {
+String identifier
+String namespace
+String consumer
+String source_type
+Bigdecimal amount
+DateTime created_at
+String raw_source
}
class TrxBSource{
+String identifier
+String source_type
+Bigdecimal amount
+DateTime created_at
+String report_id
+Boolean match
+String unmatch_note
}
class Report {
+String id
+String Processor
+String reader
+String writer
+String reader_cfg
+String writer_cfg
+String reporter_cfg
+String downloadable_links
+String md5
+String state
+Boolean match
+Integer missmatch_row
+Integer missmatch_amount
+String string_var_1
+String string_var_2
+String string_var_3
+String string_var_4
+String string_var_5
+Int integer_var_1
+Int integer_var_2
+Int integer_var_3
+Int integer_var_4
+Int integer_var_5
read()
write()
report()
reconcile()
process()
input_row() interface
output_row() interface
}
class ReportChunk {
+String id
+String report_id
+String cursor
+Integer limit
+String state
}
class Reporter{
}
class Reader{
}
class Writer{
}
class ProcessorBCA {
input_row()
output_row()
}
class ProcessorGopay {
input_row()
output_row()
}
class ProcessorQRIS {
input_row()
output_row()
}
Report --|> ProcessorBCA : Inheritance
Report --|> ProcessorGopay : Inheritance
Report --|> ProcessorQRIS : Inheritance
Report "1" --> "*" ReportChunk
Report "1" --> "*" TrxBSource
Report --* Reader
Report --* Writer
Report --* Reporter
```
## Populating Trx A
each `Trx A` will be populated through event, cmp-rep team defined the standard payload for a single trxasource. cmp-rep team has on consumer to consume that event and inserting to datastore.
```mermaid
graph LR
pp(Papi Trx Consumer)
LB(Lombok Trx publisher)
kfk[(Kafka)]
transform([MRT Payload])
mrt(MRT Consumer)
DB(MRT DB)
pp-->transform
LB-->transform
transform-->kfk
kfk-.->mrt
mrt-->DB
```
## Populating Trx B
trx b source is expected from a remote source, and every single session of populating Trx B from will be represent by `Report` object in MRT.
## Report
for a `Report` it'll require the information `reader` & `writer` & `reporter` and it'll be declared by a `Processor` class.
Report consist of 3 protected method
- read
- write
- report
- reconcile
- process
and all the `Processor` classs are responsible to define the
- input_row
- output_row
`input_row` : function how each row from the input will be stored in MRT Trx B and also, `output_row` how eac row will be presented in the the output file.
```mermaid
graph LR
start((start))
stop((stop))
job1([Storing Worker ])
job2([Reconcile Worker ])
job3([Chunk Worker 1])
job4([Chunk Worker 2])
job5([Chunk Worker n])
job6([Report Worker])
step7{check completness}
start-->job1
job1-->job2
job2-->job3
job2-->job4
job2-->job5
job3-->step7
job4-->step7
job5-->step7
step7-->job6
job6-->stop
```
## Storing Worker
```mermaid
sequenceDiagram
Processor->>Processor : initiate Report
Processor->>Report : Store Report
Report-->>Processor : Get Report Object
Processor->>Report : trigger process
Report->>Report : Read
Report->>S3 : Get the file
S3-->>Report : Return File
Report->>Report : Start Iterate each Line
loop iterate
Report ->> Processor : trigger Store()
Processor -->> Report : return TrxBPayload
Report ->> TrxB : Save The payload
end
```
nb :
- S3 is sample of reader interface of this diagram
## Reconcile Worker
```mermaid
sequenceDiagram
Processor -x Report : Trigger Reconcile
Report ->> Report : Split TrxA in to Chunks
loop iterate
Report -x ReportChunk : Create report chunk (async)
ReportChunk ->> TrxA : Query By Given Cursor and Limit
ReportChunk ->> TrxB : Query By Given Cursor and Limit
ReportChunk ->> ReportChunk : Match each row
ReportChunk ->> Report : Updating Variable
ReportChunk ->> Report : Trigger Completion Check.
end
Report ->> Report : Trigger report
Report ->> TrxB : Query the row
loop iterate
TrxB -->> Report : return single row
Report ->> Processor : trigger outpur_row
Processor -->> Report : Return formatted line for the report file
Report ->> Report : Append the line to local fs
end
Report ->> Report : call write
Report ->> SFTP : Upload file
SFTP -->> Report : return file location info
Report ->> Report : trigger Report
Report ->> Pato : Send the report
```
nb :
- SFTP is sample of writer interface of this diagram