# steevanj/aforro_backend architecture

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

- Interactive diagram: https://gitdiagram.com/steevanj/aforro_backend
- Repository: https://github.com/steevanj/aforro_backend

## Overview

Aforro is a Django REST backend for catalog, store inventory, product discovery, and order management. Its key workflow accepts an order, validates requested items, locks and checks store inventory, persists the order and items, and—only on confirmation—deducts stock and schedules asynchronous confirmation. The graph also preserves search/autocomplete, cached inventory, and seed-data capabilities documented or represented in the repository. Evidence is limited to the README and indexed excerpts or references; undocumented route wiring and some cache/task configuration details are not inferred.

Main entry points: [`orders/views/order_create.py`](https://github.com/steevanj/aforro_backend/blob/main/orders/views/order_create.py) (Order creation), [`search/views/product_search.py`](https://github.com/steevanj/aforro_backend/blob/main/search/views/product_search.py) (Product search), [`config/urls.py`](https://github.com/steevanj/aforro_backend/blob/main/config/urls.py) (Django REST API), [`stores/models.py`](https://github.com/steevanj/aforro_backend/blob/main/stores/models.py) (Store inventory)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_catalog["Catalog and discovery"]
  node_product_data["Products and categories<br/>[models.py]"]
  node_product_serializers["Product serializers"]
  node_search["Product search<br/>[product_search.py]"]
  node_autocomplete["Autocomplete<br/>[product_suggest.py]"]
  node_search_pagination["Search pagination<br/>[pagination.py]"]
  node_search_serializers["Search results<br/>[serializers.py]"]
end

subgraph group_inventory["Stores and inventory"]
  node_store_inventory["Store inventory<br/>[models.py]"]
  node_inventory_api["Inventory API<br/>[views.py]"]
  node_inventory_cache_key["Inventory cache keys<br/>[cache.py]"]
  node_seed_command["Seed data command<br/>[seed_data.py]"]
end

subgraph group_orders["Order processing"]
  node_order_create["Order creation<br/>[order_create.py]"]
  node_order_data["Orders and items<br/>[models.py]"]
  node_order_serializers["Order serializers<br/>[order_item.py]"]
end

subgraph group_async["Async and caching"]
  node_order_task["Order confirmation task<br/>[tasks.py]"]
  node_celery_config["Celery configuration<br/>[celery.py]"]
  node_worker["Celery worker"]
end

node_client(("API client"))
node_api_db[("PostgreSQL")]
node_redis[("Redis")]
node_api["Django REST API<br/>[urls.py]"]

node_client -->|"sends requests"| node_api
node_api -.->|"routes order requests"| node_order_create
node_order_create -->|"validates and serializes"| node_order_serializers
node_order_create -->|"locks and updates"| node_store_inventory
node_order_create -->|"creates and fetches"| node_order_data
node_order_create -->|"schedules on commit"| node_order_task
node_order_task -->|"loads order"| node_order_data
node_order_task -->|"runs asynchronously"| node_worker
node_order_task -->|"uses app configuration"| node_celery_config
node_api -.->|"routes search requests"| node_search
node_search -->|"queries products"| node_product_data
node_search -->|"filters stock"| node_store_inventory
node_search -->|"paginates results"| node_search_pagination
node_search -->|"serializes results"| node_search_serializers
node_api -.->|"routes suggestions"| node_autocomplete
node_autocomplete -->|"queries products"| node_product_data
node_api -.->|"serves inventory"| node_inventory_api
node_inventory_api -->|"queries inventory"| node_store_inventory
node_inventory_api -->|"builds cache key"| node_inventory_cache_key
node_inventory_api -->|"reads and writes cache"| node_redis
node_order_create -.->|"invalidates inventory cache"| node_redis
node_seed_command -->|"creates catalog data"| node_product_data
node_seed_command -->|"creates stores and stock"| node_store_inventory
node_order_data -->|"persists order records"| node_api_db
node_product_data -->|"persists catalog"| node_api_db
node_store_inventory -->|"persists inventory"| node_api_db

click node_api "https://github.com/steevanj/aforro_backend/blob/main/config/urls.py"
click node_product_data "https://github.com/steevanj/aforro_backend/blob/main/products/models.py"
click node_product_serializers "https://github.com/steevanj/aforro_backend/tree/main/products/serializers"
click node_search "https://github.com/steevanj/aforro_backend/blob/main/search/views/product_search.py"
click node_autocomplete "https://github.com/steevanj/aforro_backend/blob/main/search/views/product_suggest.py"
click node_search_pagination "https://github.com/steevanj/aforro_backend/blob/main/search/pagination.py"
click node_search_serializers "https://github.com/steevanj/aforro_backend/blob/main/search/serializers.py"
click node_store_inventory "https://github.com/steevanj/aforro_backend/blob/main/stores/models.py"
click node_inventory_api "https://github.com/steevanj/aforro_backend/blob/main/stores/views.py"
click node_inventory_cache_key "https://github.com/steevanj/aforro_backend/blob/main/stores/cache.py"
click node_order_create "https://github.com/steevanj/aforro_backend/blob/main/orders/views/order_create.py"
click node_order_data "https://github.com/steevanj/aforro_backend/blob/main/orders/models.py"
click node_order_serializers "https://github.com/steevanj/aforro_backend/blob/main/orders/serializers/order_item.py"
click node_order_task "https://github.com/steevanj/aforro_backend/blob/main/orders/tasks.py"
click node_celery_config "https://github.com/steevanj/aforro_backend/blob/main/config/celery.py"
click node_seed_command "https://github.com/steevanj/aforro_backend/blob/main/stores/management/commands/seed_data.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_product_data,node_product_serializers,node_search,node_autocomplete,node_search_pagination,node_search_serializers,node_client toneBlue
class node_store_inventory,node_inventory_api,node_inventory_cache_key,node_seed_command,node_api_db,node_redis toneAmber
class node_order_create,node_order_data,node_order_serializers,node_api toneMint
class node_order_task,node_celery_config,node_worker toneRose
```

## Components

### Catalog and discovery

- [Products and categories](https://github.com/steevanj/aforro_backend/blob/main/products/models.py): `products/models.py`
- [Product serializers](https://github.com/steevanj/aforro_backend/tree/main/products/serializers): `products/serializers`
- [Product search](https://github.com/steevanj/aforro_backend/blob/main/search/views/product_search.py): `search/views/product_search.py`
- [Autocomplete](https://github.com/steevanj/aforro_backend/blob/main/search/views/product_suggest.py): `search/views/product_suggest.py`
- [Search pagination](https://github.com/steevanj/aforro_backend/blob/main/search/pagination.py): `search/pagination.py`
- [Search results](https://github.com/steevanj/aforro_backend/blob/main/search/serializers.py): `search/serializers.py`

### Stores and inventory

- [Store inventory](https://github.com/steevanj/aforro_backend/blob/main/stores/models.py): `stores/models.py`
- [Inventory API](https://github.com/steevanj/aforro_backend/blob/main/stores/views.py): `stores/views.py`
- [Inventory cache keys](https://github.com/steevanj/aforro_backend/blob/main/stores/cache.py): `stores/cache.py`
- [Seed data command](https://github.com/steevanj/aforro_backend/blob/main/stores/management/commands/seed_data.py): `stores/management/commands/seed_data.py`

### Order processing

- [Order creation](https://github.com/steevanj/aforro_backend/blob/main/orders/views/order_create.py): `orders/views/order_create.py`
- [Orders and items](https://github.com/steevanj/aforro_backend/blob/main/orders/models.py): `orders/models.py`
- [Order serializers](https://github.com/steevanj/aforro_backend/blob/main/orders/serializers/order_item.py): `orders/serializers/order_item.py`

### Async and caching

- [Order confirmation task](https://github.com/steevanj/aforro_backend/blob/main/orders/tasks.py): `orders/tasks.py`
- [Celery configuration](https://github.com/steevanj/aforro_backend/blob/main/config/celery.py): `config/celery.py`
- **Celery worker**

### Other components

- **API client**
- **PostgreSQL**
- **Redis**
- [Django REST API](https://github.com/steevanj/aforro_backend/blob/main/config/urls.py): `config/urls.py`

## Connections

- API client → Django REST API: sends requests (evidence: `README.md`)
- Django REST API → Order creation: routes order requests
- Order creation → Order serializers: validates and serializes (evidence: `orders/views/order_create.py`)
- Order creation → Store inventory: locks and updates (evidence: `orders/views/order_create.py`)
- Order creation → Orders and items: creates and fetches (evidence: `orders/views/order_create.py`)
- Order creation → Order confirmation task: schedules on commit (evidence: `orders/views/order_create.py`)
- Order confirmation task → Orders and items: loads order (evidence: `orders/tasks.py`)
- Order confirmation task → Celery worker: runs asynchronously (evidence: `README.md`)
- Order confirmation task → Celery configuration: uses app configuration (evidence: `orders/tasks.py`)
- Django REST API → Product search: routes search requests
- Product search → Products and categories: queries products (evidence: `search/views/product_search.py`)
- Product search → Store inventory: filters stock (evidence: `search/views/product_search.py`)
- Product search → Search pagination: paginates results (evidence: `search/views/product_search.py`)
- Product search → Search results: serializes results (evidence: `search/views/product_search.py`)
- Django REST API → Autocomplete: routes suggestions
- Autocomplete → Products and categories: queries products (evidence: `search/views/product_suggest.py`)
- Django REST API → Inventory API: serves inventory
- Inventory API → Store inventory: queries inventory (evidence: `stores/views.py`)
- Inventory API → Inventory cache keys: builds cache key (evidence: `stores/views.py`)
- Inventory API → Redis: reads and writes cache (evidence: `README.md`)
- Order creation → Redis: invalidates inventory cache
- Seed data command → Products and categories: creates catalog data (evidence: `stores/management/commands/seed_data.py`)
- Seed data command → Store inventory: creates stores and stock (evidence: `stores/management/commands/seed_data.py`)
- Orders and items → PostgreSQL: persists order records (evidence: `README.md`)
- Products and categories → PostgreSQL: persists catalog (evidence: `README.md`)
- Store inventory → PostgreSQL: persists inventory (evidence: `README.md`)
