# davi1985/api-rest-nodejs architecture

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

- Interactive diagram: https://gitdiagram.com/davi1985/api-rest-nodejs
- Repository: https://github.com/davi1985/api-rest-nodejs

## Overview

This is a session-scoped transactions REST API. A client creates transactions; the API assigns or reuses a session cookie, stores the transaction, and supports listing, ID lookup, and a session total. The server builds a Fastify app, which registers transaction routes and their handlers; read routes check for a session first. SQLite access is configured through Knex and environment settings. The migration is shown as the schema component, but its contents were not sampled, so its relationship to runtime storage is unverified.

Main entry points: [`src/db/index.ts`](https://github.com/davi1985/api-rest-nodejs/blob/main/src/db/index.ts) (Knex database config), [`src/routes/index.ts`](https://github.com/davi1985/api-rest-nodejs/blob/main/src/routes/index.ts) (Route registration), [`src/app.ts`](https://github.com/davi1985/api-rest-nodejs/blob/main/src/app.ts) (Fastify app), [`src/routes/create-transaction.ts`](https://github.com/davi1985/api-rest-nodejs/blob/main/src/routes/create-transaction.ts) (Create transaction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["API runtime"]
  node_server["Server entry<br/>[server.ts]"]
  node_app["Fastify app<br/>[app.ts]"]
  node_routes["Route registration<br/>[index.ts]"]
  node_session["Session check"]
  node_httpcodes["HTTP status codes<br/>[http-code.ts]"]
end

subgraph group_transactions["Transaction workflows"]
  node_create["Create transaction"]
  node_list["List transactions"]
  node_lookup["Find transaction"]
  node_summary["Summarize transactions"]
end

subgraph group_infrastructure["Storage and configuration"]
  node_db["Knex database config<br/>[index.ts]"]
  node_sqlite[("SQLite database")]
  node_schema["Transactions schema"]
  node_env["Environment settings<br/>[index.ts]"]
end

node_client(("HTTP client"))

node_client -->|"sends requests"| node_server
node_server -->|"builds and listens"| node_app
node_app -->|"registers routes"| node_routes
node_routes -->|"guards reads"| node_session
node_routes -->|"dispatches create"| node_create
node_routes -->|"dispatches list"| node_list
node_routes -->|"dispatches lookup"| node_lookup
node_routes -->|"dispatches summary"| node_summary
node_create -->|"inserts transaction"| node_db
node_list -->|"queries session rows"| node_db
node_lookup -->|"queries by ID"| node_db
node_summary -->|"sums session rows"| node_db
node_db -->|"configures client"| node_sqlite
node_create -->|"checks cookie security"| node_env
node_db -->|"reads database URL"| node_env
node_session -->|"returns unauthorized"| node_httpcodes
node_app -->|"formats errors"| node_httpcodes
node_db -.->|"uses migration directory"| node_schema

click node_server "https://github.com/davi1985/api-rest-nodejs/blob/main/src/server.ts"
click node_app "https://github.com/davi1985/api-rest-nodejs/blob/main/src/app.ts"
click node_routes "https://github.com/davi1985/api-rest-nodejs/blob/main/src/routes/index.ts"
click node_session "https://github.com/davi1985/api-rest-nodejs/blob/main/src/middlewares/check-session-id-exists.ts"
click node_create "https://github.com/davi1985/api-rest-nodejs/blob/main/src/routes/create-transaction.ts"
click node_list "https://github.com/davi1985/api-rest-nodejs/blob/main/src/routes/get-all-transactions.ts"
click node_lookup "https://github.com/davi1985/api-rest-nodejs/blob/main/src/routes/get-transaction-by-id.ts"
click node_summary "https://github.com/davi1985/api-rest-nodejs/blob/main/src/routes/summary-transactions.ts"
click node_db "https://github.com/davi1985/api-rest-nodejs/blob/main/src/db/index.ts"
click node_schema "https://github.com/davi1985/api-rest-nodejs/blob/main/db/migrations/20261009000235_create-transactions.ts"
click node_env "https://github.com/davi1985/api-rest-nodejs/blob/main/src/env/index.ts"
click node_httpcodes "https://github.com/davi1985/api-rest-nodejs/blob/main/src/utils/http-code.ts"

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_routes,node_session,node_httpcodes,node_client toneBlue
class node_create,node_list,node_lookup,node_summary toneAmber
class node_db,node_sqlite,node_schema,node_env toneMint
```

## Components

### API runtime

- [Server entry](https://github.com/davi1985/api-rest-nodejs/blob/main/src/server.ts): `src/server.ts`
- [Fastify app](https://github.com/davi1985/api-rest-nodejs/blob/main/src/app.ts): `src/app.ts`
- [Route registration](https://github.com/davi1985/api-rest-nodejs/blob/main/src/routes/index.ts): `src/routes/index.ts`
- [Session check](https://github.com/davi1985/api-rest-nodejs/blob/main/src/middlewares/check-session-id-exists.ts): `src/middlewares/check-session-id-exists.ts`
- [HTTP status codes](https://github.com/davi1985/api-rest-nodejs/blob/main/src/utils/http-code.ts): `src/utils/http-code.ts`

### Transaction workflows

- [Create transaction](https://github.com/davi1985/api-rest-nodejs/blob/main/src/routes/create-transaction.ts): `src/routes/create-transaction.ts`
- [List transactions](https://github.com/davi1985/api-rest-nodejs/blob/main/src/routes/get-all-transactions.ts): `src/routes/get-all-transactions.ts`
- [Find transaction](https://github.com/davi1985/api-rest-nodejs/blob/main/src/routes/get-transaction-by-id.ts): `src/routes/get-transaction-by-id.ts`
- [Summarize transactions](https://github.com/davi1985/api-rest-nodejs/blob/main/src/routes/summary-transactions.ts): `src/routes/summary-transactions.ts`

### Storage and configuration

- [Knex database config](https://github.com/davi1985/api-rest-nodejs/blob/main/src/db/index.ts): `src/db/index.ts`
- **SQLite database**
- [Transactions schema](https://github.com/davi1985/api-rest-nodejs/blob/main/db/migrations/20261009000235_create-transactions.ts): `db/migrations/20261009000235_create-transactions.ts`
- [Environment settings](https://github.com/davi1985/api-rest-nodejs/blob/main/src/env/index.ts): `src/env/index.ts`

### Other components

- **HTTP client**

## Connections

- HTTP client → Server entry: sends requests (evidence: `src/server.ts`)
- Server entry → Fastify app: builds and listens (evidence: `src/server.ts`)
- Fastify app → Route registration: registers routes (evidence: `src/app.ts`)
- Route registration → Session check: guards reads (evidence: `src/routes/index.ts`)
- Route registration → Create transaction: dispatches create (evidence: `src/routes/index.ts`)
- Route registration → List transactions: dispatches list (evidence: `src/routes/index.ts`)
- Route registration → Find transaction: dispatches lookup (evidence: `src/routes/index.ts`)
- Route registration → Summarize transactions: dispatches summary (evidence: `src/routes/index.ts`)
- Create transaction → Knex database config: inserts transaction (evidence: `src/routes/create-transaction.ts`)
- List transactions → Knex database config: queries session rows (evidence: `src/routes/get-all-transactions.ts`)
- Find transaction → Knex database config: queries by ID (evidence: `src/routes/get-transaction-by-id.ts`)
- Summarize transactions → Knex database config: sums session rows (evidence: `src/routes/summary-transactions.ts`)
- Knex database config → SQLite database: configures client (evidence: `src/db/index.ts`)
- Create transaction → Environment settings: checks cookie security (evidence: `src/routes/create-transaction.ts`)
- Knex database config → Environment settings: reads database URL (evidence: `src/db/index.ts`)
- Session check → HTTP status codes: returns unauthorized (evidence: `src/middlewares/check-session-id-exists.ts`)
- Fastify app → HTTP status codes: formats errors (evidence: `src/app.ts`)
- Knex database config → Transactions schema: uses migration directory
