# carla-s-romero/library-api architecture

> Architecture diagram of the GitHub repository carla-s-romero/library-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/carla-s-romero/library-api
- Repository: https://github.com/carla-s-romero/library-api

## Overview

API Biblioteca is an Express REST API for managing authors and books. Clients send CRUD and book-search requests through the HTTP server and resource routes; controllers perform Mongoose operations, and list/search requests pass results to pagination and sorting before returning JSON. The API also connects to MongoDB and maps request, validation, missing-resource, and server errors to HTTP responses. The README documents the product capabilities; edges reflect only its explicit architecture statements or relationships visible in the sampled source, so unsampled implementation details are omitted.

Main entry points: [`src/app.js`](https://github.com/carla-s-romero/library-api/blob/main/src/app.js) (Express app), [`src/controllers/bookControllers.js`](https://github.com/carla-s-romero/library-api/blob/main/src/controllers/bookControllers.js) (Book operations and search), [`src/models/Author.js`](https://github.com/carla-s-romero/library-api/blob/main/src/models/Author.js) (Author model), [`src/router/index.js`](https://github.com/carla-s-romero/library-api/blob/main/src/router/index.js) (Route registry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["HTTP entry"]
  node_server["HTTP server<br/>[server.js]"]
  node_app["Express app<br/>[app.js]"]
end

subgraph group_resources["Resource API"]
  node_routeindex["Route registry<br/>[index.js]"]
  node_authorroutes["Author routes<br/>[authorsRoutes.js]"]
  node_bookroutes["Book routes<br/>[booksRoutes.js]"]
  node_authorcontroller["Author operations"]
  node_bookcontroller["Book operations and search<br/>[bookControllers.js]"]
end

subgraph group_data["Data layer"]
  node_dbconfig["Database connection<br/>[dbconect.js]"]
  node_author["Author model<br/>[Author.js]"]
  node_book["Book model<br/>[Livro.js]"]
  node_validators["Model validation<br/>[globalValidator.js]"]
  node_mongo[("MongoDB")]
end

subgraph group_middleware["Request middleware"]
  node_pagination["Pagination and sorting"]
  node_notfound["Not-found error<br/>[notFound.js]"]
  node_errors["Error responses<br/>[errorHandler.js]"]
  node_page404["Unknown-route handling<br/>[page404.js]"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_server
node_server -->|"loads app"| node_app
node_app -->|"connects database"| node_dbconfig
node_app -->|"registers routes"| node_routeindex
node_routeindex -->|"mounts routes"| node_authorroutes
node_routeindex -->|"mounts routes"| node_bookroutes
node_authorroutes -->|"dispatches requests"| node_authorcontroller
node_bookroutes -->|"dispatches requests"| node_bookcontroller
node_authorroutes -->|"passes list results"| node_pagination
node_bookroutes -->|"passes list results"| node_pagination
node_authorcontroller -->|"queries and writes"| node_author
node_bookcontroller -->|"queries and writes"| node_book
node_bookcontroller -->|"searches author"| node_author
node_authorcontroller -->|"raises missing error"| node_notfound
node_bookcontroller -->|"raises missing error"| node_notfound
node_app -->|"handles unknown routes"| node_page404
node_app -->|"registers error handler"| node_errors
node_pagination -->|"forwards invalid input"| node_errors
node_notfound -.->|"formats errors"| node_errors
node_author -->|"persists documents"| node_mongo
node_book -->|"persists documents"| node_mongo
node_validators -.->|"validates models"| node_author
node_validators -.->|"validates models"| node_book

click node_server "https://github.com/carla-s-romero/library-api/blob/main/server.js"
click node_app "https://github.com/carla-s-romero/library-api/blob/main/src/app.js"
click node_dbconfig "https://github.com/carla-s-romero/library-api/blob/main/src/config/dbconect.js"
click node_routeindex "https://github.com/carla-s-romero/library-api/blob/main/src/router/index.js"
click node_authorroutes "https://github.com/carla-s-romero/library-api/blob/main/src/router/authorsRoutes.js"
click node_bookroutes "https://github.com/carla-s-romero/library-api/blob/main/src/router/booksRoutes.js"
click node_authorcontroller "https://github.com/carla-s-romero/library-api/blob/main/src/controllers/AuthorsControllers.js"
click node_bookcontroller "https://github.com/carla-s-romero/library-api/blob/main/src/controllers/bookControllers.js"
click node_pagination "https://github.com/carla-s-romero/library-api/blob/main/src/middlewares/paginationSorting.js"
click node_author "https://github.com/carla-s-romero/library-api/blob/main/src/models/Author.js"
click node_book "https://github.com/carla-s-romero/library-api/blob/main/src/models/Livro.js"
click node_validators "https://github.com/carla-s-romero/library-api/blob/main/src/models/globalValidator.js"
click node_notfound "https://github.com/carla-s-romero/library-api/blob/main/src/middlewares/modelErrors/notFound.js"
click node_errors "https://github.com/carla-s-romero/library-api/blob/main/src/middlewares/errorHandler.js"
click node_page404 "https://github.com/carla-s-romero/library-api/blob/main/src/middlewares/page404.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_app,node_client toneBlue
class node_routeindex,node_authorroutes,node_bookroutes,node_authorcontroller,node_bookcontroller toneAmber
class node_dbconfig,node_author,node_book,node_validators,node_mongo toneMint
class node_pagination,node_notfound,node_errors,node_page404 toneRose
```

## Components

### HTTP entry

- [HTTP server](https://github.com/carla-s-romero/library-api/blob/main/server.js): `server.js`
- [Express app](https://github.com/carla-s-romero/library-api/blob/main/src/app.js): `src/app.js`

### Resource API

- [Route registry](https://github.com/carla-s-romero/library-api/blob/main/src/router/index.js): `src/router/index.js`
- [Author routes](https://github.com/carla-s-romero/library-api/blob/main/src/router/authorsRoutes.js): `src/router/authorsRoutes.js`
- [Book routes](https://github.com/carla-s-romero/library-api/blob/main/src/router/booksRoutes.js): `src/router/booksRoutes.js`
- [Author operations](https://github.com/carla-s-romero/library-api/blob/main/src/controllers/AuthorsControllers.js): `src/controllers/AuthorsControllers.js`
- [Book operations and search](https://github.com/carla-s-romero/library-api/blob/main/src/controllers/bookControllers.js): `src/controllers/bookControllers.js`

### Data layer

- [Database connection](https://github.com/carla-s-romero/library-api/blob/main/src/config/dbconect.js): `src/config/dbconect.js`
- [Author model](https://github.com/carla-s-romero/library-api/blob/main/src/models/Author.js): `src/models/Author.js`
- [Book model](https://github.com/carla-s-romero/library-api/blob/main/src/models/Livro.js): `src/models/Livro.js`
- [Model validation](https://github.com/carla-s-romero/library-api/blob/main/src/models/globalValidator.js): `src/models/globalValidator.js`
- **MongoDB**

### Request middleware

- [Pagination and sorting](https://github.com/carla-s-romero/library-api/blob/main/src/middlewares/paginationSorting.js): `src/middlewares/paginationSorting.js`
- [Not-found error](https://github.com/carla-s-romero/library-api/blob/main/src/middlewares/modelErrors/notFound.js): `src/middlewares/modelErrors/notFound.js`
- [Error responses](https://github.com/carla-s-romero/library-api/blob/main/src/middlewares/errorHandler.js): `src/middlewares/errorHandler.js`
- [Unknown-route handling](https://github.com/carla-s-romero/library-api/blob/main/src/middlewares/page404.js): `src/middlewares/page404.js`

### Other components

- **API client**

## Connections

- API client → HTTP server: sends requests (evidence: `README.MD`)
- HTTP server → Express app: loads app (evidence: `server.js`)
- Express app → Database connection: connects database (evidence: `src/app.js`)
- Express app → Route registry: registers routes (evidence: `src/app.js`)
- Route registry → Author routes: mounts routes (evidence: `src/router/index.js`)
- Route registry → Book routes: mounts routes (evidence: `src/router/index.js`)
- Author routes → Author operations: dispatches requests (evidence: `src/router/authorsRoutes.js`)
- Book routes → Book operations and search: dispatches requests (evidence: `src/router/booksRoutes.js`)
- Author routes → Pagination and sorting: passes list results (evidence: `src/router/authorsRoutes.js`)
- Book routes → Pagination and sorting: passes list results (evidence: `src/router/booksRoutes.js`)
- Author operations → Author model: queries and writes (evidence: `src/controllers/AuthorsControllers.js`)
- Book operations and search → Book model: queries and writes (evidence: `src/controllers/bookControllers.js`)
- Book operations and search → Author model: searches author (evidence: `src/controllers/bookControllers.js`)
- Author operations → Not-found error: raises missing error (evidence: `src/controllers/AuthorsControllers.js`)
- Book operations and search → Not-found error: raises missing error (evidence: `src/controllers/bookControllers.js`)
- Express app → Unknown-route handling: handles unknown routes (evidence: `src/app.js`)
- Express app → Error responses: registers error handler (evidence: `src/app.js`)
- Pagination and sorting → Error responses: forwards invalid input (evidence: `src/middlewares/paginationSorting.js`)
- Not-found error → Error responses: formats errors
- Author model → MongoDB: persists documents (evidence: `README.MD`)
- Book model → MongoDB: persists documents (evidence: `README.MD`)
- Model validation → Author model: validates models
- Model validation → Book model: validates models
