Skip to content

anhchan22/BTL_python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Industrial Zone Rental Platform

A modern, full-stack web application for managing industrial zone rentals with real-time notifications and multi-image support.

Status Python Django React License


πŸ“‹ Table of Contents


🎯 Features

Core Business Features

  • Industrial Zone Management: Browse, search, and filter available industrial zones
  • Rental Request System: Submit rental requests with customizable area and duration
  • Smart Approval Workflow: Admin approval/rejection with automated contract generation
  • Contract Management: View active and historical rental contracts
  • Real-time Notifications: Instant alerts for request approvals, rejections, and updates

Technical Highlights

  • Multi-Image Upload: Support 1-6 images per zone with preview and management
  • Role-Based Access Control: Separate ADMIN and TENANT interfaces with permission enforcement
  • Real-time Notifications: Polling-based notification system with badge display
  • JWT Authentication: Secure token-based authentication with refresh token support
  • Responsive UI: Neumorphism design system with smooth transitions and hover effects
  • RESTful API: Clean, well-documented API endpoints for all business operations

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    INDUSTRIAL ZONE RENTAL PLATFORM               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚  FRONTEND (React)    β”‚              β”‚  BACKEND (Django)    β”‚ β”‚
β”‚  β”‚  Port: 3000          │◄────HTTP────►│  Port: 8000          β”‚ β”‚
β”‚  β”‚                      β”‚   REST API   β”‚                      β”‚ β”‚
β”‚  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€              β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚
β”‚  β”‚ Components:          β”‚              β”‚ API Endpoints:       β”‚ β”‚
β”‚  β”‚ β€’ Navbar             β”‚              β”‚ β€’ /api/zones/        β”‚ β”‚
β”‚  β”‚ β€’ Zone List/Detail   β”‚              β”‚ β€’ /api/rentals/      β”‚ β”‚
β”‚  β”‚ β€’ Rental Requests    β”‚              β”‚ β€’ /api/contracts/    β”‚ β”‚
β”‚  β”‚ β€’ Contracts          β”‚              β”‚ β€’ /api/notifications/β”‚ β”‚
β”‚  β”‚ β€’ Dashboard          β”‚              β”‚ β€’ /api/auth/         β”‚ β”‚
β”‚  β”‚ β€’ Admin Panel        β”‚              β”‚                      β”‚ β”‚
β”‚  β”‚                      β”‚              β”‚ Models:              β”‚ β”‚
β”‚  β”‚ State Management:    β”‚              β”‚ β€’ User/Profile       β”‚ β”‚
β”‚  β”‚ β€’ AuthContext        β”‚              β”‚ β€’ IndustrialZone     β”‚ β”‚
β”‚  β”‚ β€’ Local State        β”‚              β”‚ β€’ ZoneImage          β”‚ β”‚
β”‚  β”‚ β€’ Polling            β”‚              β”‚ β€’ RentalRequest      β”‚ β”‚
β”‚  β”‚                      β”‚              β”‚ β€’ Contract           β”‚ β”‚
β”‚  β”‚ Styling:             β”‚              β”‚ β€’ Notification       β”‚ β”‚
β”‚  β”‚ β€’ Inline CSS         β”‚              β”‚                      β”‚ β”‚
β”‚  β”‚ β€’ CSS Variables      β”‚              β”‚ Database:            β”‚ β”‚
β”‚  β”‚ β€’ Neumorphism        β”‚              β”‚ β€’ SQLite (dev)       β”‚ β”‚
β”‚  β”‚                      β”‚              β”‚ β€’ PostgreSQL (prod)  β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚          β”‚                                      β”‚                 β”‚
β”‚          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β”‚
β”‚                             β”‚                                     β”‚
β”‚                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”                           β”‚
β”‚                    β”‚  File Storage   β”‚                           β”‚
β”‚                    β”‚  Media/images/  β”‚                           β”‚
β”‚                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                           β”‚
β”‚                                                                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow:
1. User submits rental request β†’ Request stored in DB
2. Admin approves request β†’ Contract created + Notification sent
3. User polls notifications endpoint β†’ Badge updates
4. User views zones β†’ First image displayed from ZoneImage model

πŸ›  Tech Stack

Backend

Layer Technology Version
Framework Django 5.0.1
API Django REST Framework 3.14.0
Authentication djangorestframework-simplejwt 5.3.1
CORS django-cors-headers 4.3.1
Database SQLite (dev) / PostgreSQL (prod) Latest
Language Python 3.9+

Frontend

Layer Technology Version
Framework React 19.2.4
Routing React Router DOM 7.14.0
HTTP Client Axios 1.14.0
Language JavaScript (ES6+) -
Build Tool React Scripts 5.0.1

Design System

  • Neumorphism: Soft UI with elevation and depth
  • CSS Variables: Dynamic theming support
  • Inline Styles: Component-scoped styling for consistency
  • Responsive Design: Mobile-first approach with CSS custom properties

πŸ“ Project Structure

BTL_python/
β”œβ”€β”€ backend/                          # Django REST API
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ models.py                # Database models (User, Zone, RentalRequest, etc.)
β”‚   β”‚   β”œβ”€β”€ views.py                 # API viewsets & endpoints
β”‚   β”‚   β”œβ”€β”€ serializers.py           # Data serialization (request/response)
β”‚   β”‚   β”œβ”€β”€ urls.py                  # API route definitions
β”‚   β”‚   β”œβ”€β”€ admin.py                 # Django admin configuration
β”‚   β”‚   β”œβ”€β”€ permissions.py           # Custom permission classes
β”‚   β”‚   └── migrations/              # Database migration files
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”œβ”€β”€ settings.py              # Django settings (DB, CORS, AUTH)
β”‚   β”‚   β”œβ”€β”€ urls.py                  # Main URL router
β”‚   β”‚   β”œβ”€β”€ wsgi.py                  # WSGI application
β”‚   β”‚   └── asgi.py                  # ASGI application
β”‚   β”œβ”€β”€ requirements.txt             # Python dependencies
β”‚   β”œβ”€β”€ manage.py                    # Django CLI
β”‚   └── media/                       # Uploaded zone images (FileField storage)
β”‚
β”œβ”€β”€ frontend/                         # React application
β”‚   β”œβ”€β”€ public/
β”‚   β”‚   └── index.html               # HTML template
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   β”œβ”€β”€ LoginPage.js         # User login & registration
β”‚   β”‚   β”‚   β”œβ”€β”€ DashboardPage.js     # Main dashboard (contracts/requests)
β”‚   β”‚   β”‚   β”œβ”€β”€ ZoneListPage.js      # Browse zones
β”‚   β”‚   β”‚   β”œβ”€β”€ ZoneDetailPage.js    # Single zone details + images
β”‚   β”‚   β”‚   β”œβ”€β”€ RentalRequestListPage.js  # View rental requests
β”‚   β”‚   β”‚   β”œβ”€β”€ RentalRequestDetailPage.js # Request details & actions
β”‚   β”‚   β”‚   β”œβ”€β”€ ContractListPage.js  # View contracts
β”‚   β”‚   β”‚   β”œβ”€β”€ ZoneFormPage.js      # Admin: create/edit zones
β”‚   β”‚   β”‚   └── ProfilePage.js       # User profile settings
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ Navbar.js            # Navigation with notification badge
β”‚   β”‚   β”‚   β”œβ”€β”€ ZoneCard.js          # Zone card with first image
β”‚   β”‚   β”‚   β”œβ”€β”€ ImageGallery.js      # Multi-image display
β”‚   β”‚   β”‚   β”œβ”€β”€ StatusBadge.js       # Status indicators
β”‚   β”‚   β”‚   β”œβ”€β”€ TablePagination.js   # Table pagination controls
β”‚   β”‚   β”‚   β”œβ”€β”€ ZoneImagePlaceholder.js # Fallback image gradient
β”‚   β”‚   β”‚   └── (other components)
β”‚   β”‚   β”œβ”€β”€ contexts/
β”‚   β”‚   β”‚   └── AuthContext.js       # Authentication state & logic
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”œβ”€β”€ api.js               # Axios instance with interceptors
β”‚   β”‚   β”‚   β”œβ”€β”€ authService.js       # Login/register/logout
β”‚   β”‚   β”‚   β”œβ”€β”€ zoneService.js       # Zone CRUD & search
β”‚   β”‚   β”‚   β”œβ”€β”€ rentalService.js     # Rental request operations
β”‚   β”‚   β”‚   β”œβ”€β”€ contractService.js   # Contract queries
β”‚   β”‚   β”‚   β”œβ”€β”€ notificationService.js # Notification polling
β”‚   β”‚   β”‚   └── imageService.js      # Image upload & management
β”‚   β”‚   β”œβ”€β”€ App.js                   # Main component & routing
β”‚   β”‚   β”œβ”€β”€ index.css                # Global styles & CSS variables
β”‚   β”‚   └── index.js                 # React DOM render
β”‚   β”œβ”€β”€ package.json                 # NPM dependencies
β”‚   └── .env.example                 # Environment template
β”‚
β”œβ”€β”€ docs/                            # Project documentation
β”‚   β”œβ”€β”€ project-overview-pdr.md
β”‚   β”œβ”€β”€ system-architecture.md
β”‚   β”œβ”€β”€ code-standards.md
β”‚   β”œβ”€β”€ design-guidelines.md
β”‚   └── deployment-guide.md
β”‚
└── README.md                        # This file

πŸš€ Quick Start

Prerequisites

  • Python 3.9+ with pip
  • Node.js 16+ with npm
  • PostgreSQL or SQLite (SQLite for development)
  • Git for version control

Backend Setup

# Clone the repository
git clone <repository-url>
cd BTL_python/backend

# Create Python virtual environment
python -m venv .venv

# Activate virtual environment
# On Windows:
.venv\Scripts\activate
# On macOS/Linux:
source .venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Create .env file (optional)
# Copy environment variables as needed

# Run migrations
python manage.py migrate

# Create superuser (admin account)
python manage.py createsuperuser

# Start development server
python manage.py runserver
# Server runs on http://127.0.0.1:8000

Frontend Setup

# Navigate to frontend
cd ../frontend

# Install dependencies
npm install

# Create .env file (optional, if needed)
# REACT_APP_API_URL=http://127.0.0.1:8000

# Start development server
npm start
# App opens at http://localhost:3000

First Steps

  1. Register Account: Create TENANT or ADMIN account on login page
  2. Browse Zones: View available industrial zones with images
  3. Submit Request: Tenants can submit rental requests
  4. Admin Actions: Admins can approve/reject requests (auto-creates contracts)
  5. Track Notifications: Real-time badge shows updates

πŸ“‘ API Documentation

Authentication Endpoints

POST   /api/auth/register/      # User registration
POST   /api/auth/login/         # User login (returns JWT tokens)
POST   /api/auth/logout/        # User logout
GET    /api/auth/me/            # Current user info
PATCH  /api/auth/profile/       # Update user profile

Zone Management

GET    /api/zones/              # List zones (search, filter, paginate)
GET    /api/zones/{id}/         # Zone details + images
POST   /api/zones/              # Create zone (admin only)
PATCH  /api/zones/{id}/         # Update zone (admin only)
DELETE /api/zones/{id}/         # Delete zone (admin only)

Zone Images

GET    /api/zones/{zone_id}/images/      # List zone images
POST   /api/zones/{zone_id}/images/      # Upload image (admin only)
DELETE /api/zones/{zone_id}/images/{id}/ # Delete image (admin only)

Rental Requests

GET    /api/rentals/              # List requests (filtered by user role)
POST   /api/rentals/              # Create rental request (tenant)
GET    /api/rentals/{id}/         # Request details
POST   /api/rentals/{id}/approve/ # Approve (admin only)
POST   /api/rentals/{id}/reject/  # Reject (admin only)
POST   /api/rentals/{id}/cancel/  # Cancel (tenant, if pending)

Contracts

GET    /api/contracts/            # List contracts (filtered by user role)
GET    /api/contracts/{id}/       # Contract details
GET    /api/contracts/my_active/  # Current user's active contracts
GET    /api/contracts/active/     # All active contracts (admin only)

Notifications

GET    /api/notifications/                # List notifications
GET    /api/notifications/unread-count/   # Unread count
POST   /api/notifications/mark-as-read/   # Mark as read
POST   /api/notifications/{id}/mark_single/ # Mark single notification

🎨 Key Features Deep Dive

1. Multi-Image Upload System

Backend (models.py)

  • ZoneImage model: ForeignKey to IndustrialZone
  • ImageField for file storage in /media/images/
  • Min 1, max 6 images per zone enforced at serializer level

Frontend (ZoneFormPage.js)

  • Drag-and-drop image upload
  • Local preview before submission
  • Separate management for existing vs new images
  • Individual delete buttons with confirmation
  • Real-time validation for image count limits

Data Flow

User selects images β†’ FileReader previews β†’ FormData multipart upload
β†’ Django receives β†’ ImageField saves to media β†’ URL returned
β†’ Frontend stores in ZoneImage β†’ Displayed on zone cards/detail

2. Real-time Notification System

Backend (models.py & views.py)

  • Notification model: recipient, actor, verb, target_id, is_read, created_at
  • NotificationViewSet with custom actions:
    • /unread-count/ - Returns unread notification count
    • /mark-as-read/ - Bulk or individual mark as read

Frontend (Navbar.js & notificationService.js)

  • 30-second polling interval to /api/notifications/unread-count/
  • Badge displays unread count (shows "99+" if >99)
  • Auto-clears badge after 5 seconds on page visit
  • Smooth pop animation when new notifications appear

Notification Triggers

Tenant creates rental request β†’ Notification created for Admin
Admin approves request β†’ Notification created for Tenant + Contract created
Admin rejects request β†’ Notification created for Tenant

3. Role-Based Access Control

User Roles

  • ADMIN: Full system access (zones, requests, users, contracts)
  • TENANT: Limited access (own requests, view zones, own contracts)

Permission Enforcement

  • Frontend conditionally renders UI based on isAdmin()
  • Backend decorators enforce permissions at endpoint level
  • API returns 403 FORBIDDEN for unauthorized actions
  • Profile page shows role badge (πŸ‘‘ for admin, πŸ‘€ for tenant)

4. Neumorphism Design System

CSS Variables (globals.css)

--color-background: #f0f2f5;
--color-foreground: #1a1a1a;
--color-accent: #6c63ff;
--shadow-extruded: 10px 10px 20px #d0d5dd, -10px -10px 20px #ffffff;

Component Styling

  • All components use inline styles for scoping
  • Hover states with smooth transitions
  • Consistent border radius via --radius-base and --radius-inner
  • Box shadows for depth and elevation

Benefits

  • Soft, modern aesthetic
  • Improved visual hierarchy
  • Reduced cognitive load (UI feels tactile)
  • Excellent for industrial/professional themes

5. Smart Approval Workflow

Request Lifecycle

PENDING β†’ APPROVED (contract created) or REJECTED
         ↓
APPROVED β†’ Active contract until end date
REJECTED β†’ Tenant notified, can resubmit

Admin Actions

  1. View pending requests in dashboard

  2. Click "Approve" with optional admin note

  3. System auto-creates contract with:

    • Start date: today
    • End date: today + rental_duration months
    • Monthly rent from request calculation
    • Status: ACTIVE
  4. Tenant receives notification immediately

  5. Contract appears in tenant's contract list


πŸ“š Development Standards

Code Organization

  • No TypeScript: Pure JavaScript (ES6+) for simplicity
  • Functional Components: React hooks (useState, useEffect, useCallback)
  • No MUI/Tailwind: Inline styles + CSS variables for complete control
  • Service Layer: Axios services abstract API calls
  • Context API: AuthContext for global state management

File Naming Convention

  • Components: PascalCase (ZoneCard.js, Navbar.js)
  • Pages: PascalCase ending in "Page" (ZoneListPage.js)
  • Services: camelCase (zoneService.js, notificationService.js)
  • Utilities: camelCase (formatPrice.js, validateEmail.js)

Code Style

  • Indentation: 2 spaces
  • Semicolons: Always use
  • Comments: For complex logic only
  • Props: Validate at component level
  • State: Lift state only when necessary

API Service Pattern

// services/zoneService.js
import api from './api';

export const zoneService = {
  getAllZones: async (params) => {
    const { data } = await api.get('/api/zones/', { params });
    return data;
  },
  
  getZoneById: async (id) => {
    const { data } = await api.get(`/api/zones/${id}/`);
    return data;
  }
};

State Management Pattern

// Use local state for component-level data
const [zones, setZones] = useState([]);
const [loading, setLoading] = useState(true);

// Use AuthContext for global auth state
const { user, isAdmin } = useAuth();

// Use effect for data fetching
useEffect(() => {
  loadData();
}, [dependencies]);

πŸ‘₯ Team

Project Lead: Anh TrαΊ§n
Role: Full-stack Developer

Responsibilities:

  • Architecture design and system implementation
  • Backend API development (Django REST Framework)
  • Frontend implementation (React with Neumorphism design)
  • Database design and optimization
  • Documentation and code standards

Contact: trananh22052005@gmail.com


πŸ“„ License

This project is proprietary software. All rights reserved.

Usage Restrictions:

  • Unauthorized copying, modification, or distribution is prohibited
  • Contact project owner for licensing inquiries

🀝 Support & Contributions

For issues, questions, or feature requests:

  1. Check existing documentation in /docs folder
  2. Review API endpoints in this README
  3. Check backend logs: python manage.py runserver (verbose mode)
  4. Check frontend console: Open browser DevTools (F12)

πŸ”— Quick Links


Last Updated: April 2026
Status: Complete & Production Ready

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors