# rituparna-ui/eligram-x architecture

> Architecture diagram of the GitHub repository rituparna-ui/eligram-x, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rituparna-ui/eligram-x
- Repository: https://github.com/rituparna-ui/eligram-x

## Overview

##### Project Components Identification
- Frontend (Client): Built with Angular, it leverages Google Material Design. The client folder contains all UI components such as authentication (login, signup, email verification, profile completion), home feed, post components, admin panel features (dashboard, datatable, reports), and user settings. Don’t forget common parts like guards and interceptors for enhanced security and user experience.
- Backend (Server): Constructed with Node.js and Express.js. The server folder includes controllers (admin, auth, post, user), middleware (for authentication, JWT verification, file uploads with Multer, etc.), models (MongoDB schemas for users, posts, reports), and route definitions separating routes for different functionalities.
- Database and Caching:
- MongoDB is used for persistent storage of users, posts, and reports.
- Redis is employed for caching and session management.
- External Services:
- Firebase serves as the file storage solution.
- WebSockets provide real-time communication between users.
- OAuth integrations (Google, Discord) and support for two-factor authentication.
- Additional logging and integration with Telegram for back-office notifications.

##### Relationships and Interactions
- The Angular frontend interacts with the Express-based backend via RESTful APIs.
- The backend uses controllers to handle business logic and then communicates with the MongoDB database.
- Redis serves as a caching layer and as a session manager for user sessions.
- Firebase is used when file uploads (for profile images, posts, etc.) are executed, while WebSocket connections are used for real-time interactions.
- External authentication and integration endpoints (e.g., Discord and Google OAuth) are utilized during the authentication process.
- Common security middleware (JWT verification, role-based access via admin or auth middleware) protects these interactions.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project distinctly separates the client (Angular) and the server (Express) sides, each having their own directory and dependency management.
- Modularization: The Angular app is divided into multiple modules (components for auth, admin, user, misc, and post), while the backend is structured with controllers, middlewares, models, and routes to manage different features.
- Service-Oriented: Both the frontend (services interacting with backend APIs) and backend (services handling file storage, caching, mailing) are built following modular and service-based designs.
- Security Heavy Design: Use of guards, interceptors, encryption, JWT, and OAuth indicates a strong focus on security, which should be distinctly highlighted.

##### Relevant Technologies & Frameworks
- Angular and Material Design in the frontend.
- Node.js, Express.js in the backend.
- MongoDB for data persistence and Redis for caching.
- Firebase, WebSockets, and third-party OAuth integrations (Discord, Google, Telegram).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend (Angular)"
        FE["Angular Frontend"]:::frontend
        Auth["Auth Module"]:::frontend
        Admin["Admin Panel"]:::frontend
        Home["Home Feed"]:::frontend
        Post["Post Components"]:::frontend
        User["User Profile & Settings"]:::frontend
        Guard["Security Guards & Interceptors"]:::frontend
        OAuth1["Discord OAuth"]:::external
        OAuth2["Google OAuth"]:::external
    end

    subgraph "Backend (Express API)"
        BE["Express API Server"]:::backend
        Controllers["Controllers"]:::backend
        Middlewares["Middlewares"]:::backend
        Models["Models"]:::backend
        Routes["Routes"]:::backend
    end

    subgraph "Databases & Caching"
        Mongo["MongoDB Database"]:::database
        Redis["Redis Cache"]:::database
    end

    subgraph "External Services"
        Firebase["Firebase Storage"]:::external
        WebSocket["WebSocket Server"]:::external
        Telegram["Telegram Integration"]:::external
    end

    %% Frontend internal relationships
    FE -->|"Uses"| Auth
    FE -->|"Uses"| Admin
    FE -->|"Uses"| Home
    FE -->|"Uses"| Post
    FE -->|"Uses"| User
    FE -->|"Secured_by"| Guard
    FE -->|"OAuth_Login"| OAuth1
    FE -->|"OAuth_Login"| OAuth2

    %% API communication from Frontend to Backend
    FE -->|"API_Calls"| BE

    %% Backend internal structure
    BE -->|"Executes"| Controllers
    BE -->|"Executes"| Middlewares
    BE -->|"Executes"| Models
    BE -->|"Executes"| Routes

    %% Backend to Databases & Caching
    Controllers -->|"DB_Query"| Mongo
    Controllers -->|"Cache_Session"| Redis
    Middlewares -->|"DB_Query"| Mongo

    %% Backend External Integrations
    BE -->|"File_Uploads"| Firebase
    BE -->|"RealTime_Data"| WebSocket
    BE -->|"Notifications"| Telegram

    %% Click Events
    click FE "https://github.com/rituparna-ui/eligram-x/tree/main/client/src/app"
    click Auth "https://github.com/rituparna-ui/eligram-x/tree/main/client/src/app/components/auth"
    click Admin "https://github.com/rituparna-ui/eligram-x/tree/main/client/src/app/components/admin"
    click Home "https://github.com/rituparna-ui/eligram-x/tree/main/client/src/app/components/home/feed"
    click Post "https://github.com/rituparna-ui/eligram-x/tree/main/client/src/app/components/post"
    click User "https://github.com/rituparna-ui/eligram-x/tree/main/client/src/app/components/user"
    click Guard "https://github.com/rituparna-ui/eligram-x/tree/main/client/src/app/guards"
    click Guard "https://github.com/rituparna-ui/eligram-x/tree/main/client/src/app/interceptors"
    click BE "https://github.com/rituparna-ui/eligram-x/tree/main/server/src"
    click Controllers "https://github.com/rituparna-ui/eligram-x/tree/main/server/src/controllers"
    click Middlewares "https://github.com/rituparna-ui/eligram-x/tree/main/server/src/middlewares"
    click Models "https://github.com/rituparna-ui/eligram-x/tree/main/server/src/models"
    click Routes "https://github.com/rituparna-ui/eligram-x/tree/main/server/src/routes"
    click Routes "https://github.com/rituparna-ui/eligram-x/blob/main/server/src/routes.js"
    click Mongo "https://github.com/rituparna-ui/eligram-x/blob/main/server/src/utls/db/mongo.js"
    click Redis "https://github.com/rituparna-ui/eligram-x/blob/main/server/src/utls/db/redis.js"
    click OAuth1 "https://github.com/rituparna-ui/eligram-x/tree/main/client/src/app/components/auth/discord"
    click OAuth2 "https://github.com/rituparna-ui/eligram-x/tree/main/client/src/app/components/auth/google"

    %% Styles
    classDef frontend fill:#a2d2ff,stroke:#000,stroke-width:2px;
    classDef backend fill:#bde0fe,stroke:#000,stroke-width:2px;
    classDef database fill:#ffafcc,stroke:#000,stroke-width:2px,stroke-dasharray: 5 5;
    classDef external fill:#caffbf,stroke:#000,stroke-width:2px;
```
