# priyans-hu/stockflow architecture

> Architecture diagram of the GitHub repository priyans-hu/stockflow, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/priyans-hu/stockflow
- Repository: https://github.com/priyans-hu/stockflow

## Overview

##### Project Overview and Identification
- Project Type: Full-stack inventory management application.
- Purpose: Manage products, track inventory levels, process orders, and handle user authentication with unique API keys for data isolation.
- Tech Stack:
- Backend: Node.js with Express.js
- Frontend: React.js with Tailwind CSS
- Database: MongoDB
- Authentication: JWT (JSON Web Tokens)

##### Main Components of the System
A. Frontend
- Represented by the “frontend” directory.
- Key elements include:
- UI Components (AddProductForm, CategoryCard, OrderCard, etc.)
- Pages (Dashboard, LoginPage, Inventory, CategoriesPage, OrdersPage, TransactionsPage)
- Static Assets and Public Files (index.html, manifest.json, robots.txt)
- Responsibilities: Presentation layer, user interactivity, interfacing with the backend API.

B. Backend
- Represented by the “backend” directory.
- Sub-components include:
- Configuration: (config.js, dbConnection.js) for setting up environment and MongoDB connections.
- Controllers: (CategoryController, InventoryController, etc.) implementing business logic.
- Models: (CategoryModel, InventoryModel, etc.) defining the database schema.
- Routes: (CategoryRoutes, ProductRoutes, etc.) mapping endpoints to controllers.
- Entry point: index.js initializing the Express server.
- Responsibilities: API endpoints, business logic, database interactions, authentication (via JWT).

C. Database
- Although not shown as a directory, it’s a crucial element.
- MongoDB is used to persist data for products, categories, orders, transactions, and users.
- Represents the data storage layer, interacting primarily with the backend models.

D. Authentication & API Keys
- This component may be abstracted within the backend's authorization middleware.
- Represents security and access control across the system.

E. External Services (Optional)
- While not explicitly mentioned, leave space for future integrations.

##### Relationships and Data Flow
- Frontend communicates with the Backend via RESTful API calls.
- Backend interacts with Database (MongoDB) to store and retrieve data.
- Authentication: Show the flow for user login:
- Frontend → Backend (credentials submission)
- Backend → External authentication (JWT generation) and API key verification.
- Micro-level interactions:
- Controllers call Models for data persistence.
- Routes direct requests to Controllers.

##### Architectural Patterns and Design Principles
- MVC Pattern (Model-View-Controller)
- Backend folders (controllers, models, routes) indicate a separation of concerns.
- Separation of Frontend and Backend layers ensures modularity.
- JWT-based stateless authentication enhances security and scalability.
- Data Isolation:
- Each user’s data is separated; indicate this with a boundary symbol around user-related database entries.
- Extensibility:
- The directory structure is modular, so consider highlighting extension points (e.g., additional controllers or pages for new features).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Styles
    classDef frontend fill:#a6cee3,stroke:#1f78b4,stroke-width:2px;
    classDef backend fill:#b2df8a,stroke:#33a02c,stroke-width:2px;
    classDef config fill:#ffffb3,stroke:#b15928,stroke-width:2px;
    classDef auth fill:#fdbf6f,stroke:#ff7f00,stroke-width:2px;
    classDef database fill:#fb9a99,stroke:#e31a1c,stroke-width:2px;

    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["React Frontend\n(UI Components & Pages)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE["Express Server\n(index.js)"]:::backend
        subgraph "Configuration"
            CFG["config.js"]:::config
            DBC["dbConnection.js"]:::config
        end
        subgraph "Controllers"
            UC["UserController.js\n(and other controllers)"]:::backend
        end
        subgraph "Models"
            UM["UserModel.js\n(and other models)"]:::backend
        end
        subgraph "Routes"
            RT["API Routes\n(CategoryRoutes, InventoryRoutes,\nOrderRoutes, ProductRoutes,\nTransactionRoutes, UserRoutes)"]:::backend
        end
    end

    %% Database Layer
    subgraph "Database Layer"
        DB["MongoDB Database"]:::database
    end

    %% Authentication & API Keys
    subgraph "Authentication & API Keys"
        AUTH["JWT & API Keys\n(User Auth)"]:::auth
    end

    %% Relationships and Data Flow
    FE -->|"REST_API_calls"| BE
    BE -->|"Uses_Config"| CFG
    BE -->|"Uses_Config"| DBC
    BE -->|"Handles_Routes"| RT
    RT -->|"Delegates_To"| UC
    UC -->|"Accesses_Data"| UM
    BE -->|"Queries_DB"| DB
    UC -->|"Authenticates_Via"| AUTH
    FE -->|"Login_Requests"| AUTH

    %% Click Events
    click FE "https://github.com/priyans-hu/stockflow/tree/main/frontend/"
    click BE "https://github.com/priyans-hu/stockflow/tree/main/backend/"
    click CFG "https://github.com/priyans-hu/stockflow/blob/main/backend/config/config.js"
    click DBC "https://github.com/priyans-hu/stockflow/blob/main/backend/config/dbConnection.js"
    click UC "https://github.com/priyans-hu/stockflow/blob/main/backend/controllers/UserController.js"
    click UM "https://github.com/priyans-hu/stockflow/blob/main/backend/models/UserModel.js"
    click UM "https://github.com/priyans-hu/stockflow/tree/main/backend/models/"
```
