# sebastianperudev2001/lab-05-backend-test architecture

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

- Interactive diagram: https://gitdiagram.com/sebastianperudev2001/lab-05-backend-test
- Repository: https://github.com/sebastianperudev2001/lab-05-backend-test

## Overview

##### Project type and purpose
- This is a small-scale Node.js backend “laboratory” project whose main focus is on database interaction and automated testing (Jest or a similar framework).
- There is no frontend; the code is purely server-side modules (db.js, inventory.js) backed by a relational database (schema.sql), with corresponding test suites (db.test.js, inventory.test.js).

##### File structure
- Top-level files only; no nested directories.
- db.js: encapsulates database connectivity and query routines.
- inventory.js: exposes higher-level CRUD business logic for inventory items.
- schema.sql: defines the database schema (tables, columns, constraints).
- *.test.js: unit tests for each module.
- package.json / package-lock.json: project metadata, dependencies, and scripts (e.g., “test” script).

##### README
- The README only names the exercise (“Laboratorio 05: Testing Backend”) and offers no further architecture details.
- We infer that emphasis is on testing the interaction between business-logic modules and the database layer.

a. Main components
- Node.js Service – split into two internal modules:
– DB Module (db.js)
– Inventory Module (inventory.js)
- Relational Database (e.g., SQLite, Postgres) defined by schema.sql
- Test Harness (Jest) running db.test.js and inventory.test.js

b. Relationships and interactions
- Inventory Module calls the DB Module to perform SQL operations (SELECT, INSERT, UPDATE, DELETE).
- DB Module uses a database driver (e.g., pg or sqlite3) to connect to and query the database.
- The Test Harness invokes both modules via their exported functions and asserts on returned data or side effects in the database.
- The database persists inventory data according to schema.sql.

c. Architectural patterns / design principles
- Module separation: business logic (inventory.js) is decoupled from data access logic (db.js).
- Single responsibility: each module has one clear responsibility—DB interface vs. domain logic.
- Test-driven mindset: for each module, there is a corresponding test file.

d. Key technologies / libraries
- Node.js (runtime)
- A SQL database (driver configured in db.js)
- Jest (or Mocha/Chai) as the testing framework
- npm for dependency management and test scripts

## Diagram (Mermaid)

```mermaid
flowchart TD
    ServiceRoot["Node.js Service"]:::service
    Inventory["Inventory Module<br/>(inventory.js)"]:::module
    DB["DB Module<br/>(db.js)"]:::module
    Database["Relational Database<br/>(schema.sql)"]:::database
    DBTest["DB Module Tests<br/>(db.test.js)"]:::test
    InvTest["Inventory Module Tests<br/>(inventory.test.js)"]:::test
    packageJSON["package.json"]:::metadata
    packageLock["package-lock.json"]:::metadata
    README["README.md"]:::metadata
    GITIGNORE[".gitignore"]:::metadata

    ServiceRoot --> Inventory
    ServiceRoot --> DB
    Inventory -->|"getItems(), addItem(), updateItem()"| DB
    DB -->|"runQuery()/INSERT/SELECT"| Database
    DBTest -->|"uses"| DB
    InvTest -->|"uses"| Inventory

    classDef service fill:#D6EAF8,stroke:#2980B9,color:#154360
    classDef module fill:#FCF3CF,stroke:#B7950B,color:#7D6608
    classDef database fill:#D5F5E3,stroke:#27AE60,color:#1E8449
    classDef test fill:#FADBD8,stroke:#C0392B,color:#78281F
    classDef metadata fill:#EBDEF0,stroke:#8E44AD,color:#4A235A

    click ServiceRoot "https://github.com/sebastianperudev2001/lab-05-backend-test/blob/main/."
    click Inventory "https://github.com/sebastianperudev2001/lab-05-backend-test/blob/main/inventory.js"
    click DB "https://github.com/sebastianperudev2001/lab-05-backend-test/blob/main/db.js"
    click Database "https://github.com/sebastianperudev2001/lab-05-backend-test/blob/main/schema.sql"
    click DBTest "https://github.com/sebastianperudev2001/lab-05-backend-test/blob/main/db.test.js"
    click InvTest "https://github.com/sebastianperudev2001/lab-05-backend-test/blob/main/inventory.test.js"
    click packageJSON "https://github.com/sebastianperudev2001/lab-05-backend-test/blob/main/package.json"
    click packageLock "https://github.com/sebastianperudev2001/lab-05-backend-test/blob/main/package-lock.json"
    click README "https://github.com/sebastianperudev2001/lab-05-backend-test/blob/main/README.md"
    click GITIGNORE "https://github.com/sebastianperudev2001/lab-05-backend-test/blob/main/.gitignore"
```
