# edwin-ngugi/retail_management architecture

> Architecture diagram of the GitHub repository edwin-ngugi/retail_management, 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/edwin-ngugi/retail_management
- Repository: https://github.com/edwin-ngugi/retail_management

## Overview

This Django application supports multi-branch retail inventory, purchasing, point-of-sale, approvals, and reporting. The main workflow is a staff or API client submitting inventory or sales data; API views and serializers validate and execute domain operations against the stock models, while analytics services provide reporting. Admin screens support operational management, and approvals can trigger email notifications. The source excerpts are partial, so edges are limited to relationships documented in the index or shown directly; unsampled integrations are not inferred.

Main entry points: [`stocks/models.py`](https://github.com/edwin-ngugi/retail_management/blob/main/stocks/models.py) (Stock and sales records), [`apis/views.py`](https://github.com/edwin-ngugi/retail_management/blob/main/apis/views.py) (API operations), [`apis/tasks.py`](https://github.com/edwin-ngugi/retail_management/blob/main/apis/tasks.py) (Approval email tasks), [`stocks/admin.py`](https://github.com/edwin-ngugi/retail_management/blob/main/stocks/admin.py) (Django admin)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_operations["Retail operations"]
  node_admin_ui["Django admin<br/>[admin.py]"]
  node_stock_domain[("Stock and sales records<br/>[models.py]")]
  node_pricing_lookup["Branch pricing lookup<br/>[views.py]"]
  node_pricing_script["Sale price helper"]
end

subgraph group_api["API and approvals"]
  node_api_routes["API routes<br/>[urls.py]"]
  node_api_views["API operations<br/>[views.py]"]
  node_api_serializers["Request serializers<br/>[serializers.py]"]
  node_approval_email_tasks["Approval email tasks<br/>[tasks.py]"]
  node_approval_emails["Approval emails<br/>[emails.py]"]
end

subgraph group_analytics["Analytics and realtime"]
  node_analytics_views["Analytics endpoints<br/>[views.py]"]
  node_analytics_services["Analytics and calculations<br/>[services.py]"]
  node_snapshot_task["Monthly stock snapshots<br/>[tasks.py]"]
  node_analytics_signals["Analytics signals<br/>[signals.py]"]
  node_asgi["ASGI application<br/>[asgi.py]"]
  node_ws_routes["Analytics WebSocket routes<br/>[routing.py]"]
  node_analytics_consumer["Analytics WebSocket consumer<br/>[consumers.py]"]
end

node_staff(("Staff user"))
node_api_client(("API client"))

node_staff -->|"manages records"| node_admin_ui
node_admin_ui -->|"reads and updates"| node_stock_domain
node_staff -->|"requests pricing"| node_pricing_lookup
node_pricing_lookup -->|"queries pricing"| node_stock_domain
node_api_client -->|"sends requests"| node_api_routes
node_api_routes -->|"routes to"| node_api_views
node_api_views -->|"validates data"| node_api_serializers
node_api_views -->|"executes operations"| node_stock_domain
node_api_serializers -->|"validates domain data"| node_stock_domain
node_api_views -->|"requests calculations"| node_analytics_services
node_api_views -->|"queues notifications"| node_approval_email_tasks
node_approval_email_tasks -->|"loads approval"| node_stock_domain
node_approval_email_tasks -->|"dispatches email"| node_approval_emails
node_approval_emails -->|"resolves branch"| node_stock_domain
node_analytics_views -->|"queries records"| node_stock_domain
node_analytics_services -->|"aggregates records"| node_stock_domain
node_snapshot_task -->|"updates snapshots"| node_stock_domain
node_asgi -->|"loads routes"| node_ws_routes
node_ws_routes -->|"dispatches connections"| node_analytics_consumer

click node_admin_ui "https://github.com/edwin-ngugi/retail_management/blob/main/stocks/admin.py"
click node_stock_domain "https://github.com/edwin-ngugi/retail_management/blob/main/stocks/models.py"
click node_pricing_lookup "https://github.com/edwin-ngugi/retail_management/blob/main/stocks/views.py"
click node_pricing_script "https://github.com/edwin-ngugi/retail_management/blob/main/stocks/static/admin/js/sale_item_pricing.js"
click node_api_routes "https://github.com/edwin-ngugi/retail_management/blob/main/apis/urls.py"
click node_api_views "https://github.com/edwin-ngugi/retail_management/blob/main/apis/views.py"
click node_api_serializers "https://github.com/edwin-ngugi/retail_management/blob/main/apis/serializers.py"
click node_approval_email_tasks "https://github.com/edwin-ngugi/retail_management/blob/main/apis/tasks.py"
click node_approval_emails "https://github.com/edwin-ngugi/retail_management/blob/main/apis/emails.py"
click node_analytics_views "https://github.com/edwin-ngugi/retail_management/blob/main/analytics/views.py"
click node_analytics_services "https://github.com/edwin-ngugi/retail_management/blob/main/analytics/services.py"
click node_snapshot_task "https://github.com/edwin-ngugi/retail_management/blob/main/analytics/tasks.py"
click node_analytics_signals "https://github.com/edwin-ngugi/retail_management/blob/main/analytics/signals.py"
click node_asgi "https://github.com/edwin-ngugi/retail_management/blob/main/myproject/asgi.py"
click node_ws_routes "https://github.com/edwin-ngugi/retail_management/blob/main/analytics/routing.py"
click node_analytics_consumer "https://github.com/edwin-ngugi/retail_management/blob/main/analytics/consumers.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_admin_ui,node_stock_domain,node_pricing_lookup,node_pricing_script,node_staff,node_api_client toneBlue
class node_api_routes,node_api_views,node_api_serializers,node_approval_email_tasks,node_approval_emails toneAmber
class node_analytics_views,node_analytics_services,node_snapshot_task,node_analytics_signals,node_asgi,node_ws_routes,node_analytics_consumer toneMint
```

## Components

### Retail operations

- [Django admin](https://github.com/edwin-ngugi/retail_management/blob/main/stocks/admin.py): `stocks/admin.py`
- [Stock and sales records](https://github.com/edwin-ngugi/retail_management/blob/main/stocks/models.py): `stocks/models.py`
- [Branch pricing lookup](https://github.com/edwin-ngugi/retail_management/blob/main/stocks/views.py): `stocks/views.py`
- [Sale price helper](https://github.com/edwin-ngugi/retail_management/blob/main/stocks/static/admin/js/sale_item_pricing.js): `stocks/static/admin/js/sale_item_pricing.js`

### API and approvals

- [API routes](https://github.com/edwin-ngugi/retail_management/blob/main/apis/urls.py): `apis/urls.py`
- [API operations](https://github.com/edwin-ngugi/retail_management/blob/main/apis/views.py): `apis/views.py`
- [Request serializers](https://github.com/edwin-ngugi/retail_management/blob/main/apis/serializers.py): `apis/serializers.py`
- [Approval email tasks](https://github.com/edwin-ngugi/retail_management/blob/main/apis/tasks.py): `apis/tasks.py`
- [Approval emails](https://github.com/edwin-ngugi/retail_management/blob/main/apis/emails.py): `apis/emails.py`

### Analytics and realtime

- [Analytics endpoints](https://github.com/edwin-ngugi/retail_management/blob/main/analytics/views.py): `analytics/views.py`
- [Analytics and calculations](https://github.com/edwin-ngugi/retail_management/blob/main/analytics/services.py): `analytics/services.py`
- [Monthly stock snapshots](https://github.com/edwin-ngugi/retail_management/blob/main/analytics/tasks.py): `analytics/tasks.py`
- [Analytics signals](https://github.com/edwin-ngugi/retail_management/blob/main/analytics/signals.py): `analytics/signals.py`
- [ASGI application](https://github.com/edwin-ngugi/retail_management/blob/main/myproject/asgi.py): `myproject/asgi.py`
- [Analytics WebSocket routes](https://github.com/edwin-ngugi/retail_management/blob/main/analytics/routing.py): `analytics/routing.py`
- [Analytics WebSocket consumer](https://github.com/edwin-ngugi/retail_management/blob/main/analytics/consumers.py): `analytics/consumers.py`

### Other components

- **Staff user**
- **API client**

## Connections

- Staff user → Django admin: manages records (evidence: `stocks/admin.py`)
- Django admin → Stock and sales records: reads and updates (evidence: `stocks/admin.py`)
- Staff user → Branch pricing lookup: requests pricing (evidence: `stocks/views.py`)
- Branch pricing lookup → Stock and sales records: queries pricing (evidence: `stocks/views.py`)
- API client → API routes: sends requests (evidence: `apis/urls.py`)
- API routes → API operations: routes to (evidence: `apis/urls.py`)
- API operations → Request serializers: validates data (evidence: `apis/views.py`)
- API operations → Stock and sales records: executes operations (evidence: `apis/views.py`)
- Request serializers → Stock and sales records: validates domain data (evidence: `apis/serializers.py`)
- API operations → Analytics and calculations: requests calculations (evidence: `apis/views.py`)
- API operations → Approval email tasks: queues notifications (evidence: `apis/views.py`)
- Approval email tasks → Stock and sales records: loads approval (evidence: `apis/tasks.py`)
- Approval email tasks → Approval emails: dispatches email (evidence: `apis/tasks.py`)
- Approval emails → Stock and sales records: resolves branch (evidence: `apis/emails.py`)
- Analytics endpoints → Stock and sales records: queries records (evidence: `analytics/views.py`)
- Analytics and calculations → Stock and sales records: aggregates records (evidence: `analytics/services.py`)
- Monthly stock snapshots → Stock and sales records: updates snapshots (evidence: `analytics/tasks.py`)
- ASGI application → Analytics WebSocket routes: loads routes (evidence: `myproject/asgi.py`)
- Analytics WebSocket routes → Analytics WebSocket consumer: dispatches connections (evidence: `analytics/routing.py`)
