# longhainguyen/mobile architecture

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

## Overview

##### Main Components
- Client (Mobile Application):
- User Interface components (various screens/pages like Home, Login, Register, Account, Post, Search, Location, Inform, etc.).
- API layer which is organized in the “client/api” folder containing endpoints for auth, post, comments, search, etc.
- State management through Redux.
- Navigation & Route management.
- Configurations for themes, fonts, and request handling.
- Static assets (images, fonts, videos) and reusable components (alerts, buttons, modals, etc.).

- Server (Backend Application):
- Server Bootstrapping (main.ts, Nest CLI config).
- Core modules:
- Auth Module: Handles authentication (login, register, forgot password) with controllers, DTOs, guards, and strategies (access token strategy using JWT).
- Post Module: Handles creation, editing, and interactions (comments, likes, sharing) for posts.
- User Module: Manages user profiles, following, and user-specific actions.
- Gateway Module: Likely used for real-time notifications, which may involve WebSocket integration.
- Configurations: Database configuration via TypeORM (typeorm.config.ts), JWT settings, Cloudinary configuration (for image and video storage).
- Entities: Defined inside “server/src/entities” representing Comment, Image, Like, Notification, Post, Profile, User, and Video.
- Shared Services: For common functions such as bcrypt hashing and integrations with third-party services (Cloudinary).
- Pipes and Guards: For input validation and authentication flow during API calls.

##### Relationships and Interactions
- The Client communicates with the Server using RESTful API calls defined in the “client/api” folder.
- The API endpoints in the Server map to the various domain areas:
- Authentication triggers the Auth Module controllers.
- Post creation, editing, and feed retrieval are processed by the Post Module.
- User management (registration, profile updates, following, etc.) is handled by the User Module.
- Real-time interactions (notifications, chat feedback, etc.) are facilitated through the Gateway Module.
- All server modules typically interact with a centralized database via TypeORM with entities modeling the social network objects.
- External integrations such as Cloudinary are used for handling media uploads.

##### Architectural Patterns and Design Principles
- The project follows a modular design (typical of NestJS) where each functional domain (auth, post, user, gateway) is encapsulated within its own module.
- Use of DTOs and guards in the server promotes clean API design and secure access control.
- Use of Redux in the client indicates unidirectional data flow, helping to manage state changes predictably.
- Separation of concerns is evident with a distinct front-end and back-end stack.
- Real-Time communication hints towards a layered approach where a dedicated gateway module handles persistent connections (possibly via websockets).

##### Technologies, Frameworks, and Libraries
- Client: React/React Native, Redux, Tailwind CSS (tailwind.config.js), and other UI libraries for components.
- Server: NestJS, TypeORM, JWT for authentication, Cloudinary for media storage, and associated testing frameworks (Jest for tests as seen in spec files).
- Additional integrations: Various utilities and configuration modules that ensure the communication between these layers is seamless.

##### Final Touches
- Use a diagramming tool that allows you to easily adjust and add components as the system evolves.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side"
        direction TB
        UI["User Interface Components"]:::client
        API["API Layer"]:::client
        Redux["State Management (Redux)"]:::client
        Nav["Navigation & Routing"]:::client
        Assets["Assets"]:::client
        Config["Configurations"]:::client
    end

    %% Server Side
    subgraph "Server Side"
        direction TB
        Boot["Bootstrapping & Core Configurations"]:::server
        subgraph "Modules"
            direction TB
            Auth["Auth Module"]:::server
            Post["Post Module"]:::server
            User["User Module"]:::server
            Gate["Gateway Module"]:::server
        end
        DB["Database (TypeORM)"]:::database
        Cloud["Cloudinary Configuration"]:::server
        JWT["JWT Configuration"]:::server
        Entities["Entities"]:::server
        subgraph "Shared Services"
            direction TB
            Bcrypt["Bcrypt Service"]:::server
            CloudModule["Cloudinary Module"]:::server
        end
        Pipes["Pipes & Guards"]:::server
    end

    %% Client to Server Interactions
    API -->|"auth_call"| Auth
    API -->|"post_call"| Post
    API -->|"user_call"| User
    API -->|"realtime_call"| Gate

    %% Server Modules to Shared Resources
    Auth -->|"uses"| DB
    Post -->|"uses"| DB
    User -->|"uses"| DB
    Gate -->|"uses"| DB

    Auth -->|"configures"| JWT
    Auth -->|"validates"| Pipes
    Post -->|"validates"| Pipes
    User -->|"validates"| Pipes
    Gate -->|"validates"| Pipes

    Auth -->|"utilizes"| Bcrypt
    Post -->|"utilizes"| CloudModule
    User -->|"utilizes"| Bcrypt

    Post -->|"uploadsMedia"| Cloud

    %% Real-time communication from Server Gateway to Client UI
    Gate -->|"realTimeUpdates"| UI

    %% Click Events for Client Side
    click UI "https://github.com/longhainguyen/mobile/tree/main/client/app"
    click API "https://github.com/longhainguyen/mobile/tree/main/client/api"
    click Redux "https://github.com/longhainguyen/mobile/tree/main/client/redux"
    click Nav "https://github.com/longhainguyen/mobile/tree/main/client/navigation"
    click Assets "https://github.com/longhainguyen/mobile/tree/main/client/assets"
    click Config "https://github.com/longhainguyen/mobile/tree/main/client/config"

    %% Click Events for Server Side
    click Boot "https://github.com/longhainguyen/mobile/tree/main/server/src"
    click Auth "https://github.com/longhainguyen/mobile/tree/main/server/src/cores/auth"
    click Post "https://github.com/longhainguyen/mobile/tree/main/server/src/cores/post"
    click User "https://github.com/longhainguyen/mobile/tree/main/server/src/cores/user"
    click Gate "https://github.com/longhainguyen/mobile/tree/main/server/src/cores/gateway"
    click DB "https://github.com/longhainguyen/mobile/blob/main/server/src/configs/typeorm.config.ts"
    click Cloud "https://github.com/longhainguyen/mobile/blob/main/server/src/configs/cloudinary.config.ts"
    click JWT "https://github.com/longhainguyen/mobile/blob/main/server/src/configs/jwt.config.ts"
    click Entities "https://github.com/longhainguyen/mobile/tree/main/server/src/entities"
    click Bcrypt "https://github.com/longhainguyen/mobile/tree/main/server/src/share/services/bcrypt"
    click CloudModule "https://github.com/longhainguyen/mobile/tree/main/server/src/share/modules/cloudinary"
    click Pipes "https://github.com/longhainguyen/mobile/tree/main/server/src/pipes"

    %% Styles
    classDef client fill:#bbf,stroke:#333,stroke-width:1px;
    classDef server fill:#fbb,stroke:#333,stroke-width:1px;
    classDef database fill:#dfd,stroke:#333,stroke-width:1px;
```
