# voctor98/techsolutions_innovations architecture

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

- Interactive diagram: https://gitdiagram.com/voctor98/techsolutions_innovations
- Repository: https://github.com/voctor98/techsolutions_innovations

## Overview

##### Project Type and Purpose
- TechSolutions is primarily a full-stack, PHP + MySQL monolith for service/product/user management, augmented by modern front-end clients (a static PWA shell in root, a React SPA in /react-app, and a Next-JS SSR front end in /techsolutions-ssr) and by separate Node/Express API services (the root `server.js` + `/routes/*` and the dedicated `/techsolutions-api` microservice).
- Its goal is to let SMBs register users, manage products/services, and eventually use PWA/offline features.

##### File Structure
- Top-level PHP monolith
- `.php` files (index.php, login.php, add_product.php, etc.)
- `/models` with ORM-like JS models (`Product.js`, `User.js`)
- `/database/techsolutions.sql` for MySQL schema
- `db.js` likely for Node-layer DB connectivity
- `/api` PHP endpoints
- `/routes/*.js` + `server.js` for a Node/Express thin API
- `service-worker.js` + `manifest.json` for PWA scaffolding
- React SPA (`/react-app`)
- Vite-powered front end (App.jsx, main.jsx)
- Connects to one or both Node APIs
- Dedicated Node-Express microservice (`/techsolutions-api`)
- Controllers, models, routes in JS
- Separate package.json and `.env`
- SSR Next.js app (`/techsolutions-ssr`)
- Uses Next 13 App Router (`app/layout.tsx`, page.tsx, etc.)
- IndexedDB helper for offline caching
- Tests and E2E (`__tests__`, `cypress/`)
- Misc: uploads, logs, vendor, composer.lock (composer PHP deps)

##### README for Context
- Confirms the PHP + MySQL core, PWA in development, optional React/Firebase expansions.
- Mentions user/role management, product modules, reporting, PWA offline.

##### Main Components
a. Clients / Presentation Layer
- Web browser (static PHP pages + embedded JS)
- PWA shell (service-worker, manifest)
- React SPA (hosted via Vite or static server)
- Next-JS SSR front end
b. API Layer(s) / App Servers
- PHP monolith (Apache + PHP-FPM) handling .php routes, business logic, session management
- Node/Express “root” API (`server.js` + `/routes`)
- techsolutions-api microservice (productController, authMiddleware)
c. Data Layer
- MySQL database (single instance hosting `techsolutions` schema imported from `/database/techsolutions.sql`)
d. External & Support Services
- BotMan chat (botman.php)
- Email / password recovery service (send_recovery_email.php)
- File storage (`/uploads`)
- Logging (logs.txt, login_logout.log, password_reset.log)
e. Offline / Caching
- IndexedDB (in Next.js and `testIndexedDB.js`)
- Service Worker (caching static assets)

##### Relationships & Data Flows
- Browsers → (HTTP/HTTPS) → PHP Monolith or Node/Express APIs → MySQL
- React SPA & Next SSR → (REST) → Node/Express APIs (either root or `/techsolutions-api`) → MySQL
- PWA shell uses service-worker to intercept and cache requests to both PHP endpoints and Node API endpoints.
- BotMan chat communicates via webhook endpoints in PHP.
- Email module calls external SMTP (via PHP mail functions).
- All servers read/write to the same MySQL instance.

##### Architectural Patterns & Principles
- Monolithic core in PHP for legacy modules
- Microservices pattern for product API (`/techsolutions-api`) and for SPA/SSR separation
- Progressive enhancement via PWA (service-worker + manifest)
- MVC-ish separation in Node APIs (controllers/models/routes)
- Single source of truth (MySQL), with JS ORM-style models in `/models` and `/techsolutions-api/models`

##### Essential Detail
- Don’t omit any major component: show both root Node API and `/techsolutions-api` microservice.
- PWA elements (service-worker, manifest, offline storage).

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Clients / Presentation Layer"
        Browser["Web Browser"]:::client
        MobilePWA["Mobile PWA Shell"]:::pwa
        ReactClient["React SPA"]:::react
        NextClient["Next.js SSR Front-end"]:::next
    end

    subgraph "Front-end Applications"
        PHPPages["PHP Pages"]:::php
        PWAElements["Service Worker & Manifest"]:::pwa
    end

    subgraph "Back-end APIs"
        PHPMono["PHP Monolith<br/>(Apache+PHP-FPM)"]:::php
        RootAPI["Node/Express Root API"]:::node
        Microservice["techsolutions-api Microservice"]:::node
    end

    subgraph "Data & External Services"
        MySQL["MySQL Database"]:::db
        EmailSvc["Email Service (SMTP)"]:::external
        BotMan["BotMan Chat"]:::external
        FileStorage["File Storage (uploads)"]:::external
        Logging["Logging Services"]:::external
    end

    %% Client to Front-end
    Browser -->|"HTTP/HTTPS"| PHPPages
    Browser -->|"Fetch Assets"| PWAElements
    MobilePWA -->|"HTTP/HTTPS"| PHPPages
    MobilePWA -->|"Service Worker Cache"| PWAElements

    %% Front-end to Back-end
    PHPPages -->|"POST /login, GET /products"| PHPMono
    PWAElements -.->|"Intercept & Cache"| PHPMono
    PWAElements -.->|"Intercept & Cache"| RootAPI

    ReactClient -->|"REST API Calls"| RootAPI
    ReactClient -->|"REST API Calls"| Microservice

    NextClient -->|"REST API Calls"| RootAPI
    NextClient -->|"REST API Calls"| Microservice

    %% Back-end to Data/External
    PHPMono -->|"SQL Queries"| MySQL
    RootAPI -->|"SQL Queries"| MySQL
    Microservice -->|"SQL Queries"| MySQL

    PHPMono -->|"Send Email"| EmailSvc
    PHPMono -->|"Webhook"| BotMan
    PHPMono -->|"Upload Files"| FileStorage
    PHPMono -->|"Write Logs"| Logging

    %% Testing
    subgraph "Testing (dashed)"
        Jest["Jest Tests"]:::test
        Cypress["Cypress E2E"]:::test
    end
    Jest -.-> ReactClient
    Cypress -.-> PHPPages

    %% Click Events
    click PHPMono "https://github.com/voctor98/techsolutions_innovations/tree/master/./"
    click PHPPages "https://github.com/voctor98/techsolutions_innovations/tree/master/./"
    click APIEndpoints "https://github.com/voctor98/techsolutions_innovations/tree/master/./api"
    click BotMan "https://github.com/voctor98/techsolutions_innovations/blob/master/botman.php"
    click Recovery "https://github.com/voctor98/techsolutions_innovations/blob/master/send_recovery_email.php"
    click DBjs "https://github.com/voctor98/techsolutions_innovations/blob/master/db.js"
    click ModelsDir "https://github.com/voctor98/techsolutions_innovations/tree/master/./models"
    click Schema "https://github.com/voctor98/techsolutions_innovations/blob/master/database/techsolutions.sql"
    click RootServer "https://github.com/voctor98/techsolutions_innovations/blob/master/server.js"
    click RoutesDir "https://github.com/voctor98/techsolutions_innovations/tree/master/./routes"
    click MicroDir "https://github.com/voctor98/techsolutions_innovations/tree/master/./techsolutions-api"
    click Microservice "https://github.com/voctor98/techsolutions_innovations/blob/master/./techsolutions-api/server.js"
    click MicroController "https://github.com/voctor98/techsolutions_innovations/blob/master/./techsolutions-api/controllers/productController.js"
    click MicroModel "https://github.com/voctor98/techsolutions_innovations/blob/master/./techsolutions-api/models/product.js"
    click MicroRoutes "https://github.com/voctor98/techsolutions_innovations/blob/master/./techsolutions-api/routes/productRoutes.js"
    click MicroAuth "https://github.com/voctor98/techsolutions_innovations/blob/master/./techsolutions-api/utils/authMiddleware.js"
    click ReactApp "https://github.com/voctor98/techsolutions_innovations/tree/master/./react-app"
    click AppJS "https://github.com/voctor98/techsolutions_innovations/blob/master/./react-app/src/App.jsx"
    click MainJS "https://github.com/voctor98/techsolutions_innovations/blob/master/./react-app/src/main.jsx"
    click ViteConfig "https://github.com/voctor98/techsolutions_innovations/blob/master/./react-app/vite.config.js"
    click HTML "https://github.com/voctor98/techsolutions_innovations/blob/master/./react-app/public/index.html"
    click NextDir "https://github.com/voctor98/techsolutions_innovations/tree/master/./techsolutions-ssr"
    click Layout "https://github.com/voctor98/techsolutions_innovations/blob/master/./techsolutions-ssr/app/layout.tsx"
    click Page "https://github.com/voctor98/techsolutions_innovations/blob/master/./techsolutions-ssr/app/page.tsx"
    click IndexedDBHelper "https://github.com/voctor98/techsolutions_innovations/blob/master/./techsolutions-ssr/app/products/indexeddb.js"
    click Manifest "https://github.com/voctor98/techsolutions_innovations/blob/master/manifest.json"
    click SW "https://github.com/voctor98/techsolutions_innovations/blob/master/service-worker.js"
    click TestIndexed "https://github.com/voctor98/techsolutions_innovations/blob/master/./testIndexedDB.js"
    click MySQLDB "https://github.com/voctor98/techsolutions_innovations/blob/master/database/techsolutions.sql"
    click ORMProd "https://github.com/voctor98/techsolutions_innovations/blob/master/models/Product.js"
    click ORMUser "https://github.com/voctor98/techsolutions_innovations/blob/master/models/User.js"
    click Uploads "https://github.com/voctor98/techsolutions_innovations/tree/master/./uploads"
    click Logs "https://github.com/voctor98/techsolutions_innovations/blob/master/logs.txt"
    click LoginLog "https://github.com/voctor98/techsolutions_innovations/blob/master/login_logout.log"
    click PassResetLog "https://github.com/voctor98/techsolutions_innovations/blob/master/password_reset.log"
    click TestsDir "https://github.com/voctor98/techsolutions_innovations/tree/master/./__tests__"
    click JestConfig "https://github.com/voctor98/techsolutions_innovations/blob/master/jest.config.js"
    click CypressDir "https://github.com/voctor98/techsolutions_innovations/tree/master/./cypress"

    classDef client fill:#FFD699,stroke:#333,stroke-width:1px,color:#000
    classDef pwa fill:#FFC266,stroke:#333,stroke-width:1px,color:#000
    classDef react fill:#66D9EF,stroke:#333,stroke-width:1px,color:#000
    classDef next fill:#5FDDE5,stroke:#333,stroke-width:1px,color:#000
    classDef php fill:#7BAAF7,stroke:#333,stroke-width:1px,color:#000
    classDef node fill:#8FD17B,stroke:#333,stroke-width:1px,color:#000
    classDef db fill:#F7A96B,stroke:#333,stroke-width:1px,color:#000
    classDef external fill:#CCCCCC,stroke:#333,stroke-width:1px,color:#000
    classDef test stroke-dasharray: 5 5,fill:#EFEFEF,stroke:#333,stroke-width:1px,color:#000
```
