How naman1995jain/inventory-manager works
Project type and purpose
• This is a full-stack Inventory Management application:
• Frontend: Next.js (TypeScript + Tailwind) UI for dashboards, product CRUD, auth, real-time updates
• Backend: FastAPI REST API with JWT auth, product/stock management, web scraping, AI-powered recommendations
• Database: PostgreSQL for core data and separate scrapdata table
• AI Service: Uses sentence-transformer embeddings stored on disk for semantic recommendations
• Scripts: CLI scripts for scraping, DB setup, embedding generation
File-structure analysis
• Top-level separation:
• Backend/ – FastAPI app, app/api (routers), app/core (config, DB, security), app/models & schemas, app/services, data & embeddings, scripts, tests
• Frontend/ – Next.js App Router in src/app, reusable UI components, React Context for auth and WebSocket, custom hooks, lib/api client
• Docker & CI-CD files for containerized deployment
• Architectural patterns:
• Backend follows layered architecture: Routers → Services → Models/Database
• Frontend follows component-based UI with context for global state and hooks for real-time (WebSocket) updates
• Deployment artifacts:
• docker-compose.yml and docker-compose.dev.yml orchestrating Frontend, Backend, PostgreSQL, pgAdmin
• Dockerfiles in each service
Key README insights
• Recommendations pipeline: web scraper → scrapdata table → embedding generation → recommendation API
• Real-time stock updates via WebSocket endpoints
Main components
• Frontend client
• Browser running Next.js app
• Key modules: pages (login, dashboard, products, recommendations), components (charts, forms), AuthContext, WebSocketContext
• Backend API service
• FastAPI app (main.py)
• Routers: auth, products, stock_movements, stock_transfers, warehouses, scraped_products, recommendations, websocket
• Core modules: config, database session (SQLAlchemy), security (JWT), permissions
• Services: auth_service, product_service, stock_service, recommendation_service, websocket_manager
• Database
• PostgreSQL instance
• Tables: users, products, warehouses, stock_movements, stock_transfers, scrapdata
• Embeddings files on disk (NumPy .npy and metadata .pkl) under Backend/data/embeddings
• AI Recommendation Engine
• Uses SentenceTransformer model to compute and cache embeddings
• Hybrid recommender combining price, category, description similarities
• Web Scraper
• Python script (scripts/scrape_and_store.py) that respects robots.txt, rate-limits, writes to scrapdata table
• External Services
• External e-commerce sites (target of scraper)
• (Optional) pgAdmin for DB admin
Relationships and interactions
• Browser → HTTP(S) → Next.js frontend
• Frontend → Axios → FastAPI endpoints (/api/v1) for all CRUD, auth, recommendations
• FastAPI → SQLAlchemy → PostgreSQL for reads/writes
• FastAPI recommendation_service → reads embeddings files → computes similarity → returns recommendation payload
• CLI scripts (run manually or as cron) → FastAPI scripts folder → interact with DB and disk to populate scrapdata and embeddings
• WebSocket: Frontend subscribes to websocket endpoint for real-time stock updates; FastAPI websocket_manager broadcasts events
Architectural patterns and principles
• Layered separation: presentation (frontend), API/Routers, services/business logic, data access (models/DB)
• Single-responsibility: each service and router handles a distinct domain
• Stateless backend: JWT tokens for auth, no session state on server
• Event-driven updates: WebSockets for real-time inventory changes
• Data pipeline: ETL for web scraping and AI embedding generation
Capturing essential details
• Explicitly show JWT auth flow: login request, token issuance, protected endpoints with Authorization header
• Where cached embeddings live and how they’re accessed by recommendation_service