# thanhnhat23/lightnoveltrans architecture

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

## Overview

##### Main Components Identification
- Frontend Client (App):
- Code located under “app” with React used to render pages and UI components.
- Contains components (layout, UI components, pages, skeletons), state management (via Zustand in “app/src/store”), and utility libraries (Axios and various style files).
- Uses Vite as a build tool and integrates Tailwind CSS, Sass, and other UI libraries (Swiper, Motion, Daisy UI, Ant Design, Lucide react).
- Backend Server:
- Code under “server” built using Express, with controllers handling business logic (auth, message, post, and user) and routes to expose API endpoints.
- Models that define MongoDB schemas (message, post, user).
- Middleware for authentication (using JWT), and integration of real‑time components (via Socket.io in the “server/src/lib/socket.js”).
- Helper libraries for connecting to the database (“server/src/lib/db.js”), handling Cloudinary image uploads, and mail functionalities using Mailtrap.
- Database:
- The README indicates usage of MongoDB.
- External Services:
- Cloudinary for storing images.
- Mailtrap for handling outgoing emails.
- Socket.io: Managing real‑time messaging and online user status.

##### Relationships and Interactions
- The Frontend (React) communicates with the Backend through REST API endpoints (as defined by routes in “server/src/routes”) for functionalities such as authentication, posting translations, and handling user profiles.
- WebSocket connections (via Socket.io) enable real‑time messaging, allowing the frontend to receive live updates.
- Authentication uses JWT tokens where the backend validates user sessions for secured routes.
- Image uploads from the frontend are handled by the backend, with integration to Cloudinary.
- When actions (like signing up or password resets) occur, the backend routes utilize Mailtrap components to send emails.

##### Architectural Patterns and Design Principles
- Layered Architecture:
- Presentation Layer (Frontend React app)
- Application/Business Logic Layer (Express controllers and middleware)
- Data Access Layer (Models and MongoDB interactions)
- Integration Layer (External services for email and image processing)
- MVC Pattern on the server side:
- Controllers, Models, and Routes are clearly separated.
- Use of State Management:
- The frontend leverages Zustand for global state management.
- Real‑time Communication:
- Integration of WebSockets (Socket.io) for chat and user status features.

##### Including Relevant Technologies
- Frontend: React, Vite, Sass, Tailwind CSS, Zustand, Axios, and various UI libraries (Swiper, Motion, Daisy UI, etc.)
- Backend: Node.js, Express, MongoDB, JWT, Socket.io, and integration libraries for Cloudinary and Mailtrap.
- Additional: Use of ESLint (via “eslint.config.js”), PostCSS configurations, and build/deployment scripts (pnpm, npm).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "Frontend Client (React App)"
        FE1["React App"]:::frontend
        FE2["UI Components"]:::frontend
        FE3["Pages"]:::frontend
        FE4["Global State (Zustand)"]:::frontend
        FE5["Axios"]:::frontend
        FE6["Utils"]:::frontend
        FE7["Styles"]:::frontend
    end

    %% Backend Subgraph
    subgraph "Backend Server (Express API)"
        BE1["Express API Server"]:::backend
        BE2["API Routes"]:::backend
        BE3["API Controllers"]:::backend
        BE4["Authentication Middleware"]:::backend
        BE5["MongoDB Models"]:::backend
        BE6["Database Connection Helper"]:::backend
        BE7["Real‑time Messaging (Socket.io)"]:::backend
        BE8["Cloudinary Integration"]:::backend
        BE9["Mailtrap Integration"]:::backend
    end

    %% External Services
    E1["MongoDB Database"]:::external
    E2["Cloudinary Service"]:::external
    E3["Mailtrap Service"]:::external

    %% Internal Frontend Connections
    FE1 -->|"renders"| FE2
    FE1 -->|"renders"| FE3
    FE1 -->|"managesState"| FE4
    FE1 -->|"calls"| FE5
    FE1 -->|"uses"| FE6
    FE1 -->|"applies"| FE7

    %% Internal Backend Connections
    BE1 -->|"handles"| BE2
    BE2 -->|"calls"| BE3
    BE3 -->|"authCheck"| BE4
    BE3 -->|"dataOps"| BE5
    BE6 -->|"connectsTo"| BE5
    BE1 -->|"integratesRT"| BE7
    BE3 -->|"uploadImage"| BE8
    BE3 -->|"sendEmail"| BE9

    %% Frontend to Backend Leaf Connections
    FE1 -->|"RESTAPI"| BE1
    FE1 <-->|"WebSocket"| BE7

    %% Backend to External Services Connections
    BE5 -->|"CRUD"| E1
    BE6 -->|"dbConnect"| E1
    BE8 -->|"storesImage"| E2
    BE9 -->|"emailSend"| E3

    %% Click Events for Frontend Components
    click FE1 "https://github.com/thanhnhat23/lightnoveltrans/tree/main/app/"
    click FE2 "https://github.com/thanhnhat23/lightnoveltrans/tree/main/app/src/components"
    click FE3 "https://github.com/thanhnhat23/lightnoveltrans/tree/main/app/src/pages"
    click FE4 "https://github.com/thanhnhat23/lightnoveltrans/tree/main/app/src/store"
    click FE5 "https://github.com/thanhnhat23/lightnoveltrans/blob/main/app/src/lib/axios.js"
    click FE6 "https://github.com/thanhnhat23/lightnoveltrans/tree/main/app/src/utils"
    click FE7 "https://github.com/thanhnhat23/lightnoveltrans/tree/main/app/src/styles"

    %% Click Events for Backend Components
    click BE1 "https://github.com/thanhnhat23/lightnoveltrans/tree/main/server/"
    click BE2 "https://github.com/thanhnhat23/lightnoveltrans/tree/main/server/src/routes"
    click BE3 "https://github.com/thanhnhat23/lightnoveltrans/tree/main/server/src/controllers"
    click BE4 "https://github.com/thanhnhat23/lightnoveltrans/blob/main/server/src/middleware/auth.middleware.js"
    click BE5 "https://github.com/thanhnhat23/lightnoveltrans/tree/main/server/src/models"
    click BE6 "https://github.com/thanhnhat23/lightnoveltrans/blob/main/server/src/lib/db.js"
    click BE7 "https://github.com/thanhnhat23/lightnoveltrans/blob/main/server/src/lib/socket.js"
    click BE8 "https://github.com/thanhnhat23/lightnoveltrans/blob/main/server/src/lib/cloudinary.js"
    click BE9 "https://github.com/thanhnhat23/lightnoveltrans/tree/main/server/src/mailtrap"

    %% Styles
    classDef frontend fill:#add8e6,stroke:#000,stroke-width:1.5px;
    classDef backend fill:#f08080,stroke:#000,stroke-width:1.5px;
    classDef external fill:#90ee90,stroke:#000,stroke-width:1.5px;
```
