A full-stack business management system with an Admin Dashboard (Next.js) and a Salesman Mobile App (Flutter), connected via a shared PostgreSQL backend.
- Overview
- Architecture
- Tech Stack
- Features
- Database Schema
- API Endpoints
- Getting Started
- Environment Variables
- Building for Production
- Project Structure
- Contributing
- License
FlowTech is an end-to-end agency/distribution management platform designed for small-to-medium FMCG distributors. It digitizes the entire workflow from order placement by field salesmen to approval by admins, stock management, invoicing, and payment tracking.
The system consists of two main applications:
| Application | Technology | Purpose |
|---|---|---|
| Admin Dashboard | Next.js 16 (App Router) | Web-based admin panel for managing orders, inventory, shops, salesmen, and reports |
| Salesman Mobile App | Flutter (Android/iOS) | Field sales app for placing orders, managing shops, generating invoices, and recording payments |
Both applications share a single PostgreSQL database hosted on Supabase and communicate through a RESTful API layer.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENTS β
β β
β βββββββββββββββββββ ββββββββββββββββββββββββ β
β β Admin Dashboard β β Salesman Mobile App β β
β β (Next.js 16) β β (Flutter + Riverpod) β β
β β Vercel Hosted β β Android APK β β
β ββββββββββ¬βββββββββ ββββββββββββ¬ββββββββββββ β
β β β β
ββββββββββββββΌββββββββββββββββββββββββββββββββΌβββββββββββββββββββ
β Server Actions & β REST API
β Server Components β /api/mobile/*
βΌ βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BACKEND (Next.js API) β
β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β Server β β API Routes β β Middleware β β
β β Actions β β /api/mobile β β (Auth Guard) β β
β β (orders.ts) β β /api/deliveryβ β Role-Based β β
β ββββββββ¬ββββββββ ββββββββ¬ββββββββ ββββββββββββββββ β
β β β β
β βΌ βΌ β
β ββββββββββββββββββββββββββββββββ β
β β Drizzle ORM β β
β β (Type-safe SQL) β β
β ββββββββββββββββ¬ββββββββββββββββ β
ββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DATABASE β
β PostgreSQL (Supabase) β
β β
β users Β· shops Β· products Β· product_variants β
β orders Β· order_items Β· payments Β· stock_ledger β
β suppliers Β· notifications Β· sessions β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Layer | Technology |
|---|---|
| Framework | Next.js 16 (App Router, React 19 RC) |
| Language | TypeScript |
| Styling | Tailwind CSS 3.4 |
| UI Components | shadcn/ui (Radix UI primitives) |
| Charts | Recharts |
| ORM | Drizzle ORM |
| Authentication | BetterAuth (email/password) |
| Database | PostgreSQL (Supabase) |
| PDF Generation | jsPDF + jspdf-autotable |
| CSV Import | PapaParse |
| Forms | React Hook Form + Zod validation |
| Hosting | Vercel |
| Layer | Technology |
|---|---|
| Framework | Flutter 3.x |
| Language | Dart |
| State Management | Riverpod (StateNotifier) |
| Routing | GoRouter |
| Local Storage | SharedPreferences |
| PDF Generation | dart pdf package |
| Sharing | printing package (native share sheet) |
| Networking | http package |
| Icons | Lucide Icons |
| Fonts | Google Fonts |
| Feature | Description |
|---|---|
| Dashboard Overview | Real-time stats β Total Revenue, Pending Orders, Today's Orders, Pending Payments, Stock Levels |
| Revenue Chart | Monthly revenue visualization (Recharts) with dark mode tooltip support |
| Recent Sales | Live feed of latest approved/delivered orders (auto-excludes rejected) |
| Order Management | View all orders, approve/reject with one click, auto-notify salesmen |
| Inventory System | Products with variants (SKU, price, stock), CSV bulk import, stock-in dialogs |
| Stock Ledger | Full audit trail of every stock movement (stock-in, orders, adjustments) |
| Invoice Generation | PDF invoices with GST breakdown (CGST/SGST), company branding, download support |
| Supplier Management | CRUD operations for suppliers, link suppliers to products |
| Shop Management | Track shops, outstanding balances, active/inactive status |
| Salesman Management | Manage field sales team accounts and assign areas |
| Payment Tracking | Monitor paid/unpaid orders, outstanding balances per shop |
| Dark Mode | Full dark mode support with smooth theme toggling |
| Role-Based Access | Middleware-enforced admin-only access to dashboard |
| Feature | Description |
|---|---|
| Authentication | Secure login with session management |
| City Selection | Multi-city support β salesmen select their operating city |
| Dashboard | Personal stats β today's orders, pending payments, quick actions |
| Order Creation | Select shop β browse product catalog β add to cart β review & submit |
| Order Tracking | View orders across tabs: Draft, Pending, Approved, Rejected |
| Invoice Preview | Full on-device invoice preview matching the admin's PDF format |
| Invoice Sharing | Generate PDF and share via WhatsApp, email, etc. using native share sheet |
| Shop Management | View city-filtered shops, add new shops, view shop details & balances |
| Bills & Payments | View outstanding bills, record cash/UPI/bank payments |
| Payment History | Full payment timeline per order with status badges |
| Notifications | Real-time notifications for order approvals/rejections |
| Reports | Daily summary, period reports, shop-wise & product-wise analytics |
| Route Planning | Plan daily visit routes, mark shops as visited, place orders during visits |
| Offline Support | Local data persistence via SharedPreferences for offline-first usage |
| Data Sync | Pull-to-refresh syncs all data (shops, orders, payments) from server |
| Profile | View and manage salesman profile |
βββββββββββββββ ββββββββββββββββ ββββββββββββββββββββ
β users β β shops β β suppliers β
βββββββββββββββ ββββββββββββββββ ββββββββββββββββββββ
β id (PK) β β id (PK) β β id (PK) β
β name β β shop_name β β name β
β email β β owner_name β β contact_person β
β role βββββββ city β β email / phone β
β phone_number β β mobile_number β β address β
β area β β gst_number β ββββββββββββββββββββ
ββββββββ¬ββββββββ β address β β
β β is_active β β
β β outstanding β ββββββββββΌββββββββββ
β β _balance β β supplier_products β
β βββββββββ¬ββββββββ ββββββββββββββββββββ
β β β supplier_id (FK) β
β β β product_id (FK) β
β ββββββββΌββββββββ ββββββββββββββββββββ
β β orders β
β ββββββββββββββββ ββββββββββββββββββββ
ββββββββββββββββ salesman_id β β products β
β β shop_id (FK) β ββββββββββββββββββββ
β β total_amount β β id (PK) β
β β paid_amount β β name / category β
β β status β β base_price β
β β is_paid β ββββββββββ¬ββββββββββ
β β approver_id β β
β βββββββββ¬ββββββββ ββββββββββΌββββββββββ
β β β product_variants β
β ββββββββΌββββββββ ββββββββββββββββββββ
β β order_items β β sku / price β
β ββββββββββββββββ β current_stock β
β β variant_id βββββββ variant_name β
β β quantity β ββββββββββ¬ββββββββββ
β β price β β
β ββββββββββββββββ ββββββββββΌββββββββββ
β β stock_ledger β
β ββββββββββββββββ ββββββββββββββββββββ
ββββββββββββββββ payments β β change_amount β
β ββββββββββββββββ β type (IN/OUT/ADJ) β
β β order_id (FK) β β reference_id β
β β shop_id (FK) β β supplier_id (FK) β
β β amount / mode β ββββββββββββββββββββ
β ββββββββββββββββ
β
β ββββββββββββββββ
ββββββββββββββββ notifications β
ββββββββββββββββ
β salesman_id β
β type / title β
β message β
β is_new β
ββββββββββββββββ
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/auth/[...all] |
BetterAuth handler (login, register, session) |
POST |
/api/mobile/auth/login |
Mobile app authentication |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/mobile/data/sync?salesmanId= |
Full data sync (shops, products, orders, payments, notifications, stats) |
POST |
/api/mobile/orders/create |
Submit a new order from mobile |
POST |
/api/mobile/payments/create |
Record a payment from mobile |
POST |
/api/mobile/shops/create |
Register a new shop from mobile |
POST |
/api/mobile/shops/update-status |
Update shop active/inactive status |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/delivery/order |
Get orders ready for delivery |
PATCH |
/api/delivery/order/[id]/status |
Update delivery status |
| Action | File | Description |
|---|---|---|
createOrder |
src/actions/orders.ts |
Create order with stock validation |
approveOrder |
src/actions/orders.ts |
Approve order, deduct stock, update shop balance |
rejectOrder |
src/actions/orders.ts |
Reject order and notify salesman |
- Node.js 18+ and npm
- Flutter 3.x SDK with Android SDK configured
- PostgreSQL database (recommend Supabase free tier)
# Clone the repository
git clone https://github.com/GARJE-01/FlowTech.git
cd FlowTech
# Install dependencies
npm install
# Set up environment variables (see below)
cp .env.example .env
# Push database schema
npx drizzle-kit push
# Run development server
npm run devThe dashboard will be available at http://localhost:3000.
# Navigate to mobile app directory
cd mobile_app
# Install Flutter dependencies
flutter pub get
# Run on Chrome (for testing)
flutter run -d chrome
# Run on connected Android device
flutter run
# Build release APK
flutter build apk --releaseThe APK will be generated at:
mobile_app/build/app/outputs/flutter-apk/app-release.apk
Create a .env file in the project root:
# Database (Supabase PostgreSQL)
DATABASE_URL=postgresql://postgres:<password>@<host>:5432/postgres
# BetterAuth
BETTER_AUTH_SECRET=<your-secret-key>
BETTER_AUTH_URL=http://localhost:3000
# Deployment URL (update after deploying to Vercel)
NEXT_PUBLIC_APP_URL=http://localhost:3000Mobile App: Update the API base URL in
mobile_app/lib/src/core/network/api_client.dartto point to your deployed Vercel URL.
# Build production bundle
npm run build
# Or deploy directly via Vercel CLI
npx vercel --prodThe project is configured for automatic deployments on push to the Dashboard branch.
cd mobile_app
# Generate launcher icons (if icon changed)
dart run flutter_launcher_icons
# Build release APK
flutter build apk --releaseFlowTech/
βββ src/ # Next.js Dashboard Source
β βββ app/
β β βββ admin/ # Admin pages
β β β βββ page.tsx # Dashboard (stats, charts, recent sales)
β β β βββ layout.tsx # Admin layout with sidebar
β β β βββ orders/ # Order management pages
β β β βββ inventory/ # Product & stock management
β β β βββ shops/ # Shop management
β β β βββ salesmen/ # Salesman management
β β β βββ suppliers/ # Supplier management
β β β βββ stock-ledger/ # Stock audit trail
β β βββ api/
β β β βββ auth/ # BetterAuth endpoints
β β β βββ mobile/ # Mobile app REST API
β β β βββ delivery/ # Delivery management API
β β βββ login/ # Login page
β βββ actions/ # Server actions (order approve/reject)
β βββ components/ # Reusable UI components (shadcn/ui)
β βββ db/
β β βββ schema.ts # Drizzle ORM schema definitions
β β βββ index.ts # DB connection
β β βββ queries.ts # Reusable database queries
β βββ lib/ # Utilities (auth, notifications)
βββ mobile_app/ # Flutter Salesman App
β βββ lib/
β β βββ main.dart # App entry point & provider setup
β β βββ src/
β β βββ core/
β β β βββ network/ # API client & sync service
β β β βββ router/ # GoRouter configuration
β β β βββ storage/ # SharedPreferences service
β β β βββ theme/ # App theme & colors
β β β βββ widgets/ # Shared widgets (navbar, placeholders)
β β βββ features/
β β βββ auth/ # Login screen & auth state
β β βββ city/ # City selection
β β βββ dashboard/ # Salesman home dashboard
β β βββ shop/ # Shop list, detail, add shop
β β βββ order/ # Order creation (cart, products)
β β βββ order_tracking/# Order list & detail (by status)
β β βββ invoice/ # Invoice preview & PDF sharing
β β βββ payment/ # Payment recording & history
β β βββ bills/ # Bills/outstanding view
β β βββ notification/ # Push notifications
β β βββ reports/ # Business analytics
β β βββ route/ # Daily route planning
β β βββ profile/ # User profile
β βββ test/ # Automated test suites
β βββ assets/icon/ # App launcher icon source
βββ drizzle/ # Database migrations
βββ middleware.ts # Auth & RBAC middleware
βββ drizzle.config.ts # Drizzle Kit configuration
βββ package.json # Node.js dependencies
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'feat: add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is private and proprietary. All rights reserved.
Built with β€οΈ by GARJE-01