# omereryilmaz/nodejs-crud-with-posgresql-advanced architecture

> Architecture diagram of the GitHub repository omereryilmaz/nodejs-crud-with-posgresql-advanced, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/omereryilmaz/nodejs-crud-with-posgresql-advanced
- Repository: https://github.com/omereryilmaz/nodejs-crud-with-posgresql-advanced

## Overview

##### Main Components

a. Client Layer (External)
- HTTP clients that will consume the API

b. Application Layer
- Express.js Server (Main entry point)
- Routes Layer (/src/routes)
- Controllers Layer (/src/controllers)
- Middleware Layer (/src/middlewares)
- Constants Layer (/src/constants)

c. Data Layer
- PostgreSQL Database
- Database Connection Layer (/src/db)

##### Component Relationships

**Client Requests**
- ↓
**Express Server (server.js)**
- ↓
**Routes (user.route.js)**
- ↓
**Middleware (error.middleware.js)**
- ↓
**Controllers (user.controller.js)**
- ↓
**Database Layer (db/index.js)**
- ↓
**PostgreSQL Database**

##### Specific Design Elements

- Rectangles: Core application components
- Hexagons: Middleware
- Rounded rectangles: External interfaces

- Blue: External interfaces
- Green: Application logic (routes, controllers)
- Yellow: Middleware
- Red: Database components
- Gray: Configuration and constants

##### Important Details

a. Environment Configuration:
- Configuration inputs (DB_USER, DB_HOST, etc.)
- SERVER_PORT configuration

b. Database Schema:
- ID (SERIAL PRIMARY KEY)
- name (VARCHAR)
- email (VARCHAR)

##### Technical Specifications to Note

- HTTP methods supported (GET, POST, PUT, DELETE)
- Connection pool configuration for PostgreSQL

Remember to include a title: "Node.js CRUD API Architecture with Express and PostgreSQL" and add any relevant notes about scaling considerations or deployment requirements.

- The modular structure of the application
- How requests are processed from client to database
- The role of each component in the architecture
- Error handling flow
- Database interaction patterns

## Diagram (Mermaid)

```mermaid
graph TB
    %% Title
    title[("Node.js CRUD API Architecture")]:::title
    
    %% Client Layer
    client["HTTP Clients"]:::external
    
    %% Application Layer
    subgraph AppLayer["Application Layer"]
        server["Express Server"]:::server
        click server "https://github.com/omereryilmaz/nodejs-crud-with-posgresql-advanced/blob/master/server.js"
        
        subgraph Routes["Routes Layer"]
            routes["User Routes"]:::route
            click routes "https://github.com/omereryilmaz/nodejs-crud-with-posgresql-advanced/blob/master/src/routes/user.route.js"
        end
        
        subgraph Middleware["Middleware Layer"]
            middleware["Error Middleware"]:::middleware
            click middleware "https://github.com/omereryilmaz/nodejs-crud-with-posgresql-advanced/blob/master/src/middlewares/error.middleware.js"
        end
        
        subgraph Controllers["Controllers Layer"]
            controller["User Controller"]:::controller
            click controller "https://github.com/omereryilmaz/nodejs-crud-with-posgresql-advanced/blob/master/src/controllers/user.controller.js"
        end
        
        subgraph Config["Configuration"]
            constants["Constants"]:::config
            click constants "https://github.com/omereryilmaz/nodejs-crud-with-posgresql-advanced/blob/master/src/constants/index.js"
            env["Environment Variables"]:::config
        end
    end
    
    %% Data Layer
    subgraph DataLayer["Data Layer"]
        dbConnection["Database Connection"]:::db
        click dbConnection "https://github.com/omereryilmaz/nodejs-crud-with-posgresql-advanced/blob/master/src/db/index.js"
        postgres[(PostgreSQL DB)]:::db
        
        subgraph Schema["User Schema"]
            userTable["ID (SERIAL PRIMARY KEY)<br/>name (VARCHAR)<br/>email (VARCHAR)"]:::schema
        end
    end
    
    %% Connections
    client --> server
    server --> routes
    routes --> middleware
    middleware --> controller
    controller --> dbConnection
    dbConnection --> postgres
    postgres --> userTable
    
    %% Error Flow
    controller -.-> middleware
    routes -.-> middleware
    
    %% Config Connections
    constants --> server
    env --> server
    env --> dbConnection
    
    %% Styling
    classDef external fill:#68B5E8,stroke:#333,stroke-width:2px
    classDef server fill:#95DAC1,stroke:#333,stroke-width:2px
    classDef route fill:#95DAC1,stroke:#333,stroke-width:2px
    classDef middleware fill:#FBD6D2,stroke:#333,stroke-width:2px
    classDef controller fill:#95DAC1,stroke:#333,stroke-width:2px
    classDef db fill:#DB6B97,stroke:#333,stroke-width:2px
    classDef config fill:#DDD,stroke:#333,stroke-width:2px
    classDef schema fill:#FFF,stroke:#333,stroke-width:1px
    classDef title fill:none,stroke:none
    
    %% Legend
    subgraph Legend["Legend"]
        l1["External System"]:::external
        l2["Application Components"]:::server
        l3["Middleware"]:::middleware
        l4["Database Components"]:::db
        l5["Configuration"]:::config
    end
```
