Skip to content

adilahmetsargin/codespaces-react

Β 
Β 

Repository files navigation

SaaS Dashboard - Production-Ready Frontend

A complete, scalable SaaS Dashboard application built with React, Redux Toolkit, and a mock API layer. This project demonstrates enterprise-level architecture patterns and best practices for modern web applications.

✨ Features

πŸ“Š Dashboard Page

  • KPI Statistics Cards: Real-time metrics (Total Users, Revenue, Active Subscriptions, Growth)
  • Revenue Chart: Interactive 12-month revenue visualization
  • Recent Users Table: Latest user registrations with details
  • Loading States: Skeleton loaders for excellent UX
  • Error Handling: User-friendly error boundaries

πŸ‘₯ Users Management

  • Complete User Listing: Full table with all user details
  • Pagination: Navigate through users efficiently
  • Status Indicators: Visual badges for user status
  • Responsive Design: Mobile and desktop optimized

πŸ” Authentication

  • Login System: Email/password authentication (demo: [email protected] / password)
  • Protected Routes: Guards authenticated pages
  • Session Persistence: Token storage with localStorage
  • Secure Logout: Clean session management

πŸš€ Quick Start

Prerequisites

  • Node.js 16+
  • npm or yarn

Installation & Running

# Install dependencies
npm install

# Start development server
npm start

The app opens at http://localhost:3000/

Demo Credentials

Email:    [email protected]
Password: password

πŸ—οΈ Architecture

This project uses a layered architecture for maximum scalability and maintainability:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   React Components (UI)     β”‚  ← User Interface
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Redux Toolkit (State)      β”‚  ← Predictable State Management
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Services (API Layer)       β”‚  ← Business Logic
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Mock Server / Real API     β”‚  ← Data Source
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Benefits

βœ… Separation of Concerns: Each layer has a single responsibility βœ… Easy Testing: Mock APIs can be replaced without code changes βœ… Scalability: Add new features following the established pattern βœ… Team Friendly: Clear structure for new developers βœ… Backend Agnostic: Works with any REST API

πŸ“ Project Structure

src/
β”œβ”€β”€ app/                    # Redux configuration
β”‚   β”œβ”€β”€ store.js           # Redux store setup
β”‚   └── rootReducer.js     # Combined reducers
β”‚
β”œβ”€β”€ features/              # Domain-based features
β”‚   β”œβ”€β”€ auth/              # Authentication feature
β”‚   β”œβ”€β”€ dashboard/         # Dashboard feature with components
β”‚   └── users/             # Users management feature
β”‚
β”œβ”€β”€ services/              # API layer
β”‚   β”œβ”€β”€ apiClient.js       # Axios configuration
β”‚   └── mockServer.js      # Mock API responses
β”‚
β”œβ”€β”€ pages/                 # Page-level components
β”‚   β”œβ”€β”€ LoginPage.jsx
β”‚   β”œβ”€β”€ DashboardPage.jsx
β”‚   └── UsersPage.jsx
β”‚
β”œβ”€β”€ components/            # Reusable components
β”‚   β”œβ”€β”€ Topbar.jsx
β”‚   β”œβ”€β”€ Sidebar.jsx
β”‚   β”œβ”€β”€ Loader.jsx
β”‚   └── EmptyState.jsx
β”‚
β”œβ”€β”€ styles/               # Global & component styles
β”œβ”€β”€ utils/                # Helper functions
└── App.jsx              # Main routing

πŸ”„ Data Flow

// 1. Component dispatches action
dispatch(fetchDashboardStats())

// 2. Redux Thunk calls service
↓ dashboardService.fetchStats()

// 3. Service calls mock API (or real backend)
↓ mockGetDashboardStats()

// 4. Redux reducer updates state
↓ state.dashboard.stats = data

// 5. Component re-renders with new data
↓ {stats} = useSelector(state => state.dashboard)

πŸ”Œ Replacing Mock APIs with Real Backend

The architecture makes migration to real APIs incredibly simple:

Before: Using Mock API

// dashboardService.js
import { mockGetDashboardStats } from '../../services/mockServer';

export const dashboardService = {
  fetchStats: async () => {
    const result = await mockGetDashboardStats();  // ← Mock
    if (!result.success) throw new Error(result.error);
    return result.data;
  },
};

After: Using Real API

// dashboardService.js
import apiClient from '../../services/apiClient';

export const dashboardService = {
  fetchStats: async () => {
    const response = await apiClient.get('/dashboard/stats');  // ← Real API
    return response.data;
  },
};

That's it! No Redux changes needed. No component changes needed.

πŸ‘‰ See ARCHITECTURE.md for detailed migration guide

🎯 Best Practices Demonstrated

Practice Implementation
Redux Toolkit createSlice, createAsyncThunk, createSelector
Async Operations RTK async thunks with error handling
Loading States Separate loading, success, error states
Error Boundaries Proper try-catch and error messages
Service Layer Single point for API changes
Route Protection ProtectedRoute component for auth
Responsive Design Mobile-first CSS with media queries
Code Organization Feature-based folder structure

πŸ› οΈ Available Scripts

Development

npm start      # Start dev server (runs on port 3000)
npm run build  # Production build
npm run preview # Preview production build
npm test       # Run tests

πŸ“¦ Tech Stack

  • React 18: Modern React with hooks
  • Redux Toolkit: Simplified Redux with best practices
  • React Router v6: Client-side routing
  • Axios: HTTP client with interceptors
  • CSS3: Modern CSS with Grid and Flexbox
  • Vite: Fast build tool

🎨 UI Features

Loading States

  • Skeleton loaders while fetching data
  • Progress indicators
  • Smooth transitions

Error Handling

  • User-friendly error messages
  • Retry mechanisms
  • Error boundaries

Empty States

  • Clear messaging when no data
  • Call-to-action suggestions
  • Consistent design

Responsive Design

  • Desktop: Full-featured layout
  • Tablet: Optimized spacing
  • Mobile: Stack-based layout

πŸ“± Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

πŸ” Security Features

  • βœ… CORS configuration via axios
  • βœ… XSS prevention (React escaping)
  • βœ… Protected routes
  • βœ… Secure token storage (can upgrade to secure httpOnly cookies)
  • βœ… Request/response interceptors

πŸ§ͺ Mock API Endpoints

All endpoints simulate realistic network latency (400-800ms):

Method Endpoint Purpose
POST /auth/login User authentication
GET /dashboard/stats KPI metrics
GET /dashboard/revenue Revenue trends
GET /users User list (paginated)
GET /users/:id Single user
GET /dashboard/recent-users Latest users

πŸ’Ύ State Management Structure

// redux/auth
{
  user: { id, name, email, role },
  isAuthenticated: boolean,
  isLoading: boolean,
  error: null | string
}

// redux/dashboard
{
  stats: { totalUsers, totalRevenue, activeSubscriptions, monthlyGrowth },
  revenueChart: [{ month, revenue }],
  recentUsers: [{ id, name, email, ... }],
  loadingStats: boolean,
  loadingRevenue: boolean,
  loadingRecentUsers: boolean,
  error: null | string
}

// redux/users
{
  list: [{ id, name, email, ... }],
  selectedUser: null | user,
  total: number,
  currentPage: number,
  pageSize: number,
  loading: boolean,
  error: null | string
}

πŸŽ“ Learning Path

  1. Start Here: Understand the architecture in ARCHITECTURE.md
  2. Explore: Navigate through components and Redux slices
  3. Modify: Try adding a new statistic card
  4. Experiment: Replace mock data with real API calls
  5. Deploy: Build and deploy to production

πŸš€ Portfolio Presentation

What to Highlight in Interviews

  1. "I built this with enterprise-level architecture in mind"

    • Redux Toolkit for state management
    • Clear separation of concerns
    • Service layer abstraction
  2. "The mock API layer is production-ready"

    • Can swap real endpoints in minutes
    • Zero Redux/component changes needed
    • Design your own API contract
  3. "This demonstrates real-world best practices"

    • Error handling and loading states
    • Protected authentication
    • Responsive design
    • Accessibility considerations
  4. "It's built for scalability"

    • Easy to add new features
    • Team-friendly codebase
    • Well-documented decisions

πŸ“š Next Steps

  • Add unit tests (Jest + React Testing Library)
  • Implement dark mode
  • Add data export (CSV/PDF)
  • Set up CI/CD pipeline
  • Add international localization (i18n)
  • Implement real WebSocket updates
  • Add advanced filtering/sorting
  • Create admin analytics dashboard

πŸ› Troubleshooting

Port 3000 Already in Use

# Use a different port
PORT=3001 npm start

Dependencies Installation Issues

# Clear npm cache and reinstall
rm -rf node_modules package-lock.json
npm install

Component Not Rendering

  • Check Redux DevTools to see state
  • Verify component is wrapped with <Provider store={store}>
  • Check console for errors

πŸ“ž Support

For questions about the architecture or implementation:

  1. Review ARCHITECTURE.md
  2. Check Redux DevTools in browser for state inspection
  3. Review Redux thunk implementations for async patterns

πŸ“„ License

MIT - Feel free to use this for learning and portfolio projects


Created with ❀️ for modern React development

Ready for production or portfolio showcase ✨

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 69.2%
  • CSS 28.3%
  • HTML 2.5%