Enterprise-grade B2B perishable supply platform engineered to eliminate food waste and logistics inefficiencies across cold-chain distribution networks.
- Algorithmic FEFO Stock Allocation: First-Expired, First-Out batch picking with row-level database locking (
select_for_update) to prevent race conditions and over-allocation. - Cold-Chain Compliance Tracking: Temperature logging per batch with automated quarantine status triggers upon thermal breach.
- B2B Dynamic Tiered Pricing: Dynamic customer tier discounts (Bronze 0%, Silver 3%, Gold 7%, Platinum 10% on profit margin) with baseline purchase cost protection.
- Automated Wastage & Expiry Markdown: Near-expiry price degradation (30% markdown for items within 48h of expiration) and audited financial wastage scrap accounting.
- Role-Based Access Control (RBAC): Server-side zero-trust authorization enforcing four business roles with SimpleJWT token rotation and blacklisting.
| Layer | Technology | Version |
|---|---|---|
| Backend Framework | Django / Django REST Framework | Django 6.1.2 / DRF 3.15+ |
| Authentication | SimpleJWT with Token Rotation & Blacklisting | 5.3+ |
| Database | SQLite (WAL mode, busy timeout 5000ms) / Turso (libSQL) | 3.x |
| Frontend Framework | Next.js (App Router) | 16.3.8 |
| UI & Styling | React 19, Tailwind CSS 4, Lucide Icons | React 19.2.8 / Tailwind 4.x |
| Data Fetching | Axios singleton (with refresh concurrency queue), TanStack Query | Axios 1.7+ / Query 5.66+ |
| Language & Tooling | TypeScript 5, Biome | TS 5.x / Biome 2.4+ |
freshflow-erp/
├── backend/
│ ├── apps/
│ │ ├── authentication/ # Custom User model, JWT serializers, RBAC permissions
│ │ ├── inventory/ # PerishableItem, StockBatch, TemperatureLog
│ │ ├── crm/ # Restaurant profiles, rolling spend, tier progression
│ │ ├── orders/ # Order, OrderItem, atomic FEFO allocation service
│ │ ├── wastage/ # WastageLog, scrap write-offs, markdown commands
│ │ └── analytics/ # Spoilage metrics, sourcing matrix, KPI views
│ ├── core/ # settings.py, urls.py, wsgi.py
│ ├── manage.py
│ └── requirements.txt
├── frontend/
│ ├── src/
│ │ ├── app/ # Next.js App Router (pages and layouts)
│ │ ├── components/ # UI elements and layout components
│ │ ├── lib/ # api.ts (Axios client with JWT interceptor queue)
│ │ └── types/ # TypeScript data contracts mirroring Django models
│ ├── package.json
│ └── tsconfig.json
├── docs/
│ ├── AUTHENTICATION.md # Technical specification for auth & RBAC
│ └── deliverables.txt # Implementation roadmap and domain logic specifications
├── qna/
│ └── AUTHENTICATION_QNA.md # Defense presentation Q&A preparation guide
└── README.md
The system enforces four distinct personas aligned with cold-chain operations:
| Role | Target Persona | Access Level |
|---|---|---|
ADMIN |
System administrator / business owner | Full system access across all modules |
WAREHOUSE_MANAGER |
Cold storage facility manager | Inventory intake, batch logging, temperature records, wastage logging |
SALES_AGENT |
B2B restaurant account manager | CRM restaurant management, order placement across clients |
RESTAURANT_CLIENT |
B2B restaurant buyer | Read catalog (dynamic tier price), self-service order placement, own order history |
- Python: 3.12+
- Node.js: 18.18+ (Node 20+ recommended)
- Package Manager: npm or pnpm
-
Navigate to the backend directory:
cd backend -
Create and activate a virtual environment:
python3 -m venv ../venv source ../venv/bin/activate -
Install dependencies:
pip install -r requirements.txt
-
Configure environment variables:
cp .env.example .env
Ensure
.envcontains:SECRET_KEY=your-secure-secret-key DEBUG=True ALLOWED_HOSTS=localhost,127.0.0.1 USE_TURSO=False
-
Apply database migrations:
python manage.py migrate
-
Start the development server:
python manage.py runserver 8005
The backend API will be available at
http://127.0.0.1:8005/.
-
Navigate to the frontend directory:
cd frontend -
Install dependencies:
npm install
-
Configure environment variables: Create
.env.local:NEXT_PUBLIC_API_URL=http://localhost:8005/api
-
Start the development server:
npm run dev
The frontend application will be available at
http://localhost:3000/.
GET /api/health/— Service liveness probe
POST /api/auth/token/— Login (returns access token, refresh token, user profile)POST /api/auth/token/refresh/— Refresh access token (with single-use token rotation)POST /api/auth/token/blacklist/— Logout (revokes refresh token)POST /api/auth/register/— Client self-registration (default role:RESTAURANT_CLIENT)GET, PUT /api/auth/profile/— Authenticated user profile inspection and updates
GET, POST /api/inventory/items/— Perishable item definitions and catalogGET, POST /api/inventory/batches/— Stock batch intake with initial temperature loggingPOST /api/inventory/batches/{id}/log_temperature/— Cold-chain compliance temperature check
GET, POST /api/crm/restaurants/— Restaurant client profiles and rolling spend trackingGET /api/crm/restaurants/{id}/tier/— Current discount tier status
POST /api/orders/— Place order (executes transactional FEFO allocation)GET /api/orders/— Order history and fulfillment status
POST /api/wastage/scrap/— Log physical wastage and calculate balance sheet lossGET /api/wastage/logs/— Audit trail of scrap events
GET /api/analytics/kpis/— Executive KPI aggregation (active batches, daily orders, spoilage)GET /api/analytics/supplier-spoilage/— Supplier quality and spoilage rate matrix
cd backend
python manage.py test apps.authenticationcd frontend
npm run typecheck
npm run lint- docs/AUTHENTICATION.md: Complete technical architecture, sequence diagrams, security invariants, and API payload definitions.
- qna/AUTHENTICATION_QNA.md: Comprehensive defense preparation covering 13 sections of supervisor and panel questions.
- docs/deliverables.txt: Full technical roadmap and algorithmic specifications for FEFO allocation and dynamic pricing.
This project is licensed under the MIT License.