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! π₯οΈπ±
- π€ Register: Create a new user account.
- π Login: Authenticate and access the system.
- πͺ Logout: Securely log out of the system.
- β 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.
- π Only the author of a product can edit or delete it.
- π All users can view the product list
- π 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).
- β‘ 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.
- π 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.
- Clone the repository:
git clone https://github.com/kevinThulnith/django-vite-react-tailwind-project.git
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: .\venv\Scripts\activate
- Install dependencies:
- install postgressSQL and c++ buid tool first.
pip install -r requirements.txt
- Run migrations:
python manage.py migrate
- Start the Django development server:
python manage.py runserver
- Access the backend API at:
http://localhost:8000/
- Navigate to the frontend directory:
cd ../frontend
- Install dependencies:
npm install
- 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
- Start the Vite development server:
npm run dev
- Access the frontend at:
http://localhost:5173/
To access the application from other devices on your local network:
-
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)
-
Start bachend
py .\manage.py runserver <Device Ip address>:8000
-
Start frontend
- change .env file fist
npx vite --host {Device Ip Address}
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/
βββ 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
-
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).
- 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.
- Run the Django test suite:
python manage.py test
- Run the React tests:
npm test
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.
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).
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.
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! π