How ducmanhchu/food-selling works
Project type and purpose
• TLU Food is a full-stack web application combining an online food ordering system (“Web” Django app) with a culinary blog (“Blog” Django app).
• The frontend is a React single-page application (SPA) that consumes a Django REST API secured with JWT.
• The README confirms features: product browsing, shopping cart, order placement, user auth, blog CRUD, comments, and an admin dashboard.
File structure
• Top-level “backend” directory is a Django project (TLUfood/) with two apps:
• Blog/ – blog models, serializers, views, templates, migrations.
• Web/ – ordering models (products, orders, cart, payments), serializers, views, migrations.
• backend/manage.py, requirements.txt, import.py, data.json indicate setup, data import, migrations.
• Top-level “frontend” directory is a Vite-powered React project with:
• src/api – Axios wrappers for dishes, orders, users, posts.
• src/components – reusable UI pieces (CartContext, Dish, Post, Review, etc.).
• src/pages – route components (Home, DishDetail, Checkout, Blog, Posting, etc.).
• index.html, vite.config.js, package.json for build and dev configuration.
README for additional insights
• Confirms tech stack: React.js + Bootstrap + React Router + Axios; Django + DRF + JWT + SQLite.
• Mentions modular architecture, responsive design, admin dashboard.
a. Main components
• Client (Browser/Mobile) – React SPA
• Frontend Layer – React components, pages, routing, state management (CartContext)
• API Layer – Axios HTTP client
• Backend Layer – Django REST Framework project comprising:
– Authentication (JWT issuance/validation)
– Blog app (CRUD endpoints for posts & comments)
– Web app (endpoints for products, cart, orders, payments, user profiles)
– Admin site (Django admin UI for managing models)
• Database – SQLite (or configurable RDBMS)
• Static assets hosting (served by Django in production or via CDN)
b. Relationships and interactions
1. User interacts with React SPA in browser → UI triggers React Router navigation & component rendering.
2. SPA uses Axios (src/api/*) to call REST endpoints on Django server (authenticated with JWT in headers).
3. Django Middleware verifies JWT, dispatches to DRF viewsets/serializers in Blog or Web apps.
4. Views perform CRUD on Django ORM models, persist data to SQLite.
5. Responses (JSON) flow back to SPA; state updates (cart, posts, orders).
6. Admin users connect to /admin (Django admin) to manage models directly.
c. Architectural patterns/design principles
• Layered architecture: Presentation (React), Application/API (Django REST), Data (SQLite).
• Separation of concerns: Two Django apps isolate blog vs. ordering logic.
• RESTful API design with serializers and viewsets.
• JWT-based stateless authentication.
• React component hierarchy and Context for global state (CartContext).
d. Relevant technologies/frameworks
• React.js, React Router, Axios, Vite (frontend build)
• Django, Django REST Framework, Django admin (backend)
• JWT Authentication (DRF Simple JWT or custom)
• SQLite (default) – could be PostgreSQL in production
• Bootstrap (CSS framework for responsive UI)