# mo-renike/data-visualization-dashboard architecture

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

- Interactive diagram: https://gitdiagram.com/mo-renike/data-visualization-dashboard
- Repository: https://github.com/mo-renike/data-visualization-dashboard

## Overview

##### Project Type and Purpose
- This is a full-stack web application (“XYZ Shop”) for visualizing sales data with interactive charts, user authentication (admin/customer), order management, and time-based analytics.
- Frontend: React + TypeScript + Tailwind + Chart.js
- Backend: Node.js + Express + TypeScript + Prisma ORM + PostgreSQL + JWT

##### File Structure Analysis
- Top-level “client” and “server” directories separate the two major parts.
- client/src organizes UI components, pages, contexts, hooks, services, constants, validation, and assets—typical React feature-folder structure.
- server/src contains controllers (business logic), routes (REST API endpoints), middleware (JWT auth), utils (data population, filtering), and the Prisma schema under prisma/.
- Configuration files: vite.config.js (frontend build), tsconfig.json, package.json, .gitignore files, Prisma migrations.

##### Key Architectural Insights from README
- RESTful API with endpoints for auth (/api/auth), orders (/api/orders), and stats (/api/stats).
- Role-based access control enforced via JWT middleware.
- Prisma as Data Access Layer mapping to PostgreSQL.
- Frontend calls backend over Axios to fetch or mutate data.

##### Main Components
a. Presentation Layer (Client)
– Browser / React App
– UI Modules: Auth pages, Dashboard charts, Order management pages
– State & Context (AuthContext)
– API Service (Axios wrappers)
b. API Layer (Server)
– Express HTTP Server
– Route Handlers: auth, orders, stats
– Middleware: JWT authentication, error handlers
– Controllers: chartController, orderController, statsController
c. Business & Data Layer
– Prisma ORM (client-generated library)
– PostgreSQL Database
– Data Seeder script (populateOrders.ts)
d. External Services
– JWT provider (secret key)
– Possibly Vercel / Render for hosting

##### Relationships and Data Flow
- User interacts with the React UI → UI dispatches Axios HTTP requests → Express routes receive requests
- Auth middleware validates JWT → Controllers execute business logic → Prisma client executes SQL against PostgreSQL → Results flow back through controllers → Response to Axios → UI updates charts or tables
- Data-seeding utility populates the database on setup

##### Architectural Patterns & Principles
- Layered Architecture: Presentation → API Layer → Business Logic → Data Access
- MVC-style separation in the backend (Routes → Controllers → ORM)
- Feature-based grouping on the frontend
- Single responsibility: each controller, middleware, and React component has a focused role

- Blue for frontend components
- Green for backend/API layers
- Orange for database
- Gray for external services
- Protocols (HTTP/REST, JWT tokens, SQL).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend (Browser/React App)"
        direction TB
        Browser["Browser / React App"]:::frontend

        subgraph "UI Modules"
            direction TB
            AuthPage["Auth Page"]:::frontend
            DashboardPage["Dashboard Charts"]:::frontend
            OrdersPage["Order Management"]:::frontend
        end

        AuthContext["AuthContext (State)"]:::frontend
        APIService["API Service (Axios)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Express API Server)"
        direction TB
        Server["Express HTTP Server"]:::backend

        subgraph "API Gateway (Routes)"
            direction TB
            AuthRoute["/api/auth"]:::backend
            OrdersRoute["/api/orders"]:::backend
            StatsRoute["/api/stats"]:::backend
        end

        JWTMiddleware["JWT Auth Middleware"]:::backend
        subgraph "Controllers"
            direction TB
            ChartController["chartController"]:::backend
            OrderController["orderController"]:::backend
            StatsController["statsController"]:::backend
        end

        PrismaClient["Prisma Client"]:::backend
    end

    %% Database Layer
    PostgreSQL[(PostgreSQL Database)]:::db

    %% Utilities
    subgraph "Utilities"
        direction TB
        Seeder["Data Seeder Script"]:::backend
        DateFilter["Date Filter Utility"]:::backend
    end

    %% External Services
    JWTProvider["JWT Secret / Provider"]:::external
    Hosting["Vercel / Render"]:::external

    %% Connections
    Browser -->|interacts| AuthPage
    Browser -->|interacts| DashboardPage
    Browser -->|interacts| OrdersPage
    AuthPage -->|uses| AuthContext
    DashboardPage -->|uses| APIService
    OrdersPage -->|uses| APIService

    Browser -->|HTTP/REST| Server
    APIService -->|HTTP/REST| Server

    Server --> Routes
    Server -->|handles| AuthRoute
    Server -->|handles| OrdersRoute
    Server -->|handles| StatsRoute

    AuthRoute -->|validates JWT| JWTMiddleware
    OrdersRoute -->|validates JWT| JWTMiddleware
    StatsRoute -->|validates JWT| JWTMiddleware
    JWTMiddleware -->|injects| Controllers

    AuthRoute -->|routes to| OrderController
    OrdersRoute -->|routes to| OrderController
    StatsRoute -->|routes to| StatsController
    AuthRoute -->|routes to| ChartController

    ChartController -->|queries| PrismaClient
    OrderController -->|queries| PrismaClient
    StatsController -->|queries| PrismaClient

    PrismaClient -->|SQL| PostgreSQL
    Seeder -->|populates| PostgreSQL
    DateFilter -->|used by| ChartController
    JWTMiddleware -->|uses| JWTProvider
    Browser -->|hosted on| Hosting
    Server -->|hosted on| Hosting

    %% Click Events - Frontend
    click Browser "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/index.html"
    click AuthPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/pages/AuthPage.tsx"
    click AuthContext "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/contexts/AuthContext.tsx"
    click APIService "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/services/dashboardService.ts"
    click DashboardPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/pages/admin/Dashboard.tsx"
    click OrdersPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/pages/customer/CustomerDashboard.tsx"
    click AuthPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/pages/AuthPage.tsx"
    click AuthPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/pages/AuthPage.tsx"
    click AuthPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/pages/AuthPage.tsx"
    click AuthPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/pages/AuthPage.tsx"
    click APIService "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/services/dashboardService.ts"

    click AuthPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/pages/AuthPage.tsx"
    click DashboardPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/pages/admin/Dashboard.tsx"
    click OrdersPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/pages/customer/CustomerDashboard.tsx"

    click Browser "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/main.jsx"
    click Browser "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/App.tsx"
    click AuthPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/components/auth/LoginForm.tsx"
    click AuthPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/components/auth/RegisterForm.tsx"
    click AuthPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/components/auth/ProtectedRoute.tsx"
    click DashboardPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/components/dashboard/revenueChart.tsx"
    click DashboardPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/components/dashboard/categoryChart.tsx"
    click OrdersPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/components/orders/OrderForm.tsx"
    click OrdersPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/components/orders/OrderTable.tsx"
    click OrdersPage "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/components/orders/TableUtils.tsx"
    click Browser "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/components/layout/Header.tsx"
    click Browser "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/components/layout/SIdebar.tsx"
    click Browser "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/components/common/Modal.tsx"
    click Browser "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/components/common/Spinner.tsx"
    click Browser "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/components/ui/Box.tsx"
    click Browser "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/components/ui/Button.tsx"
    click Browser "https://github.com/mo-renike/data-visualization-dashboard/blob/main/client/src/components/ui/DateFilter.tsx"

    %% Click Events - Backend
    click Server "https://github.com/mo-renike/data-visualization-dashboard/blob/main/server/src/index.ts"
    click AuthRoute "https://github.com/mo-renike/data-visualization-dashboard/blob/main/server/src/routes/auth.ts"
    click OrdersRoute "https://github.com/mo-renike/data-visualization-dashboard/blob/main/server/src/routes/orders.ts"
    click StatsRoute "https://github.com/mo-renike/data-visualization-dashboard/blob/main/server/src/routes/stats.ts"
    click JWTMiddleware "https://github.com/mo-renike/data-visualization-dashboard/blob/main/server/src/middleware/auth.ts"
    click ChartController "https://github.com/mo-renike/data-visualization-dashboard/blob/main/server/src/controllers/chartController.ts"
    click OrderController "https://github.com/mo-renike/data-visualization-dashboard/blob/main/server/src/controllers/orderController.ts"
    click StatsController "https://github.com/mo-renike/data-visualization-dashboard/blob/main/server/src/controllers/statsController.ts"
    click PrismaClient "https://github.com/mo-renike/data-visualization-dashboard/tree/main/server/src/generated/prisma/"
    click Seeder "https://github.com/mo-renike/data-visualization-dashboard/blob/main/server/src/utils/populateOrders.ts"
    click DateFilter "https://github.com/mo-renike/data-visualization-dashboard/blob/main/server/src/utils/dateFilter.ts"
    click PostgreSQL "https://github.com/mo-renike/data-visualization-dashboard/blob/main/server/prisma/schema.prisma"
    click PostgreSQL "https://github.com/mo-renike/data-visualization-dashboard/blob/main/server/prisma/migrations/20250511234514_init/migration.sql"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef db fill:#ffe5b4,stroke:#ff8c00,color:#ff8c00
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d
```
