How laxmipriyapadegal2024/salespredict-customersegment works
Project Type and Purpose
• This is a full-stack AI-powered web application for sales prediction and customer segmentation.
• Frontend: Next.js (React + TypeScript + TailwindCSS).
• Backend: FastAPI (Python) exposing REST endpoints and running ML pipelines.
• Database: Supabase (PostgreSQL) for metadata, raw data, predictions, and segments.
File Structure
• Top-level:
• docker-compose.yml – Locally orchestrates frontend, backend, and Postgres.
• frontend/ – Next.js app with pages under app/, reusable components, and lib/ for API clients.
• backend/ – FastAPI app with main.py, ml/ (models & preprocessing), routes/ (API endpoints), utils/ (Supabase client, file handling, response models), plus Dockerfile and .env examples.
• sample_data/ – Example CSVs for testing.
• Patterns:
• MVC-style separation: routes (controllers), utils (DB & file handlers), ml (services).
• Containerized services defined in docker-compose.yml.
• Environment-based configuration (.env files).
README for Insights
• Technical stack: Next.js 15, FastAPI, scikit-learn, XGBoost, Supabase.
• API endpoints for upload, sales prediction, segmentation.
• Supabase schema: tables for uploaded_files, sales_data, predictions, customer_data, customer_segments, segment_metadata.
a. Main Components
• User’s Browser / Mobile (UI)
• Next.js Frontend (React pages, components, API & Supabase client)
• FastAPI Backend
• Upload Service (upload_routes.py)
• Sales Prediction Service (sales_routes.py + ml/sales_regression.py + ml/preprocess.py)
• Customer Segmentation Service (segment_routes.py + ml/customer_segmentation.py)
• Database Utils (utils/database.py)
• External Database: Supabase (PostgreSQL)
• Machine Learning Libraries: scikit-learn, XGBoost
• Container Orchestration: Docker (Dockerfiles, docker-compose)
b. Relationships and Interactions
1. User interacts with the Next.js UI.
2. Next.js pages/components call internal API wrappers (lib/api.ts) to reach FastAPI endpoints (via NEXT_PUBLIC_API_URL).
3. FastAPI routes invoke:
• FileHandler to validate and store metadata in Supabase (uploaded_files).
• ML modules to preprocess data, train or predict.
• Database utils to read/write raw data, predictions, segments.
4. FastAPI persists results to Supabase tables.
5. Next.js fetches processed results (predictions, clusters) via API and renders charts (Recharts).
c. Architectural Patterns & Principles
• Layered Architecture: Presentation (Next.js), Application (FastAPI controllers), Business Logic (ML services), Persistence (Supabase).
• Single Responsibility: each route handles one endpoint; ML modules focus on algorithms; utils isolate DB/file concerns.
• Scalability via Docker containers and clear service boundaries.
d. Key Technologies / Frameworks
• Frontend: Next.js, React, TypeScript, TailwindCSS, Recharts, Supabase JS client.
• Backend: FastAPI, Uvicorn, Pydantic, scikit-learn, XGBoost, Supabase Python client.
• Database: Supabase (hosted PostgreSQL).
• Orchestration: Docker, docker-compose.
Essential Architectural Elements
• Environment variables (.env) feeding into Docker container configs.
• Supabase tables relevant to each service (uploaded_files, sales_data, predictions, etc.).
• Where static assets (sample_data, public/) live in the frontend.
• CI/CD/deployment hints (DEPLOYMENT.md, Dockerfiles).
• Don’t over-fragment: group related routes or utils under cohesive service blocks.