A real-time messaging application built with Next.js, Sendbird UIKit, and PostgreSQL. This application provides a complete chat solution with user profile management and database persistence.
- Real-time Messaging: Powered by Sendbird UIKit for React
- User Profile Management: Edit nickname and profile image with validation
- Database Persistence: PostgreSQL integration for user and channel data
- Event Tracking: Automatic synchronization between Sendbird and database
- Input Validation: Comprehensive validation for user inputs
- Responsive Design: Modern UI with Tailwind CSS
- Node.js 18+
- PostgreSQL database
- Sendbird account and App ID
Create .env.local in the project root:
# Sendbird Configuration for Frontend
NEXT_PUBLIC_SENDBIRD_APP_ID=your_sendbird_app_id_here
NEXT_PUBLIC_SENDBIRD_USER_ID=your_user_id_hereCreate .env in the project root:
# PostgreSQL Database Configuration
DB_HOST=localhost
DB_USER=dev_applicant
DB_PASSWORD=bfEJGCBRYfW1NOiWeGEA
DB_PORT=5432
DB_NAME=FSD_surname
# Sendbird Configuration for Backend
SENDBIRD_APP_ID=your_sendbird_app_id_hereNote: Replace FSD_surname with FSD_ followed by your actual surname.
2. **Install dependencies**
```bash
npm install
-
Configure environment variables (see Environment Setup above)
-
Set up PostgreSQL database
- Ensure PostgreSQL is running
- Create database with name
FSD_<surname> - The application will automatically create required tables on first run
-
Start the development server
npm run dev
-
Open the application
- Navigate to http://localhost:3000 (or the port shown in terminal)
- If environment variables are configured, the app will auto-start with those credentials
- Otherwise, enter your Sendbird App ID and User ID manually
- Start chatting!
This application properly implements the SendbirdProvider to avoid the "No sendbird state value available" error:
- Provider Wrapper:
SendbirdProviderfrom@sendbird/uikit-react/SendbirdProviderwraps the entire chat application - Context Access: All components that use
useSendbirdStateContext()are within the provider tree - Dynamic Loading: Sendbird components are dynamically imported with SSR disabled to prevent window/document issues
- Environment Integration: Automatic configuration using
NEXT_PUBLIC_SENDBIRD_APP_IDandNEXT_PUBLIC_SENDBIRD_USER_ID
The application automatically creates the following tables:
CREATE TABLE users (
user_id VARCHAR(255) PRIMARY KEY,
nickname VARCHAR(255) NOT NULL,
profile_url TEXT,
deleted_flag BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);CREATE TABLE channels (
channel_url VARCHAR(255) PRIMARY KEY,
created_by VARCHAR(255) NOT NULL,
chatmate_id VARCHAR(255),
deleted_flag BOOLEAN DEFAULT FALSE,
message_count INTEGER DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (created_by) REFERENCES users(user_id),
FOREIGN KEY (chatmate_id) REFERENCES users(user_id)
);Create a new user in the database.
Request Body:
{
"user_id": "string",
"nickname": "string",
"profile_url": "string (optional)"
}Update user information.
Request Body:
{
"nickname": "string (optional)",
"profile_url": "string (optional)"
}Create a new channel in the database.
Request Body:
{
"channel_url": "string",
"created_by": "string",
"chatmate_id": "string (optional)"
}Get all channels for a specific user.
Initialize database tables (automatically called on app startup).
- Required: Yes
- Minimum Length: 1 character
- Maximum Length: 30 characters
- Invalid Characters:
< > " ' &
- Required: No (optional)
- Format: Valid HTTP/HTTPS URL
- Supported Extensions: jpg, jpeg, png, gif, webp, svg (when extension is present)
- Required: Yes
- Maximum Length: 255 characters
- Allowed Characters: Letters, numbers, dots, underscores, hyphens
-
User Opens Application
- User enters Sendbird App ID and User ID
- Application initializes database tables
- User is automatically created in database
-
Profile Management
- Click "Edit Profile" in channel list header
- Update nickname and/or profile image URL
- Changes are validated and saved to both Sendbird and database
-
Channel Creation
- Create 1-1 channels through Sendbird UI
- Channel information is automatically saved to database
- Message count defaults to 0
-
Event Synchronization
- All Sendbird events are tracked and synchronized with database
- User creation, updates, and channel creation are persisted
To test the application:
-
User Creation Test
- Open the application with a new User ID
- Verify user is created in database
-
Profile Update Test
- Edit user profile through the UI
- Verify changes are reflected in both Sendbird and database
-
Channel Creation Test
- Create a 1-1 channel
- Verify channel data is stored in database with correct information
- Verify PostgreSQL is running
- Check database credentials in
.env - Ensure database
FSD_<surname>exists
- Verify App ID is correct in environment variables
- Check Sendbird dashboard for app status
- Ensure User ID follows Sendbird naming conventions
- Clear node_modules and reinstall:
rm -rf node_modules && npm install - Check for TypeScript errors:
npm run build
messaging-app/
├── src/
│ ├── app/
│ │ ├── api/ # API routes
│ │ ├── globals.css # Global styles
│ │ ├── layout.tsx # Root layout
│ │ └── page.tsx # Main page
│ ├── components/ # React components
│ ├── hooks/ # Custom hooks
│ ├── lib/ # Utilities and database
│ └── utils/ # Validation utilities
├── .env # Backend environment variables
├── .env.local # Frontend environment variables
└── README.md
- Frontend: Next.js 15, React 19, TypeScript, Tailwind CSS
- Chat: Sendbird UIKit for React
- Database: PostgreSQL with pg client
- Validation: Custom validation utilities
- Styling: Tailwind CSS
This project is for educational/development purposes.