# abel2319/social_media_backend architecture

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

- Interactive diagram: https://gitdiagram.com/abel2319/social_media_backend
- Repository: https://github.com/abel2319/social_media_backend

## Overview

##### Project type and purpose
- This is a C++‐based backend service (“Social_Medial_Backend”) that listens on a socket, processes client requests, and reads/writes fragmented data across three remote PostgreSQL servers.

##### File structure
- Top‐level:
- README.md, database.sql (schema & fragmentation script)
- images/ (possibly UI mocks or data flow sketches)
- src/ (all C++ source + one header)
- src/:
- main.cpp – entry point, sets up socket listener and dispatch loop
- connexion.cpp – socket setup, accept(), read/write data
- classeUsers.cpp / classePub.cpp – classes modeling Users and Publications
- tools.cpp – helper routines (parsing, data‐structure manipulation)
- header.h – class declarations (fields, methods)

##### README
- Core features:
- Socket‐based C++ server
- PostgreSQL fragmentation across three remote machines
- No explicit data‐structure commentary, but “classes” imply encapsulated collections

a. Main components:
- Client(s) (e.g., mobile/web front end)
- Connection Manager (socket listener in connexion.cpp)
- Business Logic Layer
– UserManager (classeUsers)
– PublicationManager (classePub)
– Tools/Utils (tools.cpp)
- Database Cluster (3× Postgres instances, fragmentation layer)
b. Relationships & interactions:
- Client → Connection Manager (TCP socket)
- Connection Manager → Business Logic (invokes UserManager or PublicationManager)
- Business Logic → Database Cluster (via libpq or raw SQL over TCP)
- Tools provide shared data parsing, logging, in‐memory collections
c. Architectural patterns & principles:
- Modular classes for each domain entity (Users, Publications)
- Single Responsibility: connexion.cpp only handles networking, tools.cpp only utilities
- Repository‐like data access (classes encapsulate SQL queries)
d. Technologies & libraries:
- C++17/14, STL containers (vector, map, list) for in‐memory caching
- POSIX sockets or Boost.Asio for network I/O
- libpq/libpqxx or direct TCP for PostgreSQL connections
- SQL scripts (database.sql) to set up fragmentation

##### Data‐structure visualization (per your study goal)
- For each C++ class, extract its fields and map them to container types:
- classeUsers → e.g., std::vector<User>, std::map<userID,User>
- classePub → std::list<Publication> or std::unordered_map<pubID,Publication>
- tools.cpp → any specialized structures (e.g., priority queue for notifications)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Network Tier"
        Client["Client(s)"]:::network
        EntryPoint["Application Entry Point\n(main.cpp)"]:::network
        ConnMgr["Connection Manager\n(src/connexion.cpp)"]:::network
    end

    subgraph "Application Tier"
        UM["UserManager\nstd::vector<User>\nstd::map<userID,User>"]:::logic
        PM["PublicationManager\nstd::list<Publication>\nstd::unordered_map<pubID,Publication>"]:::logic
        Tools["Tools/Utilities\nparsing, in-memory\npriority_queue"]:::logic
        SD["Shared Class Declarations\n(header.h)"]:::logic
    end

    subgraph "Data Tier"
        DB1["PostgreSQL Server A"]:::datastore
        DB2["PostgreSQL Server B"]:::datastore
        DB3["PostgreSQL Server C"]:::datastore
    end

    subgraph "Artifacts"
        README["Project Overview & Instructions\n(README.md)"]:::artifact
        DBScript["Database Script & Schema\n(database.sql)"]:::artifact
        UML["UML Class Diagrams\n(prototypes/class_diagram)"]:::artifact
        DBModel["Database Diagram & Model\n(prototypes/database.dbm)"]:::artifact
        ProtoDB["Additional Prototype Assets\n(prototypes/database)"]:::artifact
        Images["UI Mocks / Sketches\n(images/)"]:::artifact
    end

    %% Connections
    Client -->|"TCP socket"| ConnMgr
    EntryPoint -->|"initializes"| ConnMgr
    ConnMgr -->|"dispatch"| UM
    ConnMgr -->|"dispatch"| PM
    ConnMgr -->|"util calls"| Tools

    UM -->|"includes"| SD
    PM -->|"includes"| SD
    Tools -->|"includes"| SD

    UM ---|"SQL (fragmented)"| DB1
    UM ---|"SQL (fragmented)"| DB2
    UM ---|"SQL (fragmented)"| DB3

    PM ---|"SQL (fragmented)"| DB1
    PM ---|"SQL (fragmented)"| DB2
    PM ---|"SQL (fragmented)"| DB3

    %% Legend
    subgraph Legend
        N["■ Network Tier"]:::network
        L["■ Application Logic Tier"]:::logic
        D["■ Data Tier (DB)"]:::datastore
        A["■ Project Artifacts"]:::artifact
        S["--- Dashed: Fragmented DB calls"]:::dashed
    end

    %% Click Events
    click ConnMgr "https://github.com/abel2319/social_media_backend/blob/main/src/connexion.cpp"
    click EntryPoint "https://github.com/abel2319/social_media_backend/blob/main/src/main.cpp"
    click UM "https://github.com/abel2319/social_media_backend/blob/main/src/classeUsers.cpp"
    click PM "https://github.com/abel2319/social_media_backend/blob/main/src/classePub.cpp"
    click Tools "https://github.com/abel2319/social_media_backend/blob/main/src/tools.cpp"
    click SD "https://github.com/abel2319/social_media_backend/blob/main/src/header.h"
    click README "https://github.com/abel2319/social_media_backend/blob/main/README.md"
    click DBScript "https://github.com/abel2319/social_media_backend/blob/main/database.sql"
    click UML "https://github.com/abel2319/social_media_backend/tree/main/prototypes/class_diagram"
    click DBModel "https://github.com/abel2319/social_media_backend/blob/main/prototypes/database.dbm"
    click ProtoDB "https://github.com/abel2319/social_media_backend/tree/main/prototypes/database"
    click Images "https://github.com/abel2319/social_media_backend/tree/main/images/"

    %% Styles
    classDef network fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef logic fill:#90EE90,stroke:#333,stroke-width:1px
    classDef datastore fill:#FFA500,stroke:#333,stroke-width:1px
    classDef artifact fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef dashed stroke-dasharray: 5 5;font-style:italic;color:#333
```
