# berrouane-wafa/titanium-api architecture

> Architecture diagram of the GitHub repository berrouane-wafa/titanium-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/berrouane-wafa/titanium-api
- Repository: https://github.com/berrouane-wafa/titanium-api

## Overview

This is a small Express/MySQL product API. A client reaches the server’s product routes, which validate requests before dispatching to controllers; controllers call the product service, which queries MySQL and returns results for HTTP responses. The server also serves the public directory and formats forwarded errors. Source excerpts establish the main request and database flow; no README capabilities were provided, and the public page’s behavior is not shown.

Main entry points: [`routes/product.routes.js`](https://github.com/berrouane-wafa/titanium-api/blob/main/routes/product.routes.js) (Product routes), [`controllers/product.controller.js`](https://github.com/berrouane-wafa/titanium-api/blob/main/controllers/product.controller.js) (Product controller), [`server.js`](https://github.com/berrouane-wafa/titanium-api/blob/main/server.js) (Express server), [`services/product.service.js`](https://github.com/berrouane-wafa/titanium-api/blob/main/services/product.service.js) (Product service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP application"]
  node_server["Express server<br/>[server.js]"]
  node_public["Static assets"]
  node_routes["Product routes<br/>[product.routes.js]"]
  node_id_validation["ID validation<br/>[validateId.js]"]
  node_create_validation["Create validation"]
  node_update_validation["Update validation"]
end

subgraph group_domain["Product operations"]
  node_controller["Product controller"]
  node_async_handler["Async wrapper<br/>[asyncHandler.js]"]
  node_app_error["HTTP errors<br/>[AppError.js]"]
end

subgraph group_data["Persistence"]
  node_service["Product service<br/>[product.service.js]"]
  node_db_config["DB connection<br/>[database.js]"]
  node_mysql[("MySQL products")]
end

node_client(("API client"))

node_client -->|"sends requests"| node_server
node_server -->|"mounts at"| node_routes
node_server -->|"serves files"| node_public
node_routes -->|"validates IDs"| node_id_validation
node_routes -->|"validates creates"| node_create_validation
node_routes -->|"validates updates"| node_update_validation
node_routes -->|"dispatches requests"| node_controller
node_controller -->|"calls operations"| node_service
node_controller -->|"wraps handlers"| node_async_handler
node_controller -->|"raises errors"| node_app_error
node_service -->|"awaits connection"| node_db_config
node_db_config -->|"opens connection"| node_mysql
node_service -->|"queries products"| node_mysql

click node_server "https://github.com/berrouane-wafa/titanium-api/blob/main/server.js"
click node_public "https://github.com/berrouane-wafa/titanium-api/tree/main/public"
click node_routes "https://github.com/berrouane-wafa/titanium-api/blob/main/routes/product.routes.js"
click node_id_validation "https://github.com/berrouane-wafa/titanium-api/blob/main/middlewares/validateId.js"
click node_create_validation "https://github.com/berrouane-wafa/titanium-api/blob/main/middlewares/validationProduct.js"
click node_update_validation "https://github.com/berrouane-wafa/titanium-api/blob/main/middlewares/validateProductUpdate.js"
click node_controller "https://github.com/berrouane-wafa/titanium-api/blob/main/controllers/product.controller.js"
click node_async_handler "https://github.com/berrouane-wafa/titanium-api/blob/main/middlewares/asyncHandler.js"
click node_app_error "https://github.com/berrouane-wafa/titanium-api/blob/main/errors/AppError.js"
click node_service "https://github.com/berrouane-wafa/titanium-api/blob/main/services/product.service.js"
click node_db_config "https://github.com/berrouane-wafa/titanium-api/blob/main/config/database.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server,node_public,node_routes,node_id_validation,node_create_validation,node_update_validation,node_client toneBlue
class node_controller,node_async_handler,node_app_error toneAmber
class node_service,node_db_config,node_mysql toneMint
```

## Components

### HTTP application

- [Express server](https://github.com/berrouane-wafa/titanium-api/blob/main/server.js): `server.js`
- [Static assets](https://github.com/berrouane-wafa/titanium-api/tree/main/public): `public`
- [Product routes](https://github.com/berrouane-wafa/titanium-api/blob/main/routes/product.routes.js): `routes/product.routes.js`
- [ID validation](https://github.com/berrouane-wafa/titanium-api/blob/main/middlewares/validateId.js): `middlewares/validateId.js`
- [Create validation](https://github.com/berrouane-wafa/titanium-api/blob/main/middlewares/validationProduct.js): `middlewares/validationProduct.js`
- [Update validation](https://github.com/berrouane-wafa/titanium-api/blob/main/middlewares/validateProductUpdate.js): `middlewares/validateProductUpdate.js`

### Product operations

- [Product controller](https://github.com/berrouane-wafa/titanium-api/blob/main/controllers/product.controller.js): `controllers/product.controller.js`
- [Async wrapper](https://github.com/berrouane-wafa/titanium-api/blob/main/middlewares/asyncHandler.js): `middlewares/asyncHandler.js`
- [HTTP errors](https://github.com/berrouane-wafa/titanium-api/blob/main/errors/AppError.js): `errors/AppError.js`

### Persistence

- [Product service](https://github.com/berrouane-wafa/titanium-api/blob/main/services/product.service.js): `services/product.service.js`
- [DB connection](https://github.com/berrouane-wafa/titanium-api/blob/main/config/database.js): `config/database.js`
- **MySQL products**

### Other components

- **API client**

## Connections

- API client → Express server: sends requests
- Express server → Product routes: mounts at (evidence: `server.js`)
- Express server → Static assets: serves files (evidence: `server.js`)
- Product routes → ID validation: validates IDs (evidence: `routes/product.routes.js`)
- Product routes → Create validation: validates creates (evidence: `routes/product.routes.js`)
- Product routes → Update validation: validates updates (evidence: `routes/product.routes.js`)
- Product routes → Product controller: dispatches requests (evidence: `routes/product.routes.js`)
- Product controller → Product service: calls operations (evidence: `controllers/product.controller.js`)
- Product controller → Async wrapper: wraps handlers (evidence: `controllers/product.controller.js`)
- Product controller → HTTP errors: raises errors (evidence: `controllers/product.controller.js`)
- Product service → DB connection: awaits connection (evidence: `services/product.service.js`)
- DB connection → MySQL products: opens connection (evidence: `config/database.js`)
- Product service → MySQL products: queries products (evidence: `services/product.service.js`)
