Skip to content

BVPritesh/react-crud-demo-project

Repository files navigation

React CRUD Demo Project

A comprehensive React application demonstrating modern web development practices with CRUD operations, authentication, and responsive design. This project serves as a learning resource for building full-featured React applications with TypeScript, Tailwind CSS, and REST API integration.


πŸ“‹ Project Description

This is a full-featured React web application that demonstrates real-world development patterns and best practices. The project implements a complete CRUD (Create, Read, Update, Delete) system for managing posts, with user authentication, protected routes, and a modern responsive UI.

Key Learning Objectives:

  • React Fundamentals: Component composition, hooks, state management, and context API
  • TypeScript Integration: Type-safe development with interfaces, types, and proper error handling
  • Authentication Flow: JWT-like token management with localStorage persistence
  • Protected Routes: Route guards and conditional navigation using React Router
  • API Integration: RESTful API consumption with JSONPlaceholder fake backend
  • Form Handling: Client-side validation, error handling, and user feedback
  • Modern UI: Responsive design with Tailwind CSS and mobile-first approach
  • State Management: Context API for global state and local component state
  • Code Architecture: Clean folder structure and separation of concerns

What You'll Build:

  • User authentication system (sign-in/sign-up)
  • Protected dashboard with CRUD operations
  • Posts management (create, read, update, delete)
  • Responsive navigation with mobile menu
  • Form validation and error handling
  • Toast notifications for user feedback
  • Modern UI with animations and transitions

πŸ›  Tech Stack & Versions

Technology Version Purpose
Node.js 24.x Runtime environment
React 19.1.1 Frontend framework
React Router 7.9.5 Client-side routing
TypeScript 5.9.3 Type-safe JavaScript
Tailwind CSS 4.1.16 Utility-first CSS framework
Vite 7.1.7 Build tool and dev server
ESLint 9.36.0 Code linting and formatting

Additional Dependencies:

  • @types/node: 24.6.0 - Node.js type definitions
  • @types/react: 19.1.16 - React type definitions
  • @vitejs/plugin-react: 5.0.4 - Vite React plugin
  • autoprefixer: 10.4.21 - CSS vendor prefixing

πŸš€ Project Installation Steps

Prerequisites

Ensure you have the following installed on your system:

  • Node.js version 24.x or higher
  • npm or yarn package manager
  • Git for version control

Step 1: Clone the Repository

git clone <your-repository-url>
cd react-crud-demo-project

Step 2: Node Version Management (Recommended)

Using nvm (Node Version Manager):

# Install Node.js 24
nvm install 24
nvm use 24

# Verify installation
node --version  # Should show v24.x.x
npm --version   # Should show compatible npm version

Using volta (Alternative):

# Install and pin Node.js 24
volta install node@24
volta pin node@24

Step 3: Install Dependencies

# Using npm
npm install

# Or using yarn
yarn install

Step 4: Environment Setup (Optional)

Create a .env.local file if you need environment variables:

# Copy example environment file
cp .env.example .env.local

# Edit with your preferred settings
VITE_API_BASE_URL=https://jsonplaceholder.typicode.com

Step 5: Start Development Server

# Start the development server
npm run dev

# Or using yarn
yarn dev

The application will be available at http://localhost:5173 (or the port shown in your terminal).

Step 6: Build for Production

# Create production build
npm run build

# Preview production build locally
npm run preview

πŸ“ Project Folder Structure Understanding

react-crud-demo-project/
β”œβ”€β”€ public/                     # Static assets
β”‚   └── vite.svg               # Vite logo
β”œβ”€β”€ src/                       # Source code directory
β”‚   β”œβ”€β”€ assets/                # Static assets (images, icons)
β”‚   β”‚   └── react.svg          # React logo
β”‚   β”œβ”€β”€ components/            # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ AddEditPost.tsx    # Post form component
β”‚   β”‚   β”œβ”€β”€ footer.tsx         # Footer component
β”‚   β”‚   └── header.tsx         # Navigation header
β”‚   β”œβ”€β”€ config/                # Configuration files
β”‚   β”‚   └── api.ts             # API configuration and endpoints
β”‚   β”œβ”€β”€ contexts/              # React Context providers
β”‚   β”‚   └── AuthContext.tsx    # Authentication context
β”‚   β”œβ”€β”€ hooks/                 # Custom React hooks
β”‚   β”‚   └── useToast.tsx       # Toast notification hook
β”‚   β”œβ”€β”€ layouts/               # Layout components
β”‚   β”‚   └── DefaultLayout.tsx  # Main layout wrapper
β”‚   β”œβ”€β”€ pages/                 # Page components
β”‚   β”‚   β”œβ”€β”€ admin/             # Protected admin pages
β”‚   β”‚   β”‚   └── dashboard.tsx  # Dashboard with CRUD operations
β”‚   β”‚   β”œβ”€β”€ about.tsx          # About page
β”‚   β”‚   β”œβ”€β”€ Home.tsx           # Home page
β”‚   β”‚   β”œβ”€β”€ PageNotFound.tsx   # 404 error page
β”‚   β”‚   β”œβ”€β”€ sign-in.tsx        # Sign-in page
β”‚   β”‚   └── sign-up.tsx        # Sign-up page
β”‚   β”œβ”€β”€ types/                 # TypeScript type definitions
β”‚   β”‚   └── types.ts           # Shared interfaces and types
β”‚   β”œβ”€β”€ utils/                 # Utility functions
β”‚   β”‚   └── validation.ts      # Form validation helpers
β”‚   β”œβ”€β”€ App.css               # Global styles
β”‚   β”œβ”€β”€ App.tsx               # Main App component
β”‚   β”œβ”€β”€ index.css             # Tailwind CSS imports
β”‚   β”œβ”€β”€ main.tsx              # Application entry point
β”‚   └── router.tsx            # React Router configuration
β”œβ”€β”€ .env.example              # Environment variables template
β”œβ”€β”€ .gitignore               # Git ignore rules
β”œβ”€β”€ eslint.config.js         # ESLint configuration
β”œβ”€β”€ index.html               # HTML template
β”œβ”€β”€ package.json             # Project dependencies
β”œβ”€β”€ postcss.config.cjs       # PostCSS configuration
β”œβ”€β”€ README.md                # Project documentation
β”œβ”€β”€ tailwind.config.cjs      # Tailwind CSS configuration
β”œβ”€β”€ tsconfig.json            # TypeScript configuration
β”œβ”€β”€ tsconfig.app.json        # App-specific TypeScript config
β”œβ”€β”€ tsconfig.node.json       # Node-specific TypeScript config
└── vite.config.ts           # Vite configuration

Key Architectural Decisions:

🎯 Component Organization

  • components/: Pure, reusable UI components
  • pages/: Route-specific components with business logic
  • layouts/: Wrapper components for consistent page structure

πŸ”§ Configuration & Setup

  • config/: Centralized API and app configuration
  • contexts/: Global state management with React Context
  • hooks/: Custom hooks for reusable logic

πŸ“ Type Safety

  • types/: Centralized TypeScript interfaces and types
  • utils/: Helper functions and validation logic

🎨 Styling Architecture

  • Tailwind CSS: Utility-first approach for rapid development
  • Component-level: Scoped styles when needed
  • Responsive Design: Mobile-first responsive utilities

✨ Project Features

πŸ” Authentication System

  • Sign In: Email/password authentication with form validation
  • Sign Up: User registration with comprehensive validation
  • Token Management: JWT-like token stored in localStorage
  • Auto-redirect: Automatic navigation based on auth state
  • Session Persistence: Maintains login across browser sessions

πŸ›‘οΈ Protected Routes

  • Route Guards: Automatic redirection for unauthenticated users
  • Conditional Navigation: Different menu options for authenticated/guest users
  • Dashboard Access: Protected admin area with full CRUD functionality

πŸ“Š Dashboard & CRUD Operations

  • Posts Management: Full CRUD operations for blog posts
    • Create: Add new posts with title and content validation
    • Read: Display posts in a clean, organized layout
    • Update: Edit existing posts with pre-populated forms
    • Delete: Remove posts with confirmation prompts
  • Real-time Updates: Optimistic UI updates for immediate feedback
  • Form Validation: Client-side validation with error messages

πŸ“± Responsive User Interface

  • Mobile-First Design: Optimized for all device sizes
  • Navigation Menu: Collapsible mobile menu with smooth animations
  • Header Management: Auto-hiding header on scroll (mobile)
  • Toast Notifications: Success and error feedback system
  • Loading States: Visual feedback during API operations

🎨 Modern UI/UX Features

  • Tailwind CSS: Utility-first styling with custom components
  • Smooth Animations: CSS transitions and hover effects
  • Form Handling: Advanced form state management
  • Error Boundaries: Graceful error handling and user feedback
  • 404 Handling: Custom error pages with navigation options

πŸ”§ Developer Experience

  • TypeScript: Full type safety with interfaces and type checking
  • ESLint: Code quality and consistency enforcement
  • Hot Reload: Instant development feedback with Vite
  • Path Aliases: Clean imports with @/ syntax
  • Build Optimization: Production-ready builds with code splitting

🌐 API Integration

  • JSONPlaceholder: Fake REST API for learning and development
  • HTTP Methods: GET, POST, PUT, DELETE operations
  • Error Handling: Comprehensive API error management
  • Loading States: User feedback during network operations

πŸ“‹ Form Validation Rules

  • Title Validation: Required, letters and spaces only
  • Content Validation: Required, alphanumeric and spaces
  • Email Validation: Proper email format checking
  • Real-time Feedback: Instant validation as user types

🎯 Learning Outcomes

By exploring this project, you will understand:

  1. Modern React Patterns: Hooks, Context API, and functional components
  2. TypeScript Integration: Type-safe development practices
  3. Authentication Flow: Token-based auth with route protection
  4. API Integration: RESTful API consumption and error handling
  5. Form Management: Validation, state management, and user feedback
  6. Responsive Design: Mobile-first CSS with Tailwind
  7. Project Architecture: Clean folder structure and separation of concerns
  8. Build Tools: Modern development setup with Vite

πŸš€ Getting Started

  1. Follow the installation steps above
  2. Start the development server with npm run dev
  3. Open http://localhost:5173 in your browser
  4. Explore the sign-in/sign-up functionality
  5. Access the dashboard to try CRUD operations
  6. Check the Network tab in DevTools to see API calls

πŸ“ API Details

This project uses JSONPlaceholder (https://jsonplaceholder.typicode.com) as a fake REST API:

  • Base URL: https://jsonplaceholder.typicode.com
  • Endpoints: /posts, /users
  • Note: Changes are not persisted on the server (fake backend)

🀝 Contributing

Feel free to fork this project and submit pull requests. This is a learning project, so contributions that enhance the educational value are especially welcome!


πŸ“„ License

This project is open source and available under the MIT License.

About

Create the demo project using rest api integration

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published