A Django REST API backend for a comprehensive inventory management system, supporting both local development and production deployments with JWT authentication.
This backend provides a robust API for managing inventory operations, including categories, suppliers, customers, products, purchase orders, sales orders, stock transactions, and other related functions. It features secure JWT-based authentication, CORS support for frontend integration, and flexible database configurations for different environments.
- JWT Authentication: Secure token-based authentication with refresh tokens
- Inventory Management: Complete CRUD operations for all inventory entities
- Stock Tracking: Real-time stock levels, reorder alerts, and transaction history
- Order Management: Purchase and sales order processing
- Multi-Environment Support: Local (SQLite) and production (PostgreSQL) database configurations
- CORS Enabled: Ready for frontend integration
- Admin Interface: Django admin panel for data management
- API Documentation: RESTful endpoints with proper serialization
- Backend: Django 5.2.5, Django REST Framework
- Authentication: JWT (Simple JWT)
- Database: SQLite (local), PostgreSQL (production)
- Deployment: Gunicorn, WhiteNoise for static files
- Environment Management: python-decouple, django-environ
- Other: CORS headers, psycopg2-binary
-
Clone the repository:
git clone <repository-url> cd inventory_fullstack/backend
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables: Create a
.envfile in the root directory:DJANGO_ENV=local DEBUG=True SECRET_KEY=your-secret-key-here ALLOWED_HOSTS=localhost,127.0.0.1 CORS_ALLOWED_ORIGINS=http://localhost:5173,http://127.0.0.1:5173
For production, set
DJANGO_ENV=productionand add database credentials:DB_NAME=your-db-name DB_USER=your-db-user DB_PASSWORD=your-db-password DB_HOST=your-db-host DB_PORT=5432
-
Run migrations:
python manage.py migrate
-
Create a superuser (optional):
python manage.py createsuperuser
Or use the temporary endpoint:
GET /create-admin/(remove in production) -
Run the development server:
python manage.py runserver
The API will be available at
http://localhost:8000
POST /api/accounts/auth/register/- User registrationPOST /api/accounts/auth/login/- User login (returns access + refresh tokens)POST /api/accounts/auth/refresh/- Refresh access tokenPOST /api/accounts/auth/logout/- Logout (blacklist refresh token)
GET/POST /api/categories/- Category CRUDGET/POST /api/suppliers/- Supplier CRUDGET/POST /api/customers/- Customer CRUDGET/POST /api/products/- Product CRUDGET /api/products/low_stock/- Get products below reorder levelGET/POST /api/purchase-orders/- Purchase order CRUDGET/POST /api/sales-orders/- Sales order CRUD
- Access Django admin at
/admin/(requires superuser login)
- Register a new user or login to get JWT tokens
- Include the access token in the Authorization header for API requests:
Authorization: Bearer <access_token> - Use the refresh token to get new access tokens when they expire
# Login
curl -X POST http://localhost:8000/api/accounts/auth/login/ \
-H "Content-Type: application/json" \
-d '{"username": "your-username", "password": "your-password"}'
# Get products (requires auth)
curl -X GET http://localhost:8000/api/products/ \
-H "Authorization: Bearer <access_token>"- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Make your changes and test thoroughly
- Commit your changes:
git commit -am 'Add your feature' - Push to the branch:
git push origin feature/your-feature - Submit a pull request
For questions or issues, please open an issue on GitHub or contact [jaydeeppatidar2301@gmail.com].