# 3adrot-shot/crm-system-server architecture

> Architecture diagram of the GitHub repository 3adrot-shot/crm-system-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/3adrot-shot/crm-system-server
- Repository: https://github.com/3adrot-shot/crm-system-server

## Overview

##### Main Components
- UI Layer: This is composed of the WPF XAML files like MainWindow.xaml, WindowMain.xaml, Page1.xaml, and the UserControls (Main_UC.xaml). They form the graphical interface that displays the log report of sent/received messages, response times, sender addresses, and contents.
- Backend/Logic Layer: Managed in the “Back” folder, this includes:
- Socket_Controller.cs: Handles the TCP communications (listening on port 8081).
- ProcessingMessage.cs: Processes and routes inbound messages.
- PostgresSQL_Controller.cs: Manages connectivity with the PostgreSQL 14 database.
- Configuration & Project Setup: Files like App.config in the project (which may contain settings such as TCP port and database configuration) along with the .sln and .csproj files.
- Auxiliary Components: Threads and data processing outlines and possibly additional utility functions hidden in the code (like logging and settings management).

##### Relationships and Interactions
- The UI layer interacts with the backend via data binding and service calls – for example, displaying the report data updated in real time as messages are processed.
- The TCP Server component (Socket_Controller) continuously listens on the global TCP port (default port 8081). When a message arrives, it hands off the message to ProcessingMessage.
- ProcessingMessage handles the business logic and may call the PostgresSQL_Controller to record or query data against the local (or potentially remote) PostgreSQL database.
- The response (or log/status update) is then propagated back to the UI for visualization.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The division of UI and backend logic is clearly established (WPF UI versus TCP/database handling).
- Multi-threading: The README mentions that the core functions of the server run on a separate thread, so indicate that the server’s listening and processing operations are decoupled from the UI thread.
- Client-Server Interaction: Even though this is an internal system, highlighting the request-response model (for TCP communication) is key.

##### Technologies and Frameworks
- WPF (Windows Presentation Foundation) for the UI.
- .NET (as indicated by the .sln and .csproj files).
- PostgreSQL for data persistence.
- TCP/IP networking fundamentals implemented in the backend.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% External Entity
    Ext["External Client"]:::external

    %% UI Layer Subgraph
    subgraph "WPF UI (UI Thread)"
        UI_MainWindow["MainWindow (UI)"]:::ui
        UI_WindowMain["WindowMain (UI)"]:::ui
        UI_Page1["Page1 (UI)"]:::ui
        UI_UserControls["Main_UC (UserControls)"]:::ui
    end

    %% Backend / Logic Layer Subgraph (Background Thread)
    subgraph "Backend / Logic (Background Thread)"
        SC["Socket_Controller (TCP Listener 8081)"]:::backend
        PM["ProcessingMessage (Business Logic)"]:::backend
        PG["PostgresSQL_Controller (DB Connector)"]:::backend
    end

    %% Configuration & Project Setup Subgraph
    subgraph "Configuration & Setup"
        AC["App.config (Settings)"]:::config
        AX["App.xaml"]:::config
        CP["TableHost.csproj & TableHost.sln"]:::config
    end

    %% Auxiliary Components Subgraph
    subgraph "Auxiliary Components"
        SET["Settings.settings"]:::aux
        SETD["Settings.Designer.cs"]:::aux
    end

    %% Data Flow
    Ext -->|"TCPRequest"| SC
    SC -->|"PassMessage"| PM
    PM -->|"DBQuery/Update"| PG
    PM -->|"UIUpdate"| UI_MainWindow

    %% Configuration Influence
    AC ---|"configures"| SC
    AC ---|"configures"| PM
    AC ---|"configures"| PG

    %% UI Components Interaction (data binding update)
    UI_MainWindow ---|"data binding"| UI_WindowMain
    UI_WindowMain ---|"data binding"| UI_Page1
    UI_Page1 ---|"data binding"| UI_UserControls

    %% Click Events
    click UI_MainWindow "https://github.com/3adrot-shot/crm-system-server/blob/master/TableHost/MainWindow.xaml"
    click UI_WindowMain "https://github.com/3adrot-shot/crm-system-server/blob/master/TableHost/WindowMain.xaml"
    click UI_Page1 "https://github.com/3adrot-shot/crm-system-server/blob/master/TableHost/Page1.xaml"
    click UI_UserControls "https://github.com/3adrot-shot/crm-system-server/blob/master/TableHost/UserControls/Main_UC.xaml"
    click SC "https://github.com/3adrot-shot/crm-system-server/blob/master/TableHost/Back/Socket_Controller.cs"
    click PM "https://github.com/3adrot-shot/crm-system-server/blob/master/TableHost/Back/ProcessingMessage.cs"
    click PG "https://github.com/3adrot-shot/crm-system-server/blob/master/TableHost/Back/PostgresSQL_Controller.cs"
    click AC "https://github.com/3adrot-shot/crm-system-server/blob/master/TableHost/App.config"
    click AX "https://github.com/3adrot-shot/crm-system-server/blob/master/TableHost/App.xaml"
    click CP "https://github.com/3adrot-shot/crm-system-server/blob/master/TableHost/TableHost.csproj"
    click CP "https://github.com/3adrot-shot/crm-system-server/blob/master/TableHost.sln"
    click SET "https://github.com/3adrot-shot/crm-system-server/blob/master/TableHost/Properties/Settings.settings"
    click SETD "https://github.com/3adrot-shot/crm-system-server/blob/master/TableHost/Properties/Settings.Designer.cs"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef config fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef aux fill:#FFCCFF,stroke:#000,stroke-width:1px;
    classDef external fill:#FFD700,stroke:#000,stroke-width:1px;
```
