How leanstix/micro_commerce works
Project Type & Purpose
• This is a full-stack “micro-commerce” application composed of:
• A React Native client built with Expo (directory: client/)
• A Django + Django REST Framework backend (directory: server/)
• A local SQLite database (server/db.sqlite3) and local media file storage (server/media/)
• Built-in Django Admin UI for product/order management
File Structure & Architectural Patterns
• Top-level directories:
• client/: Expo/React Native app
• server/: Django project (“microcommerce”) + shop app
• client/app/(tabs)/…, client/components/, client/lib/ ⇒ UI screens, shared components, API/session/theme helpers ⇒ Presentation layer
• server/microcommerce/: project settings, URL routing, ASGI/WSGI entry points ⇒ Configuration & core app
• server/shop/: models, serializers, views, auth_views, services (checkout logic), management/commands (seed_shop) ⇒ Business logic layer
• server/docker-compose.yml & Dockerfile ⇒ containerization/deployment
• Patterns:
• REST API layer (DRF)
• JWT authentication + guest cart via X-Session-Key header
• ORM layer → SQLite dev (PostgreSQL in prod)
• File-based media serving via MEDIA_URL/MEDIA_ROOT
• Stateless client, stateful session-key management, merge logic
Main Components
a. Client (Expo React Native)
• Screens: product grid, cart, orders, account, checkout, login/signup/verify
• Helpers: API client (client/lib/api.js), AsyncStorage for tokens & session key, SmartImage (native & web)
b. API Gateway (Django REST Framework)
• Auth endpoints (/api/auth/signup, verify, login, me)
• Products endpoints (/api/products, /api/products/:id)
• Cart endpoints (/api/cart, /api/cart/items)
• Orders endpoints (/api/orders/checkout, /api/orders/me, /api/orders/:id)
• Middleware: CORS, SimpleJWT, session-key merger on every authenticated request
c. Persistence Layer
• Database (SQLite dev / PostgreSQL prod) – models: Product, Cart, CartItem, Order, OrderItem
• Media file storage on disk under server/media/products
d. Admin UI
• Built-in Django Admin (http://…/admin/) for managing Products, Orders, Users
e. External Services (optional)
• Email backend (console in dev, SMTP in prod) for verification links
• Expo asset caching (expo-image)
Relationships & Data Flows
• Client → API:
• All requests include X-Session-Key header; after login, also Authorization: Bearer <JWT>
• Data flows: fetch products → render list; add to cart → POST /api/cart/items; checkout → POST /api/orders/checkout; login/signup flows
• API → Database: ORM queries for CRUD on products, cart items, orders
• API → Media Store: serve product images via MEDIA_URL endpoints
• API → Email Service: send verification link on signup (console backend)
• Admin UI ↔ API: Django Admin views talk directly to ORM & database
Architectural Patterns & Design Principles
• Layered architecture: Presentation (client) / API (Django REST) / Persistence (DB + media)
• Stateless REST with token-based auth + idempotent guest→user cart merging
• Modular code organization: shop app for business logic & DRF serializers/views, management commands for data seeding
• Containerizable via Docker/Docker-Compose for dev & prod parity
Technologies & Frameworks
• Frontend: Expo Router, React Native, expo-image, AsyncStorage, useFocusEffect for tab re-fetch
• Backend: Django, Django REST Framework, djangorestframework-simplejwt, django-cors-headers, Pillow
• DB: SQLite (dev), PostgreSQL (prod)
• Deployment: Docker, docker-compose
Critical Details to Capture
• Guest cart via X-Session-Key header and merge logic on login/each request
• JWT issuance and usage for authenticated flows
• Local media serving via /media/products/... and SmartImage converting relative URLs
• Admin UI bypassing the API layer (direct ORM access) if desired, or show it as part of the API layer
• Docker/Docker-Compose boundary (optional)