# v06012005/unify architecture

> Architecture diagram of the GitHub repository v06012005/unify, 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/v06012005/unify
- Repository: https://github.com/v06012005/unify

## Overview

##### Main Components
- Frontend Web Application: Represent the client-facing UI built with Next.js. This includes areas for authentication (login, register), profile management, posts pages, messaging, reels, video-calls, and other UI components (admin panels, global components, etc.). Indicate the API routes present in the “frontend/app/api” and “frontend/pages/api” directories.
- Backend Application: Represented by the Spring Boot project. This includes REST controllers (for authentication, posts, notifications, chats, etc.), service layers (business logic for managing posts, media, notifications, chat, etc.), repositories (data access layers for entities such as User, Post, Comment, etc.), and security configurations.
- Database / Data Sources: While there is no explicit SQL configuration file, the Spring Boot project includes a MongoConfig (under springboot/UNIFY/src/main/java/com/app/unify/config/MongoConfig.java) which indicates the use of a NoSQL database. Therefore, include a MongoDB (or similar) component that interacts with the Spring Boot repositories.
- External Services & Integrations: Identify services like Cloudinary integration (noted in “frontend/lib/cloudinary.js”) for media uploads and any Supabase integration (in “frontend/supbaseConfig.js” as well as service implementations in the backend like SupabaseServiceImpl). Other integrations such as external authentication or WebSocket for real-time functionalities (see “WebSocketConfig.java” and “WebSocketEventListener.java”) must also be captured.

##### Out the Relationships and Interactions
- UI Client → Frontend: The client (using a browser or mobile device) loads the Next.js frontend, which is responsible for the presentation layer.
- Backend → External Services: Show REST calls or SDK interactions with external services like Cloudinary (for media storage), email services (for OTP or password reset), and Supabase if applicable.

##### Important Architectural Patterns & Design Principles
- API Gateway / Router: Although not a dedicated microservices gateway, the Next.js frontend’s API routing structure (seen under “frontend/app/api” and "pages/api") demonstrates logical separation of API endpoints.
- WebSocket Integration: Acknowledge real-time communication handling using WebSocket configurations in the backend.
- Security: Include details for authentication and authorization – JWT filters, CustomUserDetailsService, and endpoint security defined in SecurityConfig.java.

##### Relevant Technologies, Frameworks, or Libraries
- Frontend: Next.js, React (as seen in the component structure and pages), Tailwind CSS (tailwind.config.mjs), and client-side libraries like cloudinary, fontawesome.
- Backend: Spring Boot, Spring Security, MongoDB (as configured by MongoConfig.java), and various utility libraries for email (ApacheMailService), JWT (JwtUtil), and Otp management.
- Real-Time & Messaging: WebSocket configuration and controllers for managing chat and call functionalities.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Global Users
    Browser["User (Browser)"]:::external

    %% Frontend Layer
    subgraph "Frontend Layer"
        FE_Main["Main UI (frontend/app)"]:::frontend
        FE_API_App["API (frontend/app/api)"]:::frontend
        FE_API_Pages["API (frontend/pages/api)"]:::frontend
        FE_Auth["Auth UI (frontend/app/(auth))"]:::frontend
        FE_Auth_API["Auth API (frontend/pages/api/auth/[...nextauth].js)"]:::frontend
        FE_Profile["User Profile (frontend/app/(auth)/user-profile)"]:::frontend
        FE_Global["Global Components (frontend/components/global)"]:::frontend
        FE_Posts["Posts Page (frontend/app/(pages)/posts)"]:::frontend
        FE_Reels["Reels Page (frontend/app/(pages)/reels)"]:::frontend
        FE_UploadComp["Upload Media Component (frontend/components/global/UploadMedia.jsx)"]:::frontend
        FE_UploadAPI["Upload API (frontend/app/api/upload/route.js)"]:::frontend
        FE_Messaging["Messaging UI (frontend/app/(pages)/messages)"]:::frontend
        FE_Call["Call UI (frontend/app/(call))"]:::frontend
        FE_Cloudinary["Cloudinary Config (frontend/lib/cloudinary.js)"]:::frontend
        FE_Supabase["Supabase Client (frontend/supbaseConfig.js)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE_Main["Spring Boot App (springboot/UNIFY/src/main/java/com/app/unify/UnifyApplication.java)"]:::backend
        BE_Controllers["REST Controllers (springboot/UNIFY/src/main/java/com/app/unify/controllers)"]:::backend
        BE_Chat["Chat Controllers (springboot/UNIFY/src/main/java/com/app/unify/controllers/chat)"]:::backend
        BE_Services["Service Layer (springboot/UNIFY/src/main/java/com/app/unify/services)"]:::backend
        BE_Security["Security (springboot/UNIFY/src/main/java/com/app/unify/security)"]:::backend
        BE_WebSocket["WebSocket Config (springboot/UNIFY/src/main/java/com/app/unify/config/WebSocketConfig.java)"]:::backend
        BE_WSListener["WebSocket Listener (springboot/UNIFY/src/main/java/com/app/unify/config/WebSocketEventListener.java)"]:::backend
        BE_SupabaseService["Supabase Service (springboot/UNIFY/src/main/java/com/app/unify/services/SupabaseServiceImpl.java)"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        DB_Config["MongoDB Config (springboot/UNIFY/src/main/java/com/app/unify/config/MongoConfig.java)"]:::database
        DB_Repos["Repositories (springboot/UNIFY/src/main/java/com/app/unify/repositories)"]:::database
        DB["MongoDB"]:::database
    end

    %% External Services
    subgraph "External Services"
        EXT_Cloudinary["Cloudinary"]:::external
        EXT_Supabase["Supabase"]:::external
    end

    %% Connections from User to Frontend
    Browser -->|"loads"| FE_Main

    %% Frontend Internal Connections
    FE_Main -->|"navigates to"| FE_Auth
    FE_Main -->|"navigates to"| FE_Posts
    FE_Main -->|"navigates to"| FE_Reels
    FE_Main -->|"navigates to"| FE_Messaging
    FE_Main -->|"navigates to"| FE_Call
    FE_Main -->|"includes"| FE_Global
    FE_Main -->|"includes"| FE_Profile
    FE_Main -->|"calls"| FE_API_App
    FE_Main -->|"calls"| FE_API_Pages
    FE_Main -->|"includes"| FE_UploadComp
    FE_Main -->|"configures"| FE_Cloudinary
    FE_Main -->|"configures"| FE_Supabase

    FE_UploadComp -->|"triggers"| FE_UploadAPI
    FE_Auth -->|"utilizes"| FE_Auth_API

    FE_Cloudinary -->|"communicates with"| EXT_Cloudinary
    FE_Supabase -->|"communicates with"| EXT_Supabase

    %% Frontend to Backend API Calls
    FE_API_App -->|"API call"| BE_Controllers
    FE_API_Pages -->|"API call"| BE_Controllers
    FE_Auth_API -->|"API call"| BE_Controllers
    FE_Posts -->|"API call"| BE_Controllers
    FE_Reels -->|"API call"| BE_Controllers
    FE_UploadAPI -->|"API call"| BE_Controllers
    FE_Messaging -->|"chat call"| BE_Chat
    FE_Call -->|"signal call"| BE_Chat

    %% Backend Internal Connections
    BE_Controllers -->|"delegates to"| BE_Services
    BE_Chat -->|"delegates to"| BE_Services
    BE_Controllers -->|"secured by"| BE_Security
    BE_Services -->|"reads config"| DB_Config
    BE_Services -->|"accesses"| DB_Repos
    DB_Config -->|"connects to"| DB
    DB_Repos -->|"connects to"| DB

    BE_Services -->|"integrates with"| EXT_Cloudinary
    BE_Services -->|"invokes"| BE_SupabaseService
    BE_SupabaseService -->|"calls"| EXT_Supabase

    FE_Messaging -->|"real-time link"| BE_WebSocket
    BE_WebSocket -->|"notifies via"| BE_WSListener

    %% Click Events for Frontend Components
    click FE_Main "https://github.com/v06012005/unify/tree/main/frontend/app"
    click FE_API_App "https://github.com/v06012005/unify/tree/main/frontend/app/api"
    click FE_API_Pages "https://github.com/v06012005/unify/tree/main/frontend/pages/api"
    click FE_Auth "https://github.com/v06012005/unify/tree/main/frontend/app/(auth)"
    click FE_Auth_API "https://github.com/v06012005/unify/blob/main/frontend/pages/api/auth/[...nextauth].js"
    click FE_Profile "https://github.com/v06012005/unify/tree/main/frontend/app/(auth)/user-profile"
    click FE_Global "https://github.com/v06012005/unify/tree/main/frontend/components/global"
    click FE_Posts "https://github.com/v06012005/unify/tree/main/frontend/app/(pages)/posts"
    click FE_Reels "https://github.com/v06012005/unify/tree/main/frontend/app/(pages)/reels"
    click FE_UploadComp "https://github.com/v06012005/unify/blob/main/frontend/components/global/UploadMedia.jsx"
    click FE_UploadAPI "https://github.com/v06012005/unify/blob/main/frontend/app/api/upload/route.js"
    click FE_Messaging "https://github.com/v06012005/unify/tree/main/frontend/app/(pages)/messages"
    click FE_Call "https://github.com/v06012005/unify/tree/main/frontend/app/(call)"
    click FE_Cloudinary "https://github.com/v06012005/unify/blob/main/frontend/lib/cloudinary.js"
    click FE_Supabase "https://github.com/v06012005/unify/blob/main/frontend/supbaseConfig.js"

    %% Click Events for Backend Components
    click BE_Main "https://github.com/v06012005/unify/blob/main/springboot/UNIFY/src/main/java/com/app/unify/UnifyApplication.java"
    click BE_Controllers "https://github.com/v06012005/unify/tree/main/springboot/UNIFY/src/main/java/com/app/unify/controllers"
    click BE_Chat "https://github.com/v06012005/unify/tree/main/springboot/UNIFY/src/main/java/com/app/unify/controllers/chat"
    click BE_Services "https://github.com/v06012005/unify/tree/main/springboot/UNIFY/src/main/java/com/app/unify/services"
    click BE_Security "https://github.com/v06012005/unify/tree/main/springboot/UNIFY/src/main/java/com/app/unify/security"
    click BE_WebSocket "https://github.com/v06012005/unify/blob/main/springboot/UNIFY/src/main/java/com/app/unify/config/WebSocketConfig.java"
    click BE_WSListener "https://github.com/v06012005/unify/blob/main/springboot/UNIFY/src/main/java/com/app/unify/config/WebSocketEventListener.java"
    click BE_SupabaseService "https://github.com/v06012005/unify/blob/main/springboot/UNIFY/src/main/java/com/app/unify/services/SupabaseServiceImpl.java"

    %% Click Events for Database Components
    click DB_Config "https://github.com/v06012005/unify/blob/main/springboot/UNIFY/src/main/java/com/app/unify/config/MongoConfig.java"
    click DB_Repos "https://github.com/v06012005/unify/tree/main/springboot/UNIFY/src/main/java/com/app/unify/repositories"

%% Styles
classDef frontend fill:#cfe2f3,stroke:#6fa8dc,stroke-width:2px;
classDef backend fill:#d9ead3,stroke:#6aa84f,stroke-width:2px;
classDef database fill:#ffe599,stroke:#f1c232,stroke-width:2px;
classDef external fill:#f4cccc,stroke:#e06666,stroke-width:2px;
```
