- 📚 Full Documentation
- About
- Key Features
- Architecture and Patterns
- Performance Techniques
- Tech Stack
- Firebase Setup Guide
- Getting Started
- Testing
- Internationalization
- Project Structure
- 🇮🇷 راهنمای فارسی
- 🇩🇪 Deutsche Anleitung
Comprehensive documentation is available in the docs/ directory:
- Architecture Overview — High-level system design and principles
- Layered Architecture — How the codebase is organized
- Design Patterns — Patterns used throughout the project
- Data Flow — How data moves through the application
- Architecture Decision Records — 12 ADRs documenting key decisions
- Firebase Setup — Complete Firebase configuration guide
- Environment Variables — Required and optional configuration
- Testing Guide — How to write and run tests
- Coding Standards — Code style and conventions
- Deployment — Production deployment guide
NexChat is a production-grade, real-time messaging platform engineered with modern software engineering principles. Built on React 18, TypeScript, and Firebase, it demonstrates enterprise-level architecture with Feature-Sliced Design, comprehensive test coverage, and Apple-inspired UI/UX.
This isn't just another chat app—it's a showcase of:
- Clean architecture with strict separation of concerns
- Performance-first development philosophy
- Comprehensive error handling and recovery
- Accessibility and internationalization best practices
- Production-ready code quality standards
- Instant delivery with Firebase Firestore real-time listeners
- Message status indicators (sent, delivered, read) with visual feedback
- Reply/Quote functionality for referencing previous messages
- Link previews for shared URLs with rich metadata
- Search within conversations with real-time filtering
- Google OAuth via Firebase Authentication
- Session management with refresh tokens
- Protected routes with authentication guards
- Stale session detection with persisted state validation
- Automatic session timeout after 24 hours
- Dark mode design with glassmorphism effects
- Responsive layout for mobile, tablet, and desktop
- Smooth animations with CSS cubic-bezier timing
- Accessibility first (ARIA labels, keyboard navigation)
- Multi-language support (English, Persian RTL, German)
- Create, join, leave, and delete chat rooms
- Public and private room types
- Real-time room updates with optimistic UI
- Search and filter rooms with debounced queries
- Member count tracking and activity indicators
NexChat follows Feature-Sliced Design (FSD), a modern architectural methodology that promotes maintainability and scalability. Here are the key patterns and techniques used:
| Pattern | Implementation | Benefit |
|---|---|---|
| Repository Pattern | messagesService, roomsService, authService |
Abstracts Firebase logic, enables easy testing and swapping backends |
| Facade Pattern | useAuth, useRooms, useMessages hooks |
Simplifies complex operations into clean APIs |
| Observer Pattern | Firebase onSnapshot listeners, useAuthListener |
Real-time updates without polling |
| Guard Pattern | AuthGuard component |
Route protection with authentication checks |
| Adapter Pattern | mapFirestoreDocToMessage, mapFirebaseUserToDomain |
Converts between Firebase and domain models |
| Singleton Pattern | Firebase app initialization, i18n instance | Ensures single source of truth for shared resources |
Feature-Sliced Design Layers:
src/
├── app/ # App-level config (providers, error boundaries, routes)
├── pages/ # Application pages (HomePage, LoginPage, ChatPage)
├── features/ # Feature modules (auth, chat, rooms)
├── shared/ # Reusable code (hooks, utils, types, constants)
├── lib/ # External integrations (Firebase, i18n, Sentry)
└── styles/ # Global design system
Key Principles:
- Single Responsibility: Each file has one clear purpose
- Dependency Rule: Upper layers depend on lower layers, never the reverse
- Public API: Features expose only what's needed via
index.ts - Type Safety: Strict TypeScript with discriminated unions
NexChat is engineered for speed and efficiency. Here are the techniques that make it fast:
// Lazy-loaded pages reduce initial bundle size
const HomePage = lazy(() => import('@/pages/HomePage'));
const ChatPage = lazy(() => import('@/pages/ChatPage'));Vite is configured to split vendor bundles optimally:
vendor-react- React core (~40KB gzipped)vendor-firebase-*- Firebase services (loaded on-demand)vendor-mui-*- MUI components (tree-shaken)vendor-i18n- Internationalization (loaded once)
React.memoforMessageBubbleto prevent re-rendersuseMemofor expensive computations (filtering, grouping)useCallbackfor stable function references- Zustand selectors with
useShallowfor granular updates
Using @tanstack/react-virtual for message lists:
const virtualizer = useVirtualizer({
count: groupedItems.length,
getScrollElement: () => parentRef.current,
estimateSize: () => 80,
overscan: 5,
});This ensures smooth scrolling even with thousands of messages.
Search queries and frequent operations are debounced to prevent excessive API calls:
const debouncedSearchQuery = useDebounce(localSearchQuery, 300);- Static gradients instead of animated backgrounds (reduced GPU usage)
will-changeandtransformfor hardware-accelerated animations- Minimal reflows with absolute positioning for virtual items
- Tree-shaking enabled with
moduleSideEffects: false - ES2022 target for modern browser features (smaller polyfills)
- Console removal in production (
console.log,console.debug) - Sourcemap hiding for security while maintaining debuggability
| Category | Technology | Version | Purpose |
|---|---|---|---|
| Core | React | 18.2 | UI library with Hooks and Concurrent Features |
| Language | TypeScript | 5.3 | Type safety and developer experience |
| Build | Vite | 5.1 | Lightning-fast builds with instant HMR |
| Backend | Firebase | 10.8 | Auth, Firestore, Storage |
| State | Zustand | 4.5 | Lightweight client state management |
| Server State | TanStack Query | 5.24 | Caching and async data management |
| Routing | React Router | 6.22 | SPA routing with protected routes |
| UI Framework | MUI | 5.15 | Material Design components |
| Forms | React Hook Form | 7.50 | Performant form handling |
| Validation | Zod | 3.22 | Schema-based validation |
| Virtualization | TanStack Virtual | 3.14 | High-performance list rendering |
| i18n | i18next | 26.4 | Multi-language support |
| Testing | Vitest + RTL | Latest | Unit and integration testing |
| Error Tracking | Sentry | 10.73 | Production error monitoring |
| Code Quality | ESLint + Prettier | Latest | Linting and formatting |
| Pre-commit | Husky + lint-staged | 9.1 | Automated quality checks |
Follow these steps to configure NexChat with your own Firebase project:
- Go to Firebase Console
- Click "Add Project" and follow the setup wizard
- Enable Google Analytics (optional but recommended)
- Once created, click the web icon (
</>) to add a web app - Register your app with a nickname (e.g., "NexChat")
- Copy the configuration object—you'll need these values
- In Firebase Console, navigate to Authentication → Sign-in method
- Click Google and enable it
- Set a Project support email (your email)
- Save the changes
- Navigate to Firestore Database → Create database
- Choose "Start in production mode"
- Select a location closest to your users (e.g.,
us-central1) - Click Enable
Replace the default Firestore rules with these production-ready rules:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper functions
function isAuthenticated() {
return request.auth != null;
}
function isOwner(userId) {
return request.auth.uid == userId;
}
function isRoomMember(roomId) {
return isAuthenticated() &&
request.auth.uid in get(/databases/$(database)/documents/rooms/$(roomId)).data.members;
}
// Users collection
match /users/{userId} {
allow read: if isAuthenticated();
allow create: if isOwner(userId);
allow update: if isOwner(userId);
allow delete: if false; // Prevent deletion
}
// Rooms collection
match /rooms/{roomId} {
allow read: if isAuthenticated() &&
(resource.data.members.hasAny([request.auth.uid]) ||
resource.data.type == 'public');
allow create: if isAuthenticated();
allow update: if isRoomMember(roomId);
allow delete: if isOwner(resource.data.creatorId);
// Messages subcollection
match /messages/{messageId} {
allow read: if isRoomMember(roomId);
allow create: if isRoomMember(roomId) &&
request.resource.data.senderId == request.auth.uid;
allow delete: if isOwner(resource.data.senderId);
allow update: if false; // Messages are immutable
}
}
}
}- Create a
.env.localfile in your project root - Add your Firebase configuration:
VITE_FIREBASE_API_KEY=your_api_key_here
VITE_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=your-project-id
VITE_FIREBASE_STORAGE_BUCKET=your-project.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=your_sender_id_here
VITE_FIREBASE_APP_ID=your_app_id_here
# Optional: Sentry DSN for error tracking
# VITE_SENTRY_DSN=your_sentry_dsn_here.env.local to version control. It's already in .gitignore.
npm install -g firebase-tools
firebase login
firebase init firestore
firebase deploy --only firestore:rules- Node.js 18+ (Download)
- npm 9+ or yarn 1.22+
- A Firebase project (see Firebase Setup)
- Clone the repository
git clone https://github.com/mhalikhani/nexchat.git
cd nexchat- Install dependencies
npm install- Configure environment
cp .env.example .env.local
# Edit .env.local with your Firebase credentials- Start development server
npm run devVisit http://localhost:5173 to see NexChat in action!
| Command | Description |
|---|---|
npm run dev |
Start development server with HMR |
npm run build |
Build for production |
npm run preview |
Preview production build locally |
npm run test |
Run tests in watch mode |
npm run test:coverage |
Generate coverage report |
npm run type-check |
Check TypeScript types |
npm run lint |
Run ESLint |
npm run lint:fix |
Fix ESLint errors automatically |
npm run format |
Format code with Prettier |
NexChat follows a testing-first culture with comprehensive coverage across all layers:
- Unit Tests: Store logic, utility functions, mappers
- Integration Tests: Service layer with mocked Firebase
- Component Tests: UI components with React Testing Library
- Hook Tests: Custom hooks with
renderHook
# Run all tests in watch mode
npm run test
# Run tests once with coverage
npm run test:coverage
# Run specific test file
npm run test src/features/auth/stores/authStore.test.ts- ✅ All stores have 100% action and selector coverage
- ✅ All services test success and error paths
- ✅ Components test user interactions, not implementation details
- ✅ Hooks test lifecycle and cleanup behavior
- ✅ Edge cases and error boundaries are tested
NexChat supports 3 languages with automatic RTL/LTR switching:
| Language | Code | Direction | File |
|---|---|---|---|
| English | en |
LTR | src/locales/en/translation.json |
| Persian (فارسی) | fa |
RTL | src/locales/fa/translation.json |
| German (Deutsch) | de |
LTR | src/locales/de/translation.json |
- Create a new directory:
src/locales/{code}/ - Copy
translation.jsonfrom an existing language - Translate all keys
- Update
src/lib/i18n.ts:
export const supportedLanguages = {
fa: { name: 'فارسی', dir: 'rtl' as const },
en: { name: 'English', dir: 'ltr' as const },
de: { name: 'Deutsch', dir: 'ltr' as const },
// Add your language here
} as const;nexchat/
├── .github/workflows/ # CI/CD pipelines
├── docs/ # Architecture Decision Records (ADRs)
├── public/ # Static assets
│ └── manifest.webmanifest # PWA manifest
├── src/
│ ├── app/ # App-level configuration
│ │ ├── components/ # ErrorBoundary
│ │ └── providers/ # AuthProvider
│ ├── features/ # Feature modules
│ │ ├── auth/ # Authentication
│ │ │ ├── components/ # SignInButton, AuthGuard, EditNameModal
│ │ │ ├── hooks/ # useAuth, useAuthListener
│ │ │ ├── services/ # auth.service, profile.service
│ │ │ ├── stores/ # authStore (Zustand)
│ │ │ ├── types/ # User, AuthError, AuthProvider
│ │ │ └── utils/ # Mappers
│ │ ├── chat/ # Chat functionality
│ │ │ ├── components/ # ChatInput, MessageBubble, MessageList
│ │ │ ├── hooks/ # useMessages, useSendMessage
│ │ │ ├── services/ # messages.service
│ │ │ ├── stores/ # chatStore (Zustand)
│ │ │ ├── types/ # Message, ChatState
│ │ │ └── utils/ # Mappers
│ │ └── rooms/ # Room management
│ │ ├── components/ # RoomList, RoomItem, CreateRoomModal
│ │ ├── hooks/ # useRooms, useCreateRoom, useRoomActions
│ │ ├── services/ # rooms.service
│ │ ├── stores/ # roomsStore (Zustand)
│ │ ├── types/ # Room, RoomType
│ │ └── utils/ # Validators, Mappers
│ ├── lib/ # External integrations
│ │ ├── firebase.ts # Firebase initialization
│ │ ├── i18n.ts # i18next configuration
│ │ ├── sentry.ts # Sentry error tracking
│ │ └── env.ts # Environment validation
│ ├── locales/ # Translation files
│ ├── pages/ # Application pages
│ │ ├── HomePage.tsx # Landing page
│ │ ├── LoginPage.tsx # Authentication page
│ │ └── ChatPage.tsx # Main chat interface
│ ├── shared/ # Reusable code
│ │ ├── constants/ # App-wide constants
│ │ ├── hooks/ # useDebounce
│ │ ├── types/ # Shared types
│ │ └── utils/ # cn, format, validation
│ ├── styles/ # Global styles
│ │ ├── global.css # Design system
│ │ └── theme.ts # MUI theme
│ ├── test/ # Test setup
│ ├── App.tsx # Root component
│ └── main.tsx # Application entry point
├── index.html # HTML template
├── vite.config.ts # Vite configuration
├── vitest.config.ts # Vitest configuration
├── tsconfig.json # TypeScript configuration
└── package.json # Dependencies and scripts
NexChat یک پلتفرم پیامرسان سازمانی نسل جدید است که با React 18، TypeScript و Firebase ساخته شده است. این پروژه با رعایت بهترین شیوههای مهندسی نرمافزار، از جمله معماری Feature-Sliced Design، تستهای جامع و طراحی الهامگرفته از Apple، توسعه یافته است.
- پیامرسانی بلادرنگ: ارسال و دریافت فوری پیامها با نشانگرهای وضعیت (ارسال شده، تحویل داده شده، خوانده شده)
- احراز هویت امن: ورود با Google OAuth و مدیریت نشستها
- طراحی مدرن: رابط کاربری الهامگرفته از Apple با افکتهای شیشهای (Glassmorphism)
- پشتیبانی از چند زبان: انگلیسی، فارسی (RTL) و آلمانی
- مدیریت هوشمند اتاقها: ایجاد، پیوستن، ترک و حذف اتاقهای چت
- عملکرد بالا: بهینهسازیهای پیشرفته برای سرعت و کارایی
- مخزن را کلون کنید:
git clone https://github.com/mhalikhani/nexchat.git
cd nexchat- وابستگیها را نصب کنید:
npm install-
فایل
.env.localرا با اطلاعات Firebase خود پیکربندی کنید -
سرور توسعه را شروع کنید:
npm run dev- الگوی Repository: تمام تعاملات با Firebase از طریق سرویسها انجام میشود
- الگوی Facade: هوکها API سادهای برای عملیات پیچیده ارائه میدهند
- الگوی Observer: بهروزرسانیهای بلادرنگ با استفاده از Firebase listeners
- الگوی Guard: محافظت از مسیرها با بررسی احراز هویت
NexChat ist eine moderne Echtzeit-Nachrichtenplattform, entwickelt mit React 18, TypeScript und Firebase. Das Projekt demonstriert erstklassige Softwareentwicklung mit Feature-Sliced Design Architektur, umfassender Testabdeckung und Apple-inspirierter Benutzeroberfläche.
- Echtzeit-Nachrichten: Sofortige Nachrichtenübermittlung mit Statusanzeigen (gesendet, zugestellt, gelesen)
- Sichere Authentifizierung: Google OAuth mit Sitzungsverwaltung
- Modernes Design: Apple-inspirierte Benutzeroberfläche mit Glassmorphism-Effekten
- Mehrsprachigkeit: Englisch, Persisch (RTL) und Deutsch
- Intelligente Raumverwaltung: Erstellen, Beitreten, Verlassen und Löschen von Chaträumen
- Hohe Leistung: Fortgeschrittene Optimierungen für Geschwindigkeit und Effizienz
- Repository klonen:
git clone https://github.com/mhalikhani/nexchat.git
cd nexchat- Abhängigkeiten installieren:
npm install-
.env.localmit Ihren Firebase-Zugangsdaten konfigurieren -
Entwicklungsserver starten:
npm run dev- Repository Pattern: Alle Firebase-Interaktionen über Services
- Facade Pattern: Hooks bieten einfache APIs für komplexe Operationen
- Observer Pattern: Echtzeit-Updates mit Firebase Listeners
- Guard Pattern: Routenschutz mit Authentifizierungsprüfung
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow Feature-Sliced Design principles
- Write tests for new features
- Ensure TypeScript strict mode compliance
- Use conventional commits for commit messages
- Update documentation as needed
This project is licensed under the MIT License — see the LICENSE file for details.
Built with ❤️ and clean code
If you find this project helpful, please consider giving it a ⭐

