django-vite-react-tailwind-project Tailwind Templates

Django Vite React Tailwind Project

A Web Project with Django Backend, Django-rest API, Vite/ React/ Tailwind frontend

๐Ÿš€โœจ Django Vite React Tailwind Project โœจ๐Ÿš€

A full-stack web application for managing products with ๐Ÿ” User Authentication and Authorization. โœจ Built with Django | Django REST Framework for the backend and Vite | React | Tailwind CSS for the frontend. โšก fully Optimized Code with Fully Responsive Desing for all devices! ๐Ÿ–ฅ๏ธ๐Ÿ“ฑ

๐ŸŒŸ Features

User Authentication

  • ๐Ÿ‘ค Register: Create a new user account.
  • ๐Ÿ”‘ Login: Authenticate and access the system.
  • ๐Ÿšช Logout: Securely log out of the system.

Product Management

  • โž• Add Product: Add a new product to the system.
  • ๐Ÿ—‘๏ธ Delete Product: Remove a product from the system.
  • โœ๏ธ Edit Product: Update product details (only the author can edit).
  • ๐Ÿ‘€ View Products: Browse all products in the system.
  • ๐Ÿ”Ž Search Products: Search products by name, id, description.

Authorization

  • ๐Ÿ”’ Only the author of a product can edit or delete it.
  • ๐Ÿ”“ All users can view the product list

๐Ÿ› ๏ธ Tech Stack

๐Ÿ”™ Backend

  • ๐Ÿ Python: Programming language.
  • ๐ŸŽฏ Django: Web framework.
  • ๐Ÿ”„ Django REST Framework (DRF): For building RESTful APIs.
  • ๐Ÿ” Simple JWT: For JSON Web Token authentication.
  • ๐Ÿ’พ SQLite (Default): Lightweight disk-based database (easily swappable).

๐Ÿ” Frontend

  • โšก Vite: Fast build tool for React.
  • โš›๏ธ React: JavaScript library for building user interfaces.
  • ๐ŸŽจ Tailwind CSS: Utility-first CSS framework for styling.
  • ๐Ÿ”„ Axios: For making HTTP requests to the backend.
  • ๐Ÿ“ฆ Node.js/npm: JavaScript runtime and package manager.

๐Ÿš€ Getting Started

๐Ÿ“‹ Prerequisites

  • ๐Ÿ Python 3.x installed.
  • ๐Ÿ“ฆ Node.js and npm (or yarn) installed.
  • ๐Ÿ’พ Database Setup:
    • The project uses SQLite by default (no extra setup needed).
    • If using PostgreSQL: Ensure PostgreSQL is installed and running. You might also need C++ build tools installed on your system (build-essential on Debian/Ubuntu, Build Tools for Visual Studio on Windows) for the psycopg2 package.

โš™๏ธ Backend Setup

  1. Clone the repository:
git clone https://github.com/kevinThulnith/django-vite-react-tailwind-project.git
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: .\venv\Scripts\activate
  1. Install dependencies:
  • install postgressSQL and c++ buid tool first.
pip install -r requirements.txt
  1. Run migrations:
python manage.py migrate
  1. Start the Django development server:
python manage.py runserver
  1. Access the backend API at:
http://localhost:8000/

โš™๏ธ Frontend Setup

  1. Navigate to the frontend directory:
cd ../frontend
  1. Install dependencies:
npm install
  1. Configure API Base URL:
    • Create a .env file in the frontend directory if it doesn't exist, and set the backend API URL:
VITE_API_BASE_URL=http://localhost:8000
  1. Start the Vite development server:
npm run dev
  1. Access the frontend at:
http://localhost:5173/

๐ŸŒ Hosting on Local Network

To access the application from other devices on your local network:

  1. Get device Ip address

    • Windows: ipconfig (Look for "IPv4 Address" under your active network adapter)
    • macOS: ipconfig getifaddr en0 (or en1 for Wi-Fi)
    • Linux: ip addr show (Look for inet under your active network interface)
  2. Start bachend

py .\manage.py runserver <Device Ip address>:8000
  1. Start frontend

    • change .env file fist
npx vite --host {Device Ip Address}

๐Ÿ“‚ Project Structure

Backend

backend/
โ”œโ”€โ”€ manage.py
โ”œโ”€โ”€ products/
โ”‚   โ”œโ”€โ”€ models.py          # Product model
โ”‚   โ”œโ”€โ”€ serializers.py     # Product serializer
โ”‚   โ”œโ”€โ”€ views.py           # Product views
โ”‚   โ””โ”€โ”€ urls.py            # Product URLs
โ”œโ”€โ”€ users/
โ”‚   โ”œโ”€โ”€ models.py          # User model
โ”‚   โ”œโ”€โ”€ serializers.py     # User serializer
โ”‚   โ”œโ”€โ”€ views.py           # User views
โ”‚   โ””โ”€โ”€ urls.py            # User URLs
โ””โ”€โ”€ settings.py            # Django settings

Frontend

frontend/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ components/        # Reusable components
โ”‚   โ”œโ”€โ”€ pages/             # Pages (Login, Register, Product List, etc.)
โ”‚   โ”œโ”€โ”€ api/               # Axios API calls
โ”‚   โ”œโ”€โ”€ App.jsx            # Main application component
โ”‚   โ””โ”€โ”€ main.jsx           # Entry point
โ”œโ”€โ”€ public/                # Static assets
โ””โ”€โ”€ tailwind.config.js     # Tailwind CSS configuration

๐Ÿ” Authentication Flow

  • Register: A new user provides credentials (e.g., username, email, password) via the frontend form.

  • API Call: Frontend sends a POST request to /api/user/register/.

  • Backend: Creates the new user in the database.

  • Login: User provides login credentials.

  • API Call: Frontend sends a POST request to /api/token/ (Simple JWT endpoint).

  • Backend: Verifies credentials, generates access and refresh JWT tokens, and returns them.

  • Frontend: Stores the tokens (e.g., in local storage or memory) and uses the access token in the Authorization: Bearer <token> header for subsequent protected requests.

  • Protected Routes: Frontend routes/components check for a valid token before rendering. API requests to protected endpoints are validated by the backend using the token.

  • Logout: User clicks logout.

  • API Call: Frontend sends a POST request to /api/token/blacklist/ with the refresh token (optional but good practice).

  • Frontend: Removes tokens from storage, redirecting the user (e.g., to the login page).

๐Ÿ›’ Product Management Flow

  • Edit Product: Only the author of a product can edit its details.
  • Delete Product: Only the author of a product can delete it.
  • Add Product: Authenticated users can add a new product.
  • View Products: All users can view the list of products.
  • Search products: All users can search the list of products.

๐Ÿงช Testing

Backend

  • Run the Django test suite:
python manage.py test

Frontend

  • Run the React tests:
npm test

๐Ÿ“ API Endpoints

Users

  • POST /api/user/register/ - Register a new user.
  • POST /api/token/ - Log in and get an authentication token.
  • POST /api/token/blacklist/ - Log out and invalidate the token.

Products

  • GET /api/products/all/ - Get a list of all products.
  • POST /api/products/ - Add a new product (authenticated users only).
  • GET /api/products/<id>/ - Get details of a specific product.
  • PUT /api/products/update/<id>/ - Update a product (author only).
  • DELETE /api/products/delete/<id>/ - Delete a product (author only).

๐Ÿ“ธ Screenshots

Login Page

Product List

Add Product

Update Product

๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

  • Fork the repository.
  • Create a new branch (git checkout -b feature/YourFeature).
  • Commit your changes (git commit -m 'Add some feature').
  • Push to the branch (git push origin feature/YourFeature).
  • Open a pull request.

๐Ÿ“œ License

This project is licensed under the MIT License. See the LICENSE file for details. ๐Ÿ™ Acknowledgments

  • Django REST Framework for the powerful backend.
  • Vite and React for the blazing-fast frontend.
  • Tailwind CSS for the beautiful and responsive design.

Made with โค๏ธ by Kevin Thulnith ๐Ÿš€ Happy coding! ๐Ÿš€

Top categories

Loading Svelte Themes