# rolly93/border_crossing architecture

> Architecture diagram of the GitHub repository rolly93/border_crossing, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rolly93/border_crossing
- Repository: https://github.com/rolly93/border_crossing

## Overview

##### Project type and purpose
- This is a full-stack, desktop-wrapped web application.
- Backend: Python + Flask REST endpoints, business logic, SQLite.
- Frontend: Jinja2 HTML templates + CSS + JS, rendered inside a pywebview desktop window.
- Purpose: Let carriers generate and send XML event files (AFS, DPU, etc.) over FTP, track statuses via email, and self-update asynchronously from GitHub.

##### File structure
- Top level:
- app.py (entry point, launches Flask and pywebview)
- Procfile, render.yaml (deployment config)
- requirements.txt (deps)
- backend/
- db/ (SQLite config & wrapper)
- model/ (entities + ORM-like models)
- routes/ (Flask blueprints: api, auth, client, dashboard, empleado, shipment)
- utility/service/ (auth_service.py, email_service.py)
- utility/ (shipment_logic.py, xml_export.py, helpers)
- exception/ (custom exception classes)
- static/ + templates/ (UI layer: JS modules, styles, Jinja2 components)

##### README for additional insights
- Describes events, file formats (XML), transport (FTP), notifications (email).
- Mentions pywebview desktop wrapper and GitHub-based update checks.

##### Main components
a. Desktop Shell (pywebview)
b. Frontend UI Layer
– Templates (Jinja2)
– Static assets (JS, CSS)
c. Backend Application Layer
– Flask app & route handlers
d. Business Logic Layer
– ShipmentLogic, XMLExport, AuthService, EmailService
e. Data Layer
– SQLite database (logistica.db) via db/db.py
f. External Services
– FTP Server
– SMTP Server (email)
– GitHub (update checks)

##### Relationships and data flow
- Desktop Shell ↔ HTTP ↔ Flask Routes
- Flask Routes ↔ Business Logic
- Business Logic ↔ Data Layer (CRUD operations)
- ShipmentLogic ↔ XMLExport → FTP Server
- Business Logic ↔ EmailService → SMTP Server
- Update module (in app.py) polls GitHub → triggers desktop app update

##### Architectural patterns & principles
- Layered/MVC style separation:
- Models (backend/model)
- Views (templates/static)
- Controllers (Flask routes)
- Service abstractions for cross-cutting concerns (auth, email).
- Single-database, synchronous calls inside desktop wrapper.

##### Essential elements checklist
- Components: Desktop Shell, UI, Backend, DB, FTP, Email, GitHub
- Clear naming: e.g., ShipmentLogic, xml_export, auth_service
- Grouping and layering to reflect separation of concerns

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Desktop Wrapper"
        DesktopShell["Desktop Shell (pywebview)"]:::desktop
    end

    subgraph "UI Layer"
        Templates["Templates (Jinja2)"]:::ui
        Static["Static Assets (JS, CSS)"]:::ui
    end

    subgraph "Backend Application"
        subgraph "Controllers (Flask Routes)"
            api["api.py"] 
            auth["auth.py"]
            client["client.py"]
            dashboard["dashboard.py"]
            empleado["empleado.py"]
            shipment_route["shipment.py"]
        end
        subgraph "Services"
            authsvc["AuthService"]:::service
            emailsvc["EmailService"]:::service
        end
        subgraph "Utilities"
            shiplogic["ShipmentLogic"]:::logic
            xmlexp["XMLExport"]:::logic
        end
        exceptions["Exceptions"]:::exception
        model_entities["entities.py"]:::model
        model_models["models.py"]:::model
    end

    subgraph "Data Layer"
        dbwrapper["db.py"]:::data
        dbfile["logistica.db"]:::data
    end

    subgraph "External Services"
        ftp["FTP Server"]:::external
        smtp["SMTP Server"]:::external
        github["GitHub (Update Checks)"]:::external
    end

    subgraph "Config & Deployment"
        procfile["Procfile"]:::config
        rendercfg["render.yaml"]:::config
        reqs["requirements.txt"]:::config
    end

    DesktopShell -->|"renders"| Templates
    DesktopShell -->|"renders"| Static
    Templates -->|"HTTP/JSON"| api
    Static -->|"HTTP/JSON"| api

    api -->|"calls"| shiplogic
    api -->|"calls"| authsvc
    api -->|"calls"| emailsvc
    api -->|"uses"| exceptions
    auth -->|"calls"| authsvc
    auth -->|"uses"| exceptions
    client -->|"calls"| shiplogic
    client -->|"uses"| exceptions
    dashboard -->|"calls"| shiplogic
    dashboard -->|"uses"| exceptions
    empleado -->|"calls"| authsvc
    empleado -->|"uses"| exceptions
    shipment_route -->|"calls"| shiplogic
    shipment_route -->|"uses"| exceptions

    shiplogic -->|"uses"| dbwrapper
    shiplogic -->|"calls"| xmlexp
    xmlexp -->|"FTP/XML"| ftp
    authsvc -->|"uses"| dbwrapper
    emailsvc -->|"SMTP"| smtp

    dbwrapper -->|"SQL"| dbfile
    model_entities --> dbwrapper
    model_models --> dbwrapper

    DesktopShell -->|"polls"| github
    github -->|"releases"| DesktopShell

    DesktopShell --> config
    config --> procfile
    config --> rendercfg
    config --> reqs

    click DesktopShell "https://github.com/rolly93/border_crossing/blob/main/app.py"
    click Templates "https://github.com/rolly93/border_crossing/tree/main/templates/"
    click Static "https://github.com/rolly93/border_crossing/tree/main/static/"
    click api "https://github.com/rolly93/border_crossing/blob/main/backend/routes/api.py"
    click auth "https://github.com/rolly93/border_crossing/blob/main/backend/routes/auth.py"
    click client "https://github.com/rolly93/border_crossing/blob/main/backend/routes/client.py"
    click dashboard "https://github.com/rolly93/border_crossing/blob/main/backend/routes/dashboard.py"
    click empleado "https://github.com/rolly93/border_crossing/blob/main/backend/routes/empleado.py"
    click shipment_route "https://github.com/rolly93/border_crossing/blob/main/backend/routes/shipment.py"
    click shiplogic "https://github.com/rolly93/border_crossing/blob/main/backend/utility/shipment_logic.py"
    click xmlexp "https://github.com/rolly93/border_crossing/blob/main/backend/utility/xml_export.py"
    click authsvc "https://github.com/rolly93/border_crossing/blob/main/backend/utility/service/auth_service.py"
    click emailsvc "https://github.com/rolly93/border_crossing/blob/main/backend/utility/service/email_service.py"
    click dbwrapper "https://github.com/rolly93/border_crossing/blob/main/backend/db/db.py"
    click dbfile "https://github.com/rolly93/border_crossing/blob/main/backend/db/logistica.db"
    click exceptions "https://github.com/rolly93/border_crossing/blob/main/backend/exception/exceptions.py"
    click model_entities "https://github.com/rolly93/border_crossing/blob/main/backend/model/entities.py"
    click model_models "https://github.com/rolly93/border_crossing/blob/main/backend/model/models.py"
    click procfile "https://github.com/rolly93/border_crossing/tree/main/Procfile"
    click rendercfg "https://github.com/rolly93/border_crossing/blob/main/render.yaml"
    click reqs "https://github.com/rolly93/border_crossing/blob/main/requirements.txt"

    classDef desktop fill:#add8e6;
    classDef ui fill:#90ee90;
    classDef backend fill:#fffacd;
    classDef data fill:#ffdead;
    classDef external fill:#d3d3d3;
    classDef service fill:#ffe4b5;
    classDef logic fill:#ffe4b5;
    classDef model fill:#fafad2;
    classDef exception fill:#f0e68c;
    classDef config fill:#e6e6fa;
```
