# vonhatphuongahihi/vibely-study-social-web architecture

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

- Interactive diagram: https://gitdiagram.com/vonhatphuongahihi/vibely-study-social-web
- Repository: https://github.com/vonhatphuongahihi/vibely-study-social-web

## Overview

##### Main Components
- Frontend Applications:
- “frontend-user”: The primary user-facing Next.js/React application that includes features such as posts, messaging, scheduling, quizzes, and more.
- “frontend-admin”: The administrative portal built with Next.js/React for managing users, posts, study materials, inquiries, and viewing dashboards.
- Backend Application:
- “backend”: A Node.js/Express server that exposes REST APIs for authentication, user management, content (posts, videos, study documents), chat, and other interactions. It includes controllers, middleware, routes, configuration (like connection to MongoDB and Cloudinary), and documentation via Swagger (swagger.yaml).
- Chatbot and AI Integration:
- “chatbot-backend”: A Python-based service that integrates with external AI services (e.g., OpenAI, Hugging Face, Weaviate) and handles AI-related tasks including chat history, processing AI tools and prompts.
- Real-time Communication Service:
- “socket”: A dedicated real-time web socket server (built with Node.js) that likely manages live messaging or notifications.
- Additional Components:
- Database: Although not visible as a file here, the “backend/config/db.js” indicates a MongoDB connection which is a central data store.
- External Services: Cloudinary (for media uploads) as seen in “config/cloudinary.js”, and API documentation/external keys referenced by files in both the Node and Python environments.
- CI/CD & Testing: The “tests” directory with Cypress tests and Dockerfiles in several directories indicate containerization and automated testing setups.

##### Relationships and Interactions
- The backend server is responsible for processing requests such as user authentication, post management, chat messaging, scheduling, etc. It interacts with the MongoDB database.
- The Express backend consults the “swagger.yaml” file in API to document its endpoints and can serve as an API gateway.

##### Architectural Patterns and Technologies
- Modular/Microservices-style Architecture: Each service (user frontend, admin frontend, REST API backend, chatbot-backend, and socket service) is logically isolated yet interacts through defined interfaces.
- MVC Pattern on the Backend: Controllers, models, and routes are clearly separated in the “backend” directory.
- Containerization: Dockerfiles are available in multiple services (backend, frontend-admin, frontend-user, socket) and a docker-compose file is present, suggesting container orchestration.
- Real-time and asynchronous communication: The socket service provides real-time data flow for messaging and notifications.
- RESTful API principles: The structured routes, controllers, and API docs (Swagger) illustrate standard API design.

##### Detailed Elements
- Frontend Components:
- Frontend-User: Include a section for pages that represent chat, posts, scheduling, quizzes, video feed, and social interactions.
- Frontend-Admin: Represent admin functionalities like dashboard, user management, post oversight, etc.
- Backend API:
- Separate logical blocks for authentication (routes and controllers), content management (posts, documents, schedules, quizzes), and administrative operations.
- Middleware layers (authentication, admin authorization).
- A pointer to “swagger.yaml” for API documentation.
- Chatbot-Backend:
- Modules responsible for AI services, including route/service for AI requests (ai_service.py), integration with external ML models, and the supporting tools and database interactions.
- Socket Server:
- Role in handling real-time messaging (using “socket/index.js”) and its interaction with both the backend API and the frontends.
- Infrastructure & DevOps:
- A note for Dockerization: show that each service (frontend, backend, socket) is containerized.
- CI/CD considerations if necessary (pointing to the tests directory and docker-compose file).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE_USER["Frontend-User"]:::frontend
        FE_ADMIN["Frontend-Admin"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE_API["Backend API"]:::backend
        API_DOC["API Documentation (Swagger)"]:::backend
    end

    %% Data & External Services
    subgraph "Data & External"
        DB["Database (MongoDB)"]:::database
        CLOUD["Cloudinary Integration"]:::external
    end

    %% Real-Time & AI Services
    subgraph "Real-Time & AI Services"
        SOCKET["Socket Server"]:::socket
        CHATBOT["Chatbot Service"]:::chatbot
        AI["External AI Providers"]:::external
    end

    %% CI/CD & Testing
    CI_CD["CI/CD & Testing"]:::ciCD

    %% Connections
    FE_USER -->|"calls"| BE_API
    FE_ADMIN -->|"calls"| BE_API
    BE_API -->|"docs-in"| API_DOC
    BE_API -->|"reads/writes"| DB
    BE_API -->|"media"| CLOUD
    BE_API <-->|"real-time"| SOCKET
    BE_API -->|"AIquery"| CHATBOT
    CHATBOT -->|"calls"| AI
    SOCKET -->|"updates"| FE_USER
    SOCKET -->|"updates"| FE_ADMIN
    CI_CD --- FE_USER
    CI_CD --- FE_ADMIN
    CI_CD --- BE_API
    CI_CD --- SOCKET
    CI_CD --- CHATBOT

    %% Click Events
    click FE_USER "https://github.com/vonhatphuongahihi/vibely-study-social-web/tree/main/frontend-user"
    click FE_ADMIN "https://github.com/vonhatphuongahihi/vibely-study-social-web/tree/main/frontend-admin"
    click BE_API "https://github.com/vonhatphuongahihi/vibely-study-social-web/tree/main/backend"
    click CHATBOT "https://github.com/vonhatphuongahihi/vibely-study-social-web/tree/main/chatbot-backend"
    click SOCKET "https://github.com/vonhatphuongahihi/vibely-study-social-web/tree/main/socket"
    click DB "https://github.com/vonhatphuongahihi/vibely-study-social-web/blob/main/backend/config/db.js"
    click CLOUD "https://github.com/vonhatphuongahihi/vibely-study-social-web/blob/main/backend/config/cloudinary.js"
    click API_DOC "https://github.com/vonhatphuongahihi/vibely-study-social-web/blob/main/backend/API/swagger.yaml"
    click CI_CD "https://github.com/vonhatphuongahihi/vibely-study-social-web/tree/main/tests"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef chatbot fill:#FFDAB9,stroke:#000,stroke-width:2px;
    classDef socket fill:#E6E6FA,stroke:#000,stroke-width:2px;
    classDef database fill:#FFFACD,stroke:#000,stroke-width:2px;
    classDef external fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef ciCD fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
