A real-time chat application frontend built with React, TypeScript, Vite, and Redux Toolkit. Features JWT authentication, WebSocket connections for real-time messaging, and a responsive Material-UI design.
- React 19
- TypeScript
- Vite
- Redux Toolkit
- Material-UI (MUI)
- STOMP/SockJS
- User registration and login with JWT authentication
- Real-time messaging via WebSocket/STOMP
- Automatic token refresh
- Protected routes
- Responsive design with Material-UI
- Message history
- Type-safe codebase with TypeScript
src/
βββ components/
β βββ auth/
β β βββ AuthHandler.tsx # Authentication provider
β β βββ Login.tsx # Login form
β β βββ Register.tsx # Registration form
β βββ chat/
β β βββ ChatView.tsx # Main chat interface
β β βββ ChatMessage.tsx # Individual message component
β β βββ MessageContainer.tsx # Message list container
β βββ Layout.tsx # Main layout wrapper
β βββ ProtectedRoute.tsx # Route protection
β βββ Sidebar.tsx # Navigation sidebar
β βββ WebSocketHandler.tsx # WebSocket connection management
βββ services/
β βββ Api.tsx # Axios configuration
βββ store/
β βββ store.ts # Redux store configuration
β βββ hooks.ts # Typed Redux hooks
β βββ slices/
β βββ authSlice.ts # Authentication state
β βββ chatViewSlice.ts # Chat messages state
β βββ wsSlice.ts # WebSocket state
βββ style/
β βββ index.css # Global styles
β βββ ChatMessage.css # Message styling
βββ types/
β βββ custom.d.ts # Custom type definitions
βββ vite-env.d.ts # Vite environment types
βββ App.tsx # Main app component
- Node.js (v22 or higher)
- npm or yarn
-
Clone the repository structure
# Create parent directory mkdir chat-application cd chat-application # Clone both repositories git clone <frontend-repository-url> chatapp-react-frontend git clone <backend-repository-url> chatapp-spring-backend
-
Install dependencies
cd chatapp-react-frontend npm install -
Environment Configuration
# Copy example environment file cp .env.example .envConfigure the following variables in
.env:VITE_API_BASE_URL=http://localhost:8080/api/v1 VITE_WS_BASE_URL=http://localhost:8080/ws
-
Start development server
npm run dev
-
Access the application
- Open
http://localhost:5173in your browser
- Open
# From parent directory containing both repos
cd chatapp-spring-backend
docker-compose -f docker-compose.dev.yml up --build# From parent directory containing both repos
cd chatapp-spring-backend
docker-compose up --buildThe API base URL is configured in src/services/Api.tsx:
const api = axios.create({
baseURL: env.VITE_API_BASE_URL,
withCredentials: true
});State management is configured in src/store/store.ts with three main slices:
- authSlice - User authentication and token management
- wsSlice - WebSocket connection state
- chatViewSlice - Chat messages and UI state
Typed hooks are provided in src/store/hooks.ts for type-safe Redux usage:
export const useAppDispatch = () => useDispatch<AppDispatch>();
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;- User registers/logs in via
Login.tsxorRegister.tsx - JWT tokens are received and stored via
AuthHandler - Protected routes are accessed through
ProtectedRoute - Automatic token refresh handles expired access tokens
The application uses WebSocket/STOMP for real-time communication:
- Connection managed by
WebSocketHandler - Messages sent to
/app/chatendpoint - Real-time updates received from
/topic/messages - Message state managed in
chatViewSlice
{
token: string | null,
user: {
email: string | null,
name: string | null,
uid: string | null
},
isValidating: boolean,
}{
chatViewCollection: [{
viewId: number,
title: string,
messages: Message[],
isLoading: boolean,
error: string | null
}]
}{
stompClient: Client | null,
connectionStatus: 'connected' | 'disconnected' | 'connecting' | 'error'
}- Material-UI (MUI) for modern, responsive components
- Custom CSS in
src/style/for chat-specific styling - FontAwesome icons for UI elements
- Dark theme with customizable Material-UI theming
The application is fully responsive with:
- Material-UI Grid system
- Flexible chat container sizing
- Responsive message bubbles
- Adaptive sidebar layout
The main chat interface that handles:
- Message display and input
- WebSocket subscription management
- Real-time message updates
- Send message functionality
Displays chat messages with:
- Auto-scrolling to latest messages
- User/other message differentiation
- Sender name display
Manages authentication state:
- Token storage and validation
- Automatic token refresh
- User session management
- Request/response interceptors
react&react-dom- Core React (v19)@reduxjs/toolkit&react-redux- State managementreact-router-dom- Routingaxios- HTTP requests@stomp/stompjs- WebSocket messagingsockjs-client- SockJS WebSocket fallback@mui/material- Material-UI components@fortawesome/*- Icons
typescript- TypeScript compilervite- Build tooleslint- Code linting@typescript-eslint/*- TypeScript ESLint plugins- Various type definitions (
@types/*)
The application is containerized and deployed using Docker Compose from the backend repository.
-
Build the application
npm run build
-
Deploy the
distfolder to your web server (served by Nginx in production) -
Configure environment variables for production API URLs
-
WebSocket connection fails
- Check backend WebSocket configuration
- Verify CORS settings
- Ensure backend is running
- Check token is properly encoded in WebSocket URL
-
Authentication issues
- Check token expiration
- Verify API endpoints
- Clear browser storage if needed
- Check localStorage for
accessToken
-
Build errors
- Update dependencies
- Check Node.js version compatibility
Additional documentation available in the backend repository:
- Architecture diagrams
- Sequence diagrams
- API integration guides
- Backend Repository - Spring Boot backend application
This project is licensed under the MIT License.
Note: This frontend is designed to work with the corresponding Spring Boot backend. Ensure both applications are running for full functionality.

