# davidchau21/eforum-blog-web architecture

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

- Interactive diagram: https://gitdiagram.com/davidchau21/eforum-blog-web
- Repository: https://github.com/davidchau21/eforum-blog-web

## Overview

##### Main Components Identification

a. Client/Frontend Layers:
- User Interface (Frontend): Located in the “frontend” directory, it is built with React (using Vite), TailwindCSS, and uses Axios for API connections. It provides pages for the forum (posts, chat, notifications, profile, etc.).
- Admin Interface (Admin-web): Found in the “admin-web” directory, this is also a React-based application that provides administrative capabilities (user and post management, statistics, content moderation, etc.). Notice that it has its own set of API calls and state management.

b. Backend API Services:
- REST API and Business Logic: The “backend” and “server” directories both implement the core API servers using Express. They are structured with routers, controllers, middleware (e.g., verifyToken), and models/schemas (for Blogs, Comments, Users, etc.), which suggests a layered (MVC-like) architecture.
- Real-Time Messaging: Both backend directories include “socket” modules using socket.io to support realtime chat and notifications.

c. External Services & Integrations:
- Database: MongoDB is used as the primary data store for forums (posts, comments, notifications, etc.). The schemas in both backend/server directories indicate document-based models.
- Cloud Storage & Third-party APIs: AWS S3 for image/storage, Firebase for Google authentication integration, and integration with Google API (via googleapis package) are used.
- Email Services: Various services are integrated (nodemailer, mailtrap, brevo, oauth2) for mail functionalities including OTP and password resets.

##### Relationships and Interactions Between Components

- Both frontends (user and admin) communicate with the backend REST API using HTTP (Axios in the frontend) to fetch/post data.
- Socket.io connections are established between the client apps and the backend to handle realtime messaging.
- The API layer (backend/server) interacts with the MongoDB database for data persistence and retrieval.
- The backend also calls external services (AWS S3, Firebase, various email services, Google API) as needed.
- Modular components inside the backend (controllers, routers, services, middleware) indicate a separation of concerns where HTTP requests follow a request–response pattern and realtime communications use socket connections.

##### Architectural Patterns and Design Principles

- Separation of Concerns: Clear delineation between the user interfaces (frontend vs. admin-web) and business logic (backend/server controllers and routers).
- Layered Architecture: For backend components (routers handling endpoints, controllers managing business logic, services for external integrations, and models/schemas for data management).
- Realtime Communication: Use of socket.io shows an event-driven pattern for chat and notifications.
- External Integration: Direct connections from the API layer to services like AWS, Firebase, and email providers are critical.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        A1["User Frontend (React/Vite + TailwindCSS)"]:::frontend
        A2["Admin Frontend (React/Vite + Administrative Features)"]:::frontend
    end

    %% Backend API Services
    subgraph "Backend API Services"
        subgraph "API Servers"
            B1["Backend Server (Primary)"]:::backend
            B2["Server API (Secondary)"]:::backend
        end
        subgraph "Core Modules"
            B3["Routers & Controllers"]:::backend
            B4["Middleware & Security"]:::backend
        end
        subgraph "Realtime Communication"
            B5["Socket.io (Backend)"]:::backend
            B6["Socket.io (Server)"]:::backend
        end
        subgraph "Data Management & Email"
            B7["Backend Schemas"]:::backend
            B8["Server Schemas"]:::backend
            B9["Email Services (Backend)"]:::backend
            B10["Email Services (Server)"]:::backend
        end
    end

    %% External Services
    subgraph "External Services"
        E1["MongoDB Database"]:::external
        E2["AWS S3"]:::external
        E3["Firebase"]:::external
        E4["Google APIs"]:::external
    end

    %% Connections: Frontend to Backend (HTTP/REST)
    A1 -->|"HTTP"| B1
    A2 -->|"HTTP"| B2

    %% Connections: Frontend to Realtime Socket Modules
    A1 -->|"Socket"| B5
    A1 -->|"Socket"| B6
    A2 -->|"Socket"| B5
    A2 -->|"Socket"| B6

    %% Internal Backend Communications
    B1 -->|"routes"| B3
    B1 -->|"secures"| B4
    B2 -->|"routes"| B3
    B2 -->|"secures"| B4

    B1 -->|"stores"| B7
    B2 -->|"stores"| B8

    B1 -->|"emails"| B9
    B2 -->|"emails"| B10

    %% Backend to External Services
    B1 -->|"DB"| E1
    B2 -->|"DB"| E1

    B1 -->|"integrates"| E2
    B1 -->|"integrates"| E3
    B2 -->|"integrates"| E4

    %% Click Events
    click A1 "https://github.com/davidchau21/eforum-blog-web/tree/main/frontend/"
    click A2 "https://github.com/davidchau21/eforum-blog-web/tree/main/admin-web/"
    click B1 "https://github.com/davidchau21/eforum-blog-web/blob/main/backend/server.js"
    click B2 "https://github.com/davidchau21/eforum-blog-web/blob/main/server/server.js"
    click B3 "https://github.com/davidchau21/eforum-blog-web/tree/main/backend/router/"
    click B5 "https://github.com/davidchau21/eforum-blog-web/tree/main/backend/socket/"
    click B6 "https://github.com/davidchau21/eforum-blog-web/tree/main/server/socket/"
    click B7 "https://github.com/davidchau21/eforum-blog-web/tree/main/backend/Schema/"
    click B8 "https://github.com/davidchau21/eforum-blog-web/tree/main/server/Schema/"
    click B9 "https://github.com/davidchau21/eforum-blog-web/tree/main/backend/Mail/"
    click B10 "https://github.com/davidchau21/eforum-blog-web/tree/main/server/Mail/"
    click E2 "https://github.com/davidchau21/eforum-blog-web/blob/main/frontend/src/common/aws.jsx"
    click E3 "https://github.com/davidchau21/eforum-blog-web/blob/main/frontend/src/common/firebase.jsx"
    click E4 "https://github.com/davidchau21/eforum-blog-web/tree/main/server/service/"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef backend fill:#ffe0b2,stroke:#ef6c00,stroke-width:2px;
    classDef external fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
```
