How nadjibgue/nj-stock_beta works
Project type and purpose
• This is a full-stack web application built with Next.js 13 (App Router) and TypeScript.
• It provides an inventory/stock management dashboard (“nj-stock_beta”) with sections for alerts, employees, products, inventory, restock, sales, reports/export, labels, shopping lists, stats, and settings.
• It includes user authentication (login/register), server-side data access (lib/database.ts), and file storage (lib/storage.ts, lib/storage-production.ts).
File structure
Top-level directories and their roles:
• app/
• Implements the Next.js App Router. Contains server and client React components under pages (login, register, dashboard, root layout).
• app/dashboard/ holds feature modules (alerts, employees, products, etc.).
• components/
• theme-provider.tsx configures global theme context.
• ui/ houses reusable UI primitives (buttons, tables, dialogs, sidebar, toasts, etc.).
• hooks/
• Custom React hooks (use-mobile, use-toast) for shared client-side logic.
• lib/
• auth.ts – server-side auth/session utilities.
• database.ts – database client or ORM setup.
• storage.ts / storage-production.ts – file upload/storage integration.
• utils.ts – shared helper functions.
• public/
• Static assets (e.g., service worker).
• styles/, globals.css, tailwind.config.ts
• Tailwind CSS configuration and global styling.
• Config files: next.config.mjs, tsconfig.json, postcss.config.mjs, package.json, pnpm-lock.yaml.
README
• README is empty. We infer architecture solely from file structure and conventions.
a. Main components
1. User’s browser (React client)
2. Next.js Frontend (App Router + server/client components in app/)
3. UI Component Library (components/ui/ + theme provider)
4. Custom React Hooks (hooks/)
5. Next.js Server (API routes / server components calling lib/*.ts)
6. Database Service (configured in lib/database.ts)
7. Authentication Service (lib/auth.ts, session store)
8. File Storage Service (lib/storage.ts & storage-production.ts, e.g., S3 or cloud storage)
9. External Services (if any—e.g., email, analytics)
b. Relationships and interactions
• Browser → Next.js Frontend: HTTP(S) requests to page routes and client-side navigation.
• Frontend components invoke React hooks (use-toast, use-mobile) for UI behavior.
• Server-side components or API routes call lib/auth.ts to check sessions, lib/database.ts to fetch/modify data, lib/storage.ts to handle file uploads.
• Database Service persists and retrieves inventory, user, sales, and alert data.
• Storage Service stores large assets (e.g., product images, generated exports).
• Auth Service issues/validates tokens or sessions.
c. Architectural patterns and principles
• File-based routing (Next.js App Router) separating client and server components.
• Component-driven UI (atomic design via components/ui).
• Layered structure: Presentation (app/, components/), Business Logic (hooks/, lib/utils.ts), Data Access (lib/database.ts, lib/storage.ts).
• Server components for data fetching and secure operations.
• Tailwind CSS + global styles for consistent theming.
d. Key technologies/frameworks
• Next.js 13 App Router (React server/client components)
• React + TypeScript
• Tailwind CSS
• Node.js for server functions
• A database client or ORM (in lib/database.ts)
• Cloud storage SDK (in lib/storage-production.ts)
Final guidance
• Break the system into its smallest meaningful units: pages, components, services.
• Keep it readable: group related features (all app/dashboard/ routes) under one “Dashboard” container.