Bash
Overview
The ChatApp Architecture Pipeline
+----------------+ +----------------+ +----------------+
| Frontend | | Backend | | Database |
| (React) | | (Hybrid) | | (MySQL) |
| | | | | |
| Chat UI |<--->| NestJS |<--->| Users |
| File Upload | | Pure Node.js | | Sessions |
| Socket Client | | Socket.IO | | Friends |
+----------------+ +----------------+ +----------------+
Step One: Project Structure
File Structure
chatapp/
├── frontend/
│ ├── src/
│ │ ├── components/
│ │ ├── services/
│ │ │ ├── api.js # API client
│ │ │ └── socket.js # Socket.IO client
│ │ └── App.js # Main application
│ └── package.json
├── backend/
│ ├── src/
│ │ ├── auth/ # Authentication (NestJS)
│ │ ├── upload/ # File upload (NestJS)
│ │ ├── debug/ # Debug tools (NestJS)
│ │ ├── routes/ # API routes (Node.js)
│ │ ├── models/ # Database models
│ │ ├── socket/ # Socket.IO handlers
│ │ └── config/ # Database config
│ ├── uploads/ # File storage
│ │ ├── send/ # Public uploads
│ │ ├── private/ # Private uploads
│ │ └── profile-images/ # Profile pictures
│ └── package.json
└── README.md
Environment Configuration
Bash
Step Two: Hybrid Backend Architecture
NestJS — Structured Concerns
Typescript
Pure Node.js — Real-Time Messaging
Javascript
Step Three: Real-Time Messaging with Socket.IO
Socket Event Reference
Javascript
Sending a Message
Javascript
Typing Indicator
Javascript
Step Four: File Upload System
Supported Formats and Size Limits
Javascript
Storage Organization
uploads/
├── send/ # Files from senders
│ ├── images/
│ ├── videos/
│ ├── audios/
│ └── documents/
├── private/ # Files for receivers
│ ├── images/
│ ├── videos/
│ ├── audios/
│ └── documents/
├── profile-images/ # User avatars
└── thumbnails/ # Generated previews
File Upload with Drag and Drop
Javascript
Step Five: API Endpoints
Authentication
POST /register # Register new user
POST /auto-login # Auto-login with session
GET /check-username # Check username availability
GET /check-phone # Check phone availability
Users and Friends
GET /users # Get all users
GET /search-users # Search users by keyword
POST /friends/add-by-phone # Add friend by phone number
GET /friends # Get friends list
File Upload
POST /upload/message-file # Upload file for messaging
POST /upload/profile-image # Upload profile picture
GET /upload/storage-stats # Get storage statistics
GET /uploads/* # Access uploaded files
Debug and Monitoring
GET /debug/files # File system debug info
GET /debug/storage-stats # Storage statistics
GET /health # System health check
Optimization Tips
Session Persistence with Auto-Login
Javascript
Connection Pooling for MySQL
Javascript