# bsandeepreddy27/neepco architecture

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

- Interactive diagram: https://gitdiagram.com/bsandeepreddy27/neepco
- Repository: https://github.com/bsandeepreddy27/neepco

## Overview

##### Project type and purpose
- This is a full-stack procurement management web application.
- Frontend: React + Vite powered UI for tenders, bidding, payments, reporting, vendor and user management.
- Backend: Node.js + Express REST API implementing MVC (models, controllers, routes, middleware).
- Persistence: PostgreSQL (managed via Supabase migrations).

##### Main components
a. Frontend (React/Vite)
- Pages and routes (public, auth, dashboard, procurement, payments, reports, vendor management).
- UI layers: PublicLayout, DashboardLayout, AdminDashboardLayout.
- Component libraries and hooks (API wrappers in src/lib/api, auth helpers, UI components).
b. Backend (Node/Express)
- Entry point: server.js
- Controllers (userController, tenderController, bidController, paymentController, vendorController)
- Routes (bidRoutes, userRoutes, tenderRoutes, paymentRoutes, vendorRoutes)
- Middleware (auth, error handling, validation, pagination)
- Models (Sequelize/mapped models or raw SQL via db.js)
- Utilities (Token generation, DB connection)
c. Database
- Supabase-managed PostgreSQL
- Schema defined in supabase/migrations/*.sql
d. External services
- Supabase Auth & Realtime (if used)
- Payment gateway (Stripe or QR code integration)
- Notification service (push/email)

##### Relationships and data flows
- User’s browser → HTTP(S) → Vite development server (or built assets on web server)
- React app → REST calls → Express API endpoints
- Express controllers → business logic → models → PostgreSQL via db.js
- On critical events (new tender, awarded bid, payment), Express may invoke external services (e.g., email, QR code)
- Supabase migrations only at build/deploy time update schema

##### Architectural patterns and key principles
- Frontend: component-based, separation of layout vs. page logic, single-page application with client routing (RoleBasedRoute, ProtectedRoute).
- State & data fetching through custom hooks (useAuth) and API client modules (src/lib/api).
- Backend: MVC pattern with clear separation of concerns.
- Middleware pipeline for cross-cutting concerns (authentication, validation, pagination, error handling).
- Token-based authentication (JWT via generateToken.js).
- Database migrations for reproducible schema changes.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser)"
        Browser["User's Browser"]:::ui
    end

    %% Frontend Application
    subgraph "Frontend (React + Vite)"
        FEEntry["main.jsx"]:::ui
        PagesRoutes["Pages & Routes"]:::ui
        PublicLayout["PublicLayout.jsx"]:::ui
        DashboardLayout["DashboardLayout.jsx"]:::ui
        AdminDashboardLayout["AdminDashboardLayout.jsx"]:::ui
        ProtectedRoute["ProtectedRoute.jsx"]:::ui
        RoleBasedRoute["RoleBasedRoute.jsx"]:::ui
        APIClient["API Client Modules"]:::ui
        AuthHooks["Auth Helpers & useAuth"]:::ui
        UIComponents["UI Component Library"]:::ui
    end

    %% API Layer
    subgraph "API Layer (Express + MVC)"
        Server["server.js"]:::api
        Middleware["Middleware"]:::api
        RoutesAPI["Routes"]:::api
        Controllers["Controllers"]:::api
        Models["Models"]:::api
        Utils["generateToken.js"]:::api
    end

    %% Data Layer
    subgraph "Database (Supabase PostgreSQL)"
        Migrations["Migrations"]:::db
        DB["PostgreSQL"]:::db
    end

    %% External Services
    subgraph "External Services"
        SupabaseAuth["Supabase Auth & Realtime"]:::ext
        PaymentGateway["Payment Gateway"]:::ext
        NotificationService["Notification Service"]:::ext
    end

    %% Connections
    Browser --> FEEntry
    FEEntry --> PagesRoutes
    PagesRoutes --> PublicLayout
    PagesRoutes --> DashboardLayout
    PagesRoutes --> AdminDashboardLayout
    PublicLayout --> ProtectedRoute
    DashboardLayout --> ProtectedRoute
    AdminDashboardLayout --> RoleBasedRoute
    ProtectedRoute --> APIClient
    RoleBasedRoute --> APIClient
    APIClient --> AuthHooks
    APIClient --> Server
    AuthHooks --> Server

    Server --> Middleware
    Middleware --> RoutesAPI
    RoutesAPI --> Controllers
    Controllers --> Models
    Models --> DB
    Utils --> Controllers

    Controllers --> SupabaseAuth
    Controllers --> PaymentGateway
    Controllers --> NotificationService

    Migrations --> DB

    %% Click Events: Frontend
    click FEEntry "https://github.com/bsandeepreddy27/neepco/blob/main/src/main.jsx"
    click PagesRoutes "https://github.com/bsandeepreddy27/neepco/tree/main/src/pages/"
    click PublicLayout "https://github.com/bsandeepreddy27/neepco/blob/main/src/components/layouts/PublicLayout.jsx"
    click DashboardLayout "https://github.com/bsandeepreddy27/neepco/blob/main/src/components/layouts/DashboardLayout.jsx"
    click AdminDashboardLayout "https://github.com/bsandeepreddy27/neepco/blob/main/src/components/layouts/AdminDashboardLayout.jsx"
    click ProtectedRoute "https://github.com/bsandeepreddy27/neepco/blob/main/src/components/auth/ProtectedRoute.jsx"
    click RoleBasedRoute "https://github.com/bsandeepreddy27/neepco/blob/main/src/components/auth/RoleBasedRoute.jsx"
    click APIClient "https://github.com/bsandeepreddy27/neepco/blob/main/src/lib/api/index.js"
    click AuthHooks "https://github.com/bsandeepreddy27/neepco/blob/main/src/lib/auth.js"
    %% UI Components (group click)
    click UIComponents "https://github.com/bsandeepreddy27/neepco/blob/main/src/components/ui/Button.jsx"

    %% Click Events: Backend
    click Server "https://github.com/bsandeepreddy27/neepco/blob/main/backend/server.js"
    click Middleware "https://github.com/bsandeepreddy27/neepco/tree/main/backend/middleware/"
    click RoutesAPI "https://github.com/bsandeepreddy27/neepco/tree/main/backend/routes/"
    click Controllers "https://github.com/bsandeepreddy27/neepco/tree/main/backend/controllers/"
    click Models "https://github.com/bsandeepreddy27/neepco/tree/main/backend/models/"
    click Utils "https://github.com/bsandeepreddy27/neepco/blob/main/backend/utils/generateToken.js"

    %% Click Events: Database & Migrations
    click Migrations "https://github.com/bsandeepreddy27/neepco/tree/main/supabase/migrations/"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef api fill:#E2F0D9,stroke:#228B22,color:#228B22
    classDef db fill:#FFE4B5,stroke:#FF8C00,color:#FF8C00
    classDef ext fill:#F2F2F2,stroke:#A9A9A9,color:#696969
```
