# nz-m/socialecho architecture

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

- Interactive diagram: https://gitdiagram.com/nz-m/socialecho
- Repository: https://github.com/nz-m/socialecho

## Overview

##### Main Components
- Frontend (Client): Built with React.js and Redux, it contains all UI components (e.g., pages for Home, Profile, Admin Panel, Moderator dashboards, etc.), client-side routing, middleware, and state management.
- Backend API Server: Built with Node.js and Express.js; it handles API endpoints for authentication, posts, comments, community management, user profiles and other core social media operations.
- Database: MongoDB serves as the data store for user profiles, posts, communities, tokens, logs, and other application data.
- Classifier/Content Moderation Service: A Flask-based microservice (located under the classifier_server directory) provides content classification using the BART Large MNLI model (or alternatively, integration with external NLP APIs like Perspective API, TextRazor, or Hugging Face Interface API).
- Email & Notification Service: Used for sending email notifications for suspicious logins and context-based authentication alerts, integrated via Nodemailer.
- External APIs and Libraries: The system integrates with multiple third-party services (Perspective API, TextRazor API, Hugging Face Interface API) for automated content moderation.
- Administrative Tools: Scripts (like the admin_tool.sh) and dedicated admin routes/controllers facilitate configuration and management of communities, moderators, and system settings.

##### Relationships & Interactions
- The Frontend communicates directly with the Backend API Server over HTTP(S) – using RESTful API endpoints for all user operations.
- The Backend Server interacts with the Database (MongoDB) for CRUD operations.
- For content moderation, when a post is created, the Backend either:
– Calls the external moderation APIs (Perspective, TextRazor, Hugging Face) via a common interface, or
– Routes the content to the Flask classifier in the classifier_server.
- The Backend incorporates authentication middleware using JWT and Passport.js – ensuring secure access control (e.g., differentiating between Admin, Moderator, and General User roles).
- Additional services include token generation/verification, logging mechanisms, and device/context management for two-factor context-based authentication.
- Admin and moderator dashboards receive tailored data views by invoking specific routes and controllers in the backend.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The clear division between frontend, backend, and the classifier service ensures modularity.
- Microservices: The classifier_server as a distinct service represents a microservice architecture element.
- Middleware and API Gateways: Use of authentication, logging, rate limiting, and input validation middleware to manage request flows.
- Redux and Component-based UI design in the frontend provide scalable state management and UI modularity.
- Use of scripts and Docker for deployment: The Dockerfile in the classifier_server and admin_tool.sh script in the server directory indicate automated deployment and configuration practices.

##### Technologies/Frameworks Emphasized
- Frontend: React.js, Redux, Tailwind CSS.
- Backend: Node.js, Express.js, Passport.js, JWT.
- Database: MongoDB.
- Content Moderation: Integration of NLP APIs, Flask with PyTorch.
- DevOps: Docker in classifier_server, environment configuration using .env files.

##### Final Steps
- Important scripts, configuration elements (Dockerfiles, .env files), and admin tools are represented or annotated as part of the deployment/configuration infrastructure.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend Layer"
        RC["React Client"]:::frontend
    end

    subgraph "Backend Layer"
        ES["Express API Server"]:::backend
    end

    subgraph "Database Layer"
        DB["MongoDB"]:::database
    end

    subgraph "Content Moderation Services"
        FC["Flask Content Classifier"]:::moderation
        NL["External NLP Services"]:::moderation
    end

    subgraph "Notification Services"
        ET["Email Templates"]:::notification
        EM["Email Model"]:::notification
    end

    subgraph "Administration"
        AT["Admin Tool (Shell)"]:::administration
        AC["Admin Controller"]:::administration
        AR["Admin Routes"]:::administration
    end

    RC -->|"HTTP_API"| ES
    ES -->|"CRUD_ops"| DB
    ES -->|"Moderation_req"| FC
    ES -->|"Moderation_req"| NL
    ES -->|"Send_alert"| ET
    ES -->|"Send_alert"| EM
    ES -->|"Admin_ops"| AC
    AC -->|"Configured_via"| AR
    AC -->|"Initiates"| AT

    click RC "https://github.com/nz-m/socialecho/tree/main/client/"
    click ES "https://github.com/nz-m/socialecho/tree/main/server/"
    click DB "https://github.com/nz-m/socialecho/blob/main/server/config/database.js"
    click FC "https://github.com/nz-m/socialecho/tree/main/classifier_server/"
    click NL "https://github.com/nz-m/socialecho/blob/main/server/services/apiServices.js"
    click ET "https://github.com/nz-m/socialecho/blob/main/server/utils/emailTemplates.js"
    click EM "https://github.com/nz-m/socialecho/blob/main/server/models/email.model.js"
    click AT "https://github.com/nz-m/socialecho/blob/main/server/admin_tool.sh"
    click AC "https://github.com/nz-m/socialecho/blob/main/server/controllers/admin.controller.js"
    click AR "https://github.com/nz-m/socialecho/blob/main/server/routes/admin.route.js"

    classDef frontend fill:#b3d9ff,stroke:#0073e6,stroke-width:2px;
    classDef backend fill:#d9ffd9,stroke:#00b300,stroke-width:2px;
    classDef database fill:#ffe6b3,stroke:#ff9900,stroke-width:2px;
    classDef moderation fill:#ffd9d9,stroke:#ff3333,stroke-width:2px;
    classDef notification fill:#e6ccff,stroke:#9933ff,stroke-width:2px;
    classDef administration fill:#ffffcc,stroke:#ffcc00,stroke-width:2px;
```
