# wekers/tcc-retaguardaloja architecture

> Architecture diagram of the GitHub repository wekers/tcc-retaguardaloja, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wekers/tcc-retaguardaloja
- Repository: https://github.com/wekers/tcc-retaguardaloja

## Overview

##### Project Type and Purpose
- This is a monolithic, thick-client desktop application (“Retaguarda de Loja”) developed in PowerBuilder 2022 R3.
- It exposes a rich GUI (windows, menus, DataWindow objects) and contains embedded business logic and data access code.
- It connects via ODBC to a PostgreSQL database and includes auxiliary executables for backup and auto-updates.

##### High-Level File Structure Analysis
- Top-level executables and project artifacts:
- RetaguardaTCC.pbw, retaguarda.pbt, Releases/… (retaguarda.exe/.pbd/.pbt/.xml + updater.exe)
- Instalador/Install_RetaguardaDeLoja.exe
- Source code directory (`ws_objects/retaguarda.pbl.src` & `ws_objects/Backup db`):
- PowerBuilder objects (.sru, .srw, .srd, .srf, .srj, .srm) organized by window, DataWindow, function, user object, menu, script.
- Database scripts (`Banco de Dados/`):
- DDL and DML scripts (.sql) for schema creation, seed data, truncation.
- Configuration and automation:
- ODBC Profile DB.ini, config.ini for backup, update.txt, updater.ini.

##### Key Components
a. Presentation Layer
- PowerBuilder Client Application
– UI Windows & Menus (w_*.srw, m_menu.srm)
– DataWindow objects (d_*.srd) for querying and binding data
– Business functions and user objects (.srf, .sru, .srj)
b. Data Access Layer
- ODBC 64-bit Driver (ODBC Profile DB.ini)
- Connection pooling, SQL execution via DataWindow retrieval objects
c. Data Store Layer
- PostgreSQL Database
– Schema and tables generated by Banco de Dados/*.sql
d. Auxiliary Services
- Backup Utility (backupdb.exe + config.ini)
- Auto-Updater (updater.exe + updater.ini + update.txt)
- Installer (Advanced Installer package)
e. Release & Deployment
- Releases folder (versioned binaries and metadata XML)
- Install_RetaguardaDeLoja.exe

##### Relationships and Data Flows
- The PowerBuilder client issues queries and DML via DataWindow objects → travels over ODBC → PostgreSQL.
- GUI actions (login, CRUD, reports) invoke functions in code objects → generate SQL retrievals/updates.
- Backup Utility connects directly to the DB via its own ODBC profile to dump/restore data.
- Auto-Updater checks `updates/update.txt` on startup or schedule → downloads new binaries from Releases → overwrites local install.
- Installer orchestrates initial deployment: places client EXE, config files, ODBC profile, and DB scripts.

##### Architectural Patterns & Design Principles
- Layered Monolith: Presentation & Business Logic co-located in one deployable; Data Access abstracted through DataWindow retrieval/specification objects.
- Code Organization: PB objects grouped by feature (windows, data windows, scripts), facilitating modular maintenance.
- Externalization of Configuration: INI files for database connection and backup/updater parameters.
- Versioned Releases: XML manifests accompany each binary release for metadata/patching.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% PowerBuilder Client Layer
    subgraph "PowerBuilder Client" 
        direction TB
        PBUI["PB Client UI\n(w_*.srw, m_menu.srm)"]:::frontend
        PBLogic["PB Business Logic & User Objects\n(.srf, .srj, .sru)"]:::frontend
        DataWin["DataWindow Objects\n(.srd)"]:::frontend
        ClientProj["Client Project Files\n(retaguarda.pbt, RetaguardaTCC.pbw)"]:::frontend
    end

    %% Data Access Layer
    ODBC["ODBC Driver\n(Profile DB.ini)"]:::config

    %% Data Store
    Postgre["PostgreSQL DB"]:::database

    %% Auxiliary Services
    subgraph "Auxiliary Services"
        direction TB
        Backup["Backup Service\n(backupdb.exe, config.ini)"]:::aux
        Updater["Auto-Updater Service\n(updater.exe, updater.ini)"]:::aux
        Installer["Installer\n(Install_RetaguardaDeLoja.exe)"]:::aux
    end

    %% Release & Updates
    subgraph "Releases & Updates"
        direction TB
        Releases["Releases Repo\n(retaguarda.exe/.pbd/.pbt/.xml)"]:::aux
        UpdateMan["Update Manifest\n(update.txt)"]:::config
    end

    %% Database Scripts
    DBScripts["DB Scripts\n(Banco de Dados/*.sql)"]:::scripts

    %% Documentation
    subgraph "Docs & Diagrams"
        direction TB
        Diagrams["diagramas/"]:::docs
        Manual["manual/"]:::docs
    end

    %% Relationships
    PBUI -->|"invokes UI actions"| PBLogic
    PBLogic -->|"calls data functions"| DataWin
    DataWin -->|"ODBC call"| ODBC
    ODBC -->|"SQL over ODBC"| Postgre

    Backup -->|"Backup dump"| ODBC
    Updater -->|"Fetch updates"| UpdateMan
    UpdateMan -->|"points to new binaries"| Releases
    Updater -->|"download patch"| Releases
    Installer -->|"initial install"| ClientProj
    Installer -->|"deploy configs & scripts"| DBScripts
    Installer -->|"setup ODBC profile"| ODBC

    %% Click Events
    click PBUI "https://github.com/wekers/tcc-retaguardaloja/blob/main/ws_objects/retaguarda.pbl.src"
    click DataWin "https://github.com/wekers/tcc-retaguardaloja/blob/main/ws_objects/retaguarda.pbl.src"
    click PBLogic "https://github.com/wekers/tcc-retaguardaloja/blob/main/ws_objects/retaguarda.pbl.src"
    click ClientProj "https://github.com/wekers/tcc-retaguardaloja/blob/main/retaguarda.pbt"
    click ClientProj "https://github.com/wekers/tcc-retaguardaloja/blob/main/RetaguardaTCC.pbw"
    click ODBC "https://github.com/wekers/tcc-retaguardaloja/blob/main/ODBC Profile DB.ini"
    click DBScripts "https://github.com/wekers/tcc-retaguardaloja/tree/main/Banco de Dados"
    click Backup "https://github.com/wekers/tcc-retaguardaloja/blob/main/ws_objects/Backup db/backupdb.exe"
    click Backup "https://github.com/wekers/tcc-retaguardaloja/blob/main/ws_objects/Backup db/config.ini"
    click Updater "https://github.com/wekers/tcc-retaguardaloja/blob/main/Releases/*/updater.exe"
    click Updater "https://github.com/wekers/tcc-retaguardaloja/blob/main/Releases/*/updater.ini"
    click UpdateMan "https://github.com/wekers/tcc-retaguardaloja/blob/main/updates/update.txt"
    click Installer "https://github.com/wekers/tcc-retaguardaloja/blob/main/Instalador/Install_RetaguardaDeLoja.exe"
    click Releases "https://github.com/wekers/tcc-retaguardaloja/tree/main/Releases/<version>"
    click Diagrams "https://github.com/wekers/tcc-retaguardaloja/tree/main/diagramas/"
    click Manual "https://github.com/wekers/tcc-retaguardaloja/tree/main/manual/"

    %% Styles
    classDef frontend fill:#B3D7FF,stroke:#037AFF,color:#000
    classDef database fill:#A2F5A2,stroke:#1E8E1E,color:#000
    classDef aux fill:#D3D3D3,stroke:#696969,color:#000
    classDef config fill:#E8E8E8,stroke:#B0B0B0,color:#000
    classDef scripts fill:#FFF2CC,stroke:#E6C200,color:#000
    classDef docs fill:#FFE4B5,stroke:#DAA520,color:#000
```
