How namnguyen1909/hotel-platform works
Project Type and Purpose
• This is a monorepo full-stack Hotel Platform Management System.
• Frontend: React SPA (Vite + Material-UI).
• Backend: Django 5.2.4 REST API (Django REST Framework).
• Purpose: manage rooms, bookings, customers, staff, payments, analytics, and automated tasks.
File Structure
• Top-level directories:
• hotelplatformapi/ → Django project & app (“hotelplatform”).
• hotelplatformweb-vite/ → React frontend.
• render.yaml, DEPLOYMENT.md → deployment configuration.
• Backend modules: models, serializers, views, permissions, signals, admin, management/commands (cron seed).
• Frontend modules: pages/, components/, services/apis.js, hooks/useSmartPolling.js, theme/.
• Config files: .env.example, requirements.txt, package.json (root & frontend), render.yaml.
README Insights
• Monorepo with “npm run dev” to start both servers.
• Core technologies: PostgreSQL, JWT Auth, Cloudinary, VNPay, Smart Polling, Gunicorn, Render.com, Cron-job.org.
• Architectural note: separation of concerns (API vs. UI), automated tasks via external cron, external services.
Main Components
a. Client Layer
• Browser (Desktop/Mobile)
• React SPA (UI components, Router, Axios, Smart-Polling Hook)
b. API Layer
• Django REST Framework
• Authentication (JWT flow)
• Business logic (views.py)
• Serializers & permissions
c. Data Layer
• PostgreSQL database
• Django ORM (models.py)
d. Admin Interface
• Django Admin (static + templates)
e. External Services
• VNPay Payment Gateway
• Cloudinary (media storage)
• cron-job.org (scheduled POST to /api/tasks/update-room-status/)
f. Hosting/Infra
• Render.com (two services: frontend & backend)
• Gunicorn + WhiteNoise (static files)
• Environment Variables (for secrets, CORS, DB URL)
Relationships & Data Flow
• Browser → HTTP(S) to React static assets on Render CDN
• React → REST calls (Axios) → Django API (api/* endpoints)
• Django → ORM → PostgreSQL
• Django → Cloudinary SDK → Cloudinary (upload/download)
• Django → outgoing URL to VNPay and VNPay callback (redirect endpoint)
• cron-job.org → scheduled POST → Django task endpoint → updates room statuses
• Django Admin UI uses internal URLs and static assets served by WhiteNoise
Architectural Patterns & Principles
• Monorepo: unified repo for coordinated releases (package.json scripts)
• MVC on backend: models ↔ views ↔ templates/serializers
• Single-Page Application frontend with service layer and custom hooks
• Explicit separation of UI vs. API vs. Data
• Stateless JWT authentication with role-based permissions
• Smart polling with Page Visibility API for real-time updates
• External cron for scheduled background jobs
Detail Without Overthinking
• Major module (e.g., views.py, serializers.py, management/commands).
• Admin interface separately from the REST API.
• Build & deployment pipeline: concurrently/dev script, npm run build, gunicorn start, Render.com.
• Environment variable usage is noted for secrets injection.