# mk48/fullstack-crud-react-node-postgresql architecture

> Architecture diagram of the GitHub repository mk48/fullstack-crud-react-node-postgresql, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mk48/fullstack-crud-react-node-postgresql
- Repository: https://github.com/mk48/fullstack-crud-react-node-postgresql

## Overview

##### Main Components
- Frontend (webclient): The “webclient” folder contains a React application. This includes components, routes, and utility functions. Key aspects include its organized components (e.g., Login, Home, NavBar, product, purchase) and use of common styles and service utilities (e.g., Axios for API calls).
- Backend (server): The “server” directory encapsulates the Node.js backend. This includes:
- Express-like server entry point (app.js, bin/www).
- Routing (in the “routes” folder) with endpoints for admin, category, product, purchase, report, supplier, and user operations.
- Business Logic (in the “bl” folder) handling operations like category management, product handling, purchase processing, etc.
- Database Models (in the “models” folder) that define the data structure and relationships (categories, products, purchases, etc.).
- Utility functions (in “util”), configuration files, and public views using Handlebars for server-side rendering of error or index pages.
- Database: Although not directly specified as a live connection in the file tree, the presence of the “server/_db” folder (with a compressed database file) and database models implies integration with PostgreSQL.
- Code Generator: The “CodeGenerator” directory is used to maintain JSON data files and EJS templates (e.g., actionCreator.ejs). This component likely automates some of the CRUD form and action creator generation, streamlining development.

##### Relationships and Interactions
- The React frontend communicates with the Node.js backend via RESTful APIs. The “webclient” sends HTTP requests (using Axios) to the routes defined in the “server/routes” folder.
- The server routes pass requests to the business logic layer (“bl”) for processing, which in turn interacts with the database via the models.
- The CodeGenerator serves as a utility that can generate and update parts of the system (especially forms and actions) based on predefined templates and JSON configurations.
- Configuration and utilities in both the client and server (e.g., authentication, constants) ensure that common data and security aspects are maintained.

##### Architectural Patterns and Design Principles
- There is clear separation of concerns:
- Presentation Layer: React webclient.
- API/Service Layer: Node.js backend using Express-style routing.
- Data Layer: Database models and connections.
- Code Generation: An auxiliary tool to speed up CRUD functionalities.
- Modularity: Notice how routes, models, business logic, and utility functions are kept in separate folders, emphasizing a modular approach.
- Standard RESTful API design, with designated endpoints for each functional area (products, categories, purchases, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        FE["Webclient - React UI"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend"
        subgraph "Server Entry Points"
            App["app.js"]:::backendEntry
            Bin["bin/www"]:::backendEntry
        end
        Routes["API Routing"]:::api
        BL["Business Logic"]:::bl
        Models["Database Models"]:::models
        Util["Server Utilities"]:::utilities
        Views["Server Views"]:::views
    end

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

    %% Auxiliary Tool
    subgraph "Tools"
        CodeGen["Code Generator Tool"]:::codegen
    end

    %% Relationships
    FE -->|"HTTPRequests"| Routes
    App -->|"StartsServer"| Routes
    Bin -->|"StartsServer"| Routes
    Routes -->|"Delegates"| BL
    BL -->|"DataOps"| Models
    Models -->|"CRUDOps"| DB
    Routes -->|"AuthMiddleware"| Util
    Routes -->|"RenderPages"| Views
    CodeGen -->|"GeneratesCRUDForms"| FE
    CodeGen -->|"GeneratesActions"| BL

    %% Styles
    classDef frontend fill:#bbf,stroke:#333,stroke-width:2px;
    classDef backendEntry fill:#ddd,stroke:#333,stroke-width:2px;
    classDef api fill:#f96,stroke:#333,stroke-width:2px;
    classDef bl fill:#fc9,stroke:#333,stroke-width:2px;
    classDef models fill:#9f9,stroke:#333,stroke-width:2px;
    classDef utilities fill:#cff,stroke:#333,stroke-width:2px;
    classDef views fill:#ccf,stroke:#333,stroke-width:2px;
    classDef database fill:#fdd,stroke:#333,stroke-width:2px;
    classDef codegen fill:#dfd,stroke:#333,stroke-width:2px;

    %% Click Events
    click FE "https://github.com/mk48/fullstack-crud-react-node-postgresql/tree/master/webclient/"
    click App "https://github.com/mk48/fullstack-crud-react-node-postgresql/blob/master/server/app.js"
    click Bin "https://github.com/mk48/fullstack-crud-react-node-postgresql/tree/master/server/bin/www"
    click Routes "https://github.com/mk48/fullstack-crud-react-node-postgresql/tree/master/server/routes/"
    click BL "https://github.com/mk48/fullstack-crud-react-node-postgresql/tree/master/server/bl/"
    click Models "https://github.com/mk48/fullstack-crud-react-node-postgresql/tree/master/server/models/"
    click Util "https://github.com/mk48/fullstack-crud-react-node-postgresql/tree/master/server/util/"
    click Views "https://github.com/mk48/fullstack-crud-react-node-postgresql/tree/master/server/views/"
    click DB "https://github.com/mk48/fullstack-crud-react-node-postgresql/tree/master/server/_db/"
    click CodeGen "https://github.com/mk48/fullstack-crud-react-node-postgresql/tree/master/CodeGenerator/"
```
