# zenika/cours-services-web-avec-nodejs architecture

> Architecture diagram of the GitHub repository zenika/cours-services-web-avec-nodejs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zenika/cours-services-web-avec-nodejs
- Repository: https://github.com/zenika/cours-services-web-avec-nodejs

## Overview

##### Project type and purpose
- This is a progressive Node.js training project that starts as a CLI tool for managing contacts in a JSON file, evolves into an HTTP-based micro-service with Express, adds an HTTP client, and finally a minimal web UI.
- Its purpose is to teach: Node.js core, asynchronous programming, command-line interfaces (commander.js), file persistence (contacts.json), HTTP servers (Express + body-parser), HTTP clients (request), and static file serving (serve-static).

##### File structure
- Top-level files:
- app.js – main entry point for both CLI and server.
- contacts.json – simple JSON store of contacts.
- package.json / .npmrc – project configuration and dependencies.
- tests/ – test suite driving each step (step0 to step6, test-utils).
- No subdirectories beyond tests; all logic lives under app.js (and any modules you add).
- The progression implies three runtime modes:
- CLI mode reading/writing contacts.json directly.
- “serve” mode launching Express HTTP server.
- “HTTP client” mode where CLI commands issue HTTP requests.
- Tests invoke app.js with different flags (`--memory`, `serve`, `add`, `remove`, etc.).

##### README for additional insights
- The README outlines each TP step, required commands, libraries (commander.js, shortid, Express, body-parser, request, serve-static).
- It specifies API routes (/health, /contacts, /contacts/:id) and CLI commands (list, add, remove, serve, update).
- It suggests an optional in-memory vs. file-based persistence switch.

##### Elements
- From CLI App to Contacts Store (file I/O).
- From CLI App to Express Server (HTTP requests).
- From Web UI to Express Server (HTTP requests).
- From Express Server to Contacts Store.
- From Test Suite to both CLI App and Express Server.
- Rectangles for runtime components (CLI, Server, UI).

2. In Presentation: place “CLI App” and “Web UI”.
3. In Application: place “Express Server (app.js + routing)”.
- CLI App → Persistence (direct mode)
- CLI App → Express Server (HTTP mode)
- Express Server → Persistence
- Web UI → Express Server
- Test Suite → CLI App & Test Suite → Express Server
7. Technologies next to each component: e.g., “Express + body-parser”, “commander.js”, “request”, “shortid”, “serve-static”.
- Core modules vs. third-party libraries
- File vs. memory storage
- Synchronous vs. asynchronous I/O

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        CLI["CLI App\n(app.js)\ncommander.js\nrequest"]:::presentation
        WebUI["Web UI\n(static files)\nserve-static"]:::presentation
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        Express["Express Server\n(app.js)\nExpress + body-parser\nRoutes: /health, /contacts, /contacts/:id"]:::application
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        direction TB
        ContactsFile[(contacts.json)]:::persistence
        InMem["In-Memory Store\n(JS object)"]:::persistence
    end

    %% External/Test Layer
    subgraph "External Components"
        direction TB
        TestSuite["Test Suite\ntests/"]:::external
        TestUtils["Test Utils\ntests/test-utils.js"]:::external
        Config["Config\npackage.json\n.npmrc"]:::external
    end

    %% Relationships
    CLI -->|Direct Mode| ContactsFile
    CLI -->|HTTP Mode| Express
    CLI -->|--memory flag| InMem
    WebUI -->|HTTP Calls| Express
    Express -->|File I/O| ContactsFile
    Express -->|--memory flag| InMem
    TestSuite -->|CLI Tests| CLI
    TestSuite -->|API Tests| Express

    %% Click Events
    click CLI "https://github.com/zenika/cours-services-web-avec-nodejs/blob/master/app.js"
    click Express "https://github.com/zenika/cours-services-web-avec-nodejs/blob/master/app.js"
    click ContactsFile "https://github.com/zenika/cours-services-web-avec-nodejs/blob/master/contacts.json"
    click TestSuite "https://github.com/zenika/cours-services-web-avec-nodejs/tree/master/tests/"
    click TestUtils "https://github.com/zenika/cours-services-web-avec-nodejs/blob/master/tests/test-utils.js"
    click Config "https://github.com/zenika/cours-services-web-avec-nodejs/blob/master/package.json"

    %% Styles
    classDef presentation fill:#a2d2ff,stroke:#0366d6,stroke-width:2px;
    classDef application fill:#ffafcc,stroke:#d0006f,stroke-width:2px;
    classDef persistence fill:#caffbf,stroke:#2d6a4f,stroke-width:2px;
    classDef external fill:#ffffd2,stroke:#ffba08,stroke-width:2px;
```
