# matnoren/inventory-api architecture

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

- Interactive diagram: https://gitdiagram.com/matnoren/inventory-api
- Repository: https://github.com/matnoren/inventory-api

## Overview

This repository is an Inventory Management REST API. Users register or log in, obtain JWT credentials, then use role-protected endpoints to manage users, categories, products, and stock. Route modules own request handling and delegate to authentication, inventory, and CRUD logic; CRUD uses SQLAlchemy models backed by PostgreSQL. README documents the major capabilities, while source excerpts and the index support the connections shown. Some route internals are unsampled, so only indexed references or documented links are used for those relationships.

Main entry points: [`app/services/auth.py`](https://github.com/matnoren/inventory-api/blob/main/app/services/auth.py) (Authentication), [`app/api/routes/auth.py`](https://github.com/matnoren/inventory-api/blob/main/app/api/routes/auth.py) (Auth endpoints), [`app/main.py`](https://github.com/matnoren/inventory-api/blob/main/app/main.py) (FastAPI app), [`app/crud/user.py`](https://github.com/matnoren/inventory-api/blob/main/app/crud/user.py) (User operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API routes"]
  node_auth_routes["Auth endpoints<br/>[auth.py]"]
  node_user_routes["User endpoints<br/>[users.py]"]
  node_category_routes["Category endpoints<br/>[categories.py]"]
  node_product_routes["Product endpoints<br/>[products.py]"]
  node_health["Health check<br/>[health.py]"]
  node_user_schema["User validation<br/>[user.py]"]
  node_auth_schema["Token schemas<br/>[auth.py]"]
  node_category_schema["Category validation<br/>[category.py]"]
  node_product_schema["Product validation<br/>[product.py]"]
end

subgraph group_domain["Domain services"]
  node_auth_service["Authentication<br/>[auth.py]"]
  node_inventory_service["Stock adjustment<br/>[inventory.py]"]
  node_security["JWT and hashing<br/>[security.py]"]
end

subgraph group_data["Persistence"]
  node_user_crud["User operations<br/>[user.py]"]
  node_category_crud["Category operations<br/>[category.py]"]
  node_product_crud["Product operations<br/>[product.py]"]
  node_user_model["User model<br/>[user.py]"]
  node_category_model["Category model<br/>[category.py]"]
  node_product_model["Product model<br/>[product.py]"]
end

subgraph group_platform["Runtime foundations"]
  node_db_session["DB sessions<br/>[session.py]"]
  node_postgres[("PostgreSQL")]
  node_config["Settings<br/>[config.py]"]
  node_exceptions["HTTP errors<br/>[exceptions.py]"]
  node_main["FastAPI app<br/>[main.py]"]
end

node_client(("API caller"))

node_client -->|"sends requests"| node_main
node_main -->|"registers routes"| node_auth_routes
node_main -->|"registers routes"| node_user_routes
node_main -->|"registers routes"| node_category_routes
node_main -->|"registers routes"| node_product_routes
node_main -->|"registers routes"| node_health
node_auth_routes -->|"delegates login"| node_auth_service
node_auth_routes -->|"checks and creates"| node_user_crud
node_auth_routes -->|"validates input"| node_user_schema
node_auth_routes -->|"returns token"| node_auth_schema
node_user_routes -->|"manages users"| node_user_crud
node_user_routes -->|"checks access"| node_auth_service
node_category_routes -->|"manages categories"| node_category_crud
node_category_routes -->|"checks access"| node_auth_service
node_product_routes -->|"manages products"| node_product_crud
node_product_routes -->|"adjusts stock"| node_inventory_service
node_product_routes -->|"checks access"| node_auth_service
node_auth_service -->|"loads users"| node_user_crud
node_auth_service -->|"verifies and signs"| node_security
node_auth_service -->|"gets DB dependency"| node_db_session
node_user_crud -->|"queries and writes"| node_user_model
node_user_crud -->|"hashes passwords"| node_security
node_user_crud -->|"accepts updates"| node_user_schema
node_category_crud -->|"queries and writes"| node_category_model
node_category_crud -->|"accepts updates"| node_category_schema
node_product_crud -->|"queries and writes"| node_product_model
node_product_crud -->|"accepts updates"| node_product_schema
node_inventory_service -->|"updates stock"| node_product_crud
node_inventory_service -->|"checks stock"| node_product_model
node_inventory_service -->|"uses stock update"| node_product_schema
node_db_session -->|"loads DB settings"| node_config
node_db_session -->|"connects"| node_postgres
node_health -->|"checks DB"| node_db_session
node_auth_routes -->|"raises conflicts"| node_exceptions

click node_auth_routes "https://github.com/matnoren/inventory-api/blob/main/app/api/routes/auth.py"
click node_user_routes "https://github.com/matnoren/inventory-api/blob/main/app/api/routes/users.py"
click node_category_routes "https://github.com/matnoren/inventory-api/blob/main/app/api/routes/categories.py"
click node_product_routes "https://github.com/matnoren/inventory-api/blob/main/app/api/routes/products.py"
click node_health "https://github.com/matnoren/inventory-api/blob/main/app/api/routes/health.py"
click node_auth_service "https://github.com/matnoren/inventory-api/blob/main/app/services/auth.py"
click node_inventory_service "https://github.com/matnoren/inventory-api/blob/main/app/services/inventory.py"
click node_security "https://github.com/matnoren/inventory-api/blob/main/app/core/security.py"
click node_user_crud "https://github.com/matnoren/inventory-api/blob/main/app/crud/user.py"
click node_category_crud "https://github.com/matnoren/inventory-api/blob/main/app/crud/category.py"
click node_product_crud "https://github.com/matnoren/inventory-api/blob/main/app/crud/product.py"
click node_user_model "https://github.com/matnoren/inventory-api/blob/main/app/models/user.py"
click node_category_model "https://github.com/matnoren/inventory-api/blob/main/app/models/category.py"
click node_product_model "https://github.com/matnoren/inventory-api/blob/main/app/models/product.py"
click node_user_schema "https://github.com/matnoren/inventory-api/blob/main/app/schemas/user.py"
click node_auth_schema "https://github.com/matnoren/inventory-api/blob/main/app/schemas/auth.py"
click node_category_schema "https://github.com/matnoren/inventory-api/blob/main/app/schemas/category.py"
click node_product_schema "https://github.com/matnoren/inventory-api/blob/main/app/schemas/product.py"
click node_db_session "https://github.com/matnoren/inventory-api/blob/main/app/db/session.py"
click node_config "https://github.com/matnoren/inventory-api/blob/main/app/core/config.py"
click node_exceptions "https://github.com/matnoren/inventory-api/blob/main/app/core/exceptions.py"
click node_main "https://github.com/matnoren/inventory-api/blob/main/app/main.py"

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_auth_routes,node_user_routes,node_category_routes,node_product_routes,node_health,node_user_schema,node_auth_schema,node_category_schema,node_product_schema toneBlue
class node_auth_service,node_inventory_service,node_security toneAmber
class node_user_crud,node_category_crud,node_product_crud,node_user_model,node_category_model,node_product_model,node_client toneMint
class node_db_session,node_postgres,node_config,node_exceptions,node_main toneRose
```

## Components

### API routes

- [Auth endpoints](https://github.com/matnoren/inventory-api/blob/main/app/api/routes/auth.py): `app/api/routes/auth.py`
- [User endpoints](https://github.com/matnoren/inventory-api/blob/main/app/api/routes/users.py): `app/api/routes/users.py`
- [Category endpoints](https://github.com/matnoren/inventory-api/blob/main/app/api/routes/categories.py): `app/api/routes/categories.py`
- [Product endpoints](https://github.com/matnoren/inventory-api/blob/main/app/api/routes/products.py): `app/api/routes/products.py`
- [Health check](https://github.com/matnoren/inventory-api/blob/main/app/api/routes/health.py): `app/api/routes/health.py`
- [User validation](https://github.com/matnoren/inventory-api/blob/main/app/schemas/user.py): `app/schemas/user.py`
- [Token schemas](https://github.com/matnoren/inventory-api/blob/main/app/schemas/auth.py): `app/schemas/auth.py`
- [Category validation](https://github.com/matnoren/inventory-api/blob/main/app/schemas/category.py): `app/schemas/category.py`
- [Product validation](https://github.com/matnoren/inventory-api/blob/main/app/schemas/product.py): `app/schemas/product.py`

### Domain services

- [Authentication](https://github.com/matnoren/inventory-api/blob/main/app/services/auth.py): `app/services/auth.py`
- [Stock adjustment](https://github.com/matnoren/inventory-api/blob/main/app/services/inventory.py): `app/services/inventory.py`
- [JWT and hashing](https://github.com/matnoren/inventory-api/blob/main/app/core/security.py): `app/core/security.py`

### Persistence

- [User operations](https://github.com/matnoren/inventory-api/blob/main/app/crud/user.py): `app/crud/user.py`
- [Category operations](https://github.com/matnoren/inventory-api/blob/main/app/crud/category.py): `app/crud/category.py`
- [Product operations](https://github.com/matnoren/inventory-api/blob/main/app/crud/product.py): `app/crud/product.py`
- [User model](https://github.com/matnoren/inventory-api/blob/main/app/models/user.py): `app/models/user.py`
- [Category model](https://github.com/matnoren/inventory-api/blob/main/app/models/category.py): `app/models/category.py`
- [Product model](https://github.com/matnoren/inventory-api/blob/main/app/models/product.py): `app/models/product.py`

### Runtime foundations

- [DB sessions](https://github.com/matnoren/inventory-api/blob/main/app/db/session.py): `app/db/session.py`
- **PostgreSQL**
- [Settings](https://github.com/matnoren/inventory-api/blob/main/app/core/config.py): `app/core/config.py`
- [HTTP errors](https://github.com/matnoren/inventory-api/blob/main/app/core/exceptions.py): `app/core/exceptions.py`
- [FastAPI app](https://github.com/matnoren/inventory-api/blob/main/app/main.py): `app/main.py`

### Other components

- **API caller**

## Connections

- API caller → FastAPI app: sends requests (evidence: `README.md`)
- FastAPI app → Auth endpoints: registers routes (evidence: `app/main.py`)
- FastAPI app → User endpoints: registers routes (evidence: `app/main.py`)
- FastAPI app → Category endpoints: registers routes (evidence: `app/main.py`)
- FastAPI app → Product endpoints: registers routes (evidence: `app/main.py`)
- FastAPI app → Health check: registers routes (evidence: `app/main.py`)
- Auth endpoints → Authentication: delegates login (evidence: `app/api/routes/auth.py`)
- Auth endpoints → User operations: checks and creates (evidence: `app/api/routes/auth.py`)
- Auth endpoints → User validation: validates input (evidence: `app/api/routes/auth.py`)
- Auth endpoints → Token schemas: returns token (evidence: `app/api/routes/auth.py`)
- User endpoints → User operations: manages users (evidence: `app/api/routes/users.py`)
- User endpoints → Authentication: checks access (evidence: `app/api/routes/users.py`)
- Category endpoints → Category operations: manages categories (evidence: `app/api/routes/categories.py`)
- Category endpoints → Authentication: checks access (evidence: `app/api/routes/categories.py`)
- Product endpoints → Product operations: manages products (evidence: `app/api/routes/products.py`)
- Product endpoints → Stock adjustment: adjusts stock (evidence: `app/api/routes/products.py`)
- Product endpoints → Authentication: checks access (evidence: `app/api/routes/products.py`)
- Authentication → User operations: loads users (evidence: `app/services/auth.py`)
- Authentication → JWT and hashing: verifies and signs (evidence: `app/services/auth.py`)
- Authentication → DB sessions: gets DB dependency (evidence: `app/services/auth.py`)
- User operations → User model: queries and writes (evidence: `app/crud/user.py`)
- User operations → JWT and hashing: hashes passwords (evidence: `app/crud/user.py`)
- User operations → User validation: accepts updates (evidence: `app/crud/user.py`)
- Category operations → Category model: queries and writes (evidence: `app/crud/category.py`)
- Category operations → Category validation: accepts updates (evidence: `app/crud/category.py`)
- Product operations → Product model: queries and writes (evidence: `app/crud/product.py`)
- Product operations → Product validation: accepts updates (evidence: `app/crud/product.py`)
- Stock adjustment → Product operations: updates stock (evidence: `app/services/inventory.py`)
- Stock adjustment → Product model: checks stock (evidence: `app/services/inventory.py`)
- Stock adjustment → Product validation: uses stock update (evidence: `app/services/inventory.py`)
- DB sessions → Settings: loads DB settings (evidence: `app/db/session.py`)
- DB sessions → PostgreSQL: connects (evidence: `app/db/session.py`)
- Health check → DB sessions: checks DB (evidence: `app/api/routes/health.py`)
- Auth endpoints → HTTP errors: raises conflicts (evidence: `app/api/routes/auth.py`)
