# bawfng04/cnpm-assignment architecture

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

- Interactive diagram: https://gitdiagram.com/bawfng04/cnpm-assignment
- Repository: https://github.com/bawfng04/cnpm-assignment

## Overview

##### Main Components
- Frontend (Client):
- Built with ReactJS and hosted via Firebase Hosting.
- Contains pages for Login, Registration, and Main Dashboards (both user and admin).
- Organized into several components (Sidebar, Dashboard, Printer, Settings, etc.) that are modular and reflect different functionalities.
- Backend (Server/BE):
- Developed with NodeJS, following an MVC structure with separate folders for controllers, routes, models, validations, and middleware.
- Responsible for delivering APIs to handle authentication, printer management, order processing, payment handling, and reporting.
- Database:
- Implied by files in Server/BE/database and SQL migration scripts, likely using PostgreSQL.
- Stores persistent data for users, printers, orders, and payments.
- External Services:
- Firebase: Managing client hosting and potentially real-time notifications.
- Payment gateways or notification services may be integrated, as suggested by payment and real-time notification features.

##### Relationships and Interactions
- The Frontend (React app) communicates with the Backend API endpoints.
- Backend-to-Database Interaction:
- How the backend controllers and services interact with the database (e.g., CRUD operations).
- External Service Integration:
- Firebase as a component for hosting and, if applicable, real-time notifications.
- Payment integration as an external service that the backend interfaces with via its payment APIs.

##### Architectural Patterns and Design Principles
- Frontend:
- Component-based architecture typical of React applications.
- Similar components (pages, subcomponents) to indicate modularity.
- Backend:
- Use of the MVC pattern—separate controllers, models, and routes.
- Middleware for handling authentication and access control.
- Communication Mechanisms:
- Optionally, note the use of WebSockets or similar (if real-time notifications are implemented via such methods).

##### Relevant Technologies and Frameworks
- Client:
- ReactJS
- Firebase for hosting (and possibly additional Firebase tools)
- Server:
- NodeJS and Express (or a similar framework given the structure)
- Associated libraries for authentication, routing, and data validation.
- Database:
- PostgreSQL (as implied by migration scripts and database service files)
- Additional Tools:
- Firebase CLI for deployment and management of hosting.
- Possibly external APIs for payment processing.

##### Final Touches
- Detail both admin and user functionalities where necessary – for example, distinguishing admin routes for printer and user management.
- Verify that each element in the file tree (e.g., “Client/src/pages/components”, “Server/BE/src/controllers”, etc.) has its corresponding place in the overall system design.

## Diagram (Mermaid)

```mermaid
flowchart TD 
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["React Frontend"]:::frontend
        Login["Login Page"]:::frontend
        Register["Registration Page"]:::frontend
        Dashboard["Main Dashboard"]:::frontend
        Components["Dashboard Components"]:::frontend
        FirebaseHost["Firebase Hosting"]:::frontend
        FirebaseConfig["Firebase Config"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE["Express API Server"]:::backend
        Controllers["Controllers (MVC)"]:::backend
        Routes["Routes (MVC)"]:::backend
        Models["Models (MVC)"]:::backend
        Middleware["Middleware"]:::backend
        Validations["Validations"]:::backend
    end

    %% Database & External Services
    subgraph "Database & External Services"
        DB["PostgreSQL Database"]:::database
        DBServices["Database Services"]:::database
        DBMigrations["Database Migrations"]:::database
        Payment["Payment Gateway Service"]:::external
        FirebaseExt["Firebase (Real-time Notifications)"]:::external
    end

    %% Frontend Internal Relationships
    FE -->|"renders"| Login
    FE -->|"renders"| Register
    FE -->|"renders"| Dashboard
    FE -->|"contains"| Components
    FirebaseHost --> FE
    FirebaseConfig --> FE

    %% Communication Between Layers
    FE -->|"APIRequest"| BE

    %% Backend Internal Structure
    BE --> Controllers
    BE --> Routes
    BE --> Models
    BE --> Middleware
    BE --> Validations

    %% Backend to Database & External Services
    BE -->|"CRUD"| DBServices
    DBServices -->|"Query"| DB
    DBServices -->|"Migrations"| DBMigrations
    BE -->|"PaymentProcessing"| Payment
    BE -->|"Notifications"| FirebaseExt

    %% Click Events for Frontend Components
    click FE "https://github.com/bawfng04/cnpm-assignment/tree/_main/Client/src/pages & Client/public"
    click Login "https://github.com/bawfng04/cnpm-assignment/blob/_main/Client/src/pages/Login.js"
    click Register "https://github.com/bawfng04/cnpm-assignment/blob/_main/Client/src/pages/Register.js"
    click Dashboard "https://github.com/bawfng04/cnpm-assignment/blob/_main/Client/src/pages/Main.js"
    click Components "https://github.com/bawfng04/cnpm-assignment/tree/_main/Client/src/pages/components"
    click FirebaseHost "https://github.com/bawfng04/cnpm-assignment/blob/_main/Client/.firebase"
    click FirebaseConfig "https://github.com/bawfng04/cnpm-assignment/blob/_main/Client/.firebaserc"

    %% Click Events for Backend Components
    click BE "https://github.com/bawfng04/cnpm-assignment/tree/_main/Server/BE/src"
    click Controllers "https://github.com/bawfng04/cnpm-assignment/tree/_main/Server/BE/src/controllers"
    click Routes "https://github.com/bawfng04/cnpm-assignment/tree/_main/Server/BE/src/routes"
    click Models "https://github.com/bawfng04/cnpm-assignment/tree/_main/Server/BE/src/models"
    click Middleware "https://github.com/bawfng04/cnpm-assignment/tree/_main/Server/BE/src/middleware"
    click Validations "https://github.com/bawfng04/cnpm-assignment/tree/_main/Server/BE/src/validations"

    %% Click Events for Database Services & Migrations
    click DBServices "https://github.com/bawfng04/cnpm-assignment/tree/_main/Server/BE/database"
    click DBMigrations "https://github.com/bawfng04/cnpm-assignment/tree/_main/Server/BE/migration"

    %% Styles
    classDef frontend fill:#FFEEAD,stroke:#333,stroke-width:2px;
    classDef backend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef database fill:#C1FFC1,stroke:#333,stroke-width:2px;
    classDef external fill:#FFD1DC,stroke:#333,stroke-width:2px;
```
