# kaela122/pharmacy-inventory-recognizer architecture

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

- Interactive diagram: https://gitdiagram.com/kaela122/pharmacy-inventory-recognizer
- Repository: https://github.com/kaela122/pharmacy-inventory-recognizer

## Overview

PharmaHub combines pharmacy inventory operations with a product-code DFA recognizer. Staff use the React screens to manage medicines, categories, suppliers, purchase orders, stock movements, analytics, and users; medicine creation checks its SKU before saving. The FastAPI backend exposes these capabilities over the API and persists them through SQLAlchemy. The README documents the full automata-construction and theory experience; source excerpts show product validation and application setup, but not most route-to-service wiring, so those links are omitted or marked unverified.

Main entry points: [`pharmacy-inventory-recognizer/frontend/src/api/index.ts`](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/frontend/src/api/index.ts) (API client), [`pharmacy-inventory-recognizer/frontend/src/pages`](https://github.com/kaela122/pharmacy-inventory-recognizer/tree/main/pharmacy-inventory-recognizer/frontend/src/pages) (Operations screens), [`pharmacy-inventory-recognizer/backend/app/api/routes`](https://github.com/kaela122/pharmacy-inventory-recognizer/tree/main/pharmacy-inventory-recognizer/backend/app/api/routes) (API routes), [`pharmacy-inventory-recognizer/backend/app/automata/recognizer.py`](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/automata/recognizer.py) (SKU recognizer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Staff interface"]
  node_webapp["React app shell<br/>[App.tsx]"]
  node_screens["Operations screens"]
  node_webapi["API client<br/>[index.ts]"]
  node_authstate["Browser auth state<br/>[auth.ts]"]
end

subgraph group_api["Backend API"]
  node_main["FastAPI app<br/>[main.py]"]
  node_routes["API routes"]
  node_authservice["Authentication<br/>[auth_service.py]"]
  node_security["Token security<br/>[security.py]"]
end

subgraph group_domain["Inventory domain"]
  node_productservice["Product management<br/>[product_service.py]"]
  node_domainservices["Inventory services"]
  node_models["Inventory records"]
  node_database[("SQL database<br/>[session.py]")]
  node_settings["Runtime settings<br/>[config.py]"]
  node_seed["Demo data setup<br/>[seed.py]"]
end

subgraph group_automata["Code recognition"]
  node_automata_def["SKU language<br/>[definitions.py]"]
  node_construction["DFA construction<br/>[construction.py]"]
  node_dfa["DFA execution<br/>[dfa.py]"]
  node_recognizer["SKU recognizer<br/>[recognizer.py]"]
  node_theory["Theory walkthrough<br/>[TheoryPage.tsx]"]
  node_simulator["CLI simulator<br/>[simulator.py]"]
end

node_staff(("Pharmacy staff"))

node_staff -->|"uses"| node_webapp
node_webapp -->|"selects"| node_screens
node_screens -->|"requests"| node_webapi
node_webapi -->|"loads token"| node_authstate
node_webapi -.->|"calls API"| node_routes
node_main -->|"registers"| node_routes
node_routes -->|"login handler"| node_authservice
node_authservice -->|"verifies and signs"| node_security
node_productservice -->|"validates SKU"| node_recognizer
node_productservice -->|"reads and writes"| node_models
node_domainservices -.->|"uses records"| node_models
node_main -->|"seeds startup"| node_seed
node_seed -->|"opens session"| node_database
node_database -->|"reads URL"| node_settings
node_construction -->|"builds from"| node_automata_def
node_dfa -->|"uses definition"| node_automata_def
node_recognizer -->|"runs"| node_dfa
node_screens -.->|"opens walkthrough"| node_theory
node_theory -->|"fetches theory"| node_webapi
node_simulator -->|"demonstrates build"| node_construction
node_simulator -->|"simulates codes"| node_recognizer

click node_webapp "https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/frontend/src/App.tsx"
click node_screens "https://github.com/kaela122/pharmacy-inventory-recognizer/tree/main/pharmacy-inventory-recognizer/frontend/src/pages"
click node_webapi "https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/frontend/src/api/index.ts"
click node_authstate "https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/frontend/src/lib/auth.ts"
click node_main "https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/main.py"
click node_routes "https://github.com/kaela122/pharmacy-inventory-recognizer/tree/main/pharmacy-inventory-recognizer/backend/app/api/routes"
click node_authservice "https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/services/auth_service.py"
click node_security "https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/core/security.py"
click node_productservice "https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/services/product_service.py"
click node_domainservices "https://github.com/kaela122/pharmacy-inventory-recognizer/tree/main/pharmacy-inventory-recognizer/backend/app/services"
click node_models "https://github.com/kaela122/pharmacy-inventory-recognizer/tree/main/pharmacy-inventory-recognizer/backend/app/models"
click node_database "https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/db/session.py"
click node_settings "https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/core/config.py"
click node_seed "https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/db/seed.py"
click node_automata_def "https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/automata/definitions.py"
click node_construction "https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/automata/construction.py"
click node_dfa "https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/automata/dfa.py"
click node_recognizer "https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/automata/recognizer.py"
click node_theory "https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/frontend/src/pages/TheoryPage.tsx"
click node_simulator "https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/cli/simulator.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_webapp,node_screens,node_webapi,node_authstate toneBlue
class node_main,node_routes,node_authservice,node_security toneAmber
class node_productservice,node_domainservices,node_models,node_database,node_settings,node_seed toneMint
class node_automata_def,node_construction,node_dfa,node_recognizer,node_theory,node_simulator toneRose
class node_staff toneIndigo
```

## Components

### Staff interface

- [React app shell](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/frontend/src/App.tsx): `pharmacy-inventory-recognizer/frontend/src/App.tsx`
- [Operations screens](https://github.com/kaela122/pharmacy-inventory-recognizer/tree/main/pharmacy-inventory-recognizer/frontend/src/pages): `pharmacy-inventory-recognizer/frontend/src/pages`
- [API client](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/frontend/src/api/index.ts): `pharmacy-inventory-recognizer/frontend/src/api/index.ts`
- [Browser auth state](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/frontend/src/lib/auth.ts): `pharmacy-inventory-recognizer/frontend/src/lib/auth.ts`

### Backend API

- [FastAPI app](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/main.py): `pharmacy-inventory-recognizer/backend/app/main.py`
- [API routes](https://github.com/kaela122/pharmacy-inventory-recognizer/tree/main/pharmacy-inventory-recognizer/backend/app/api/routes): `pharmacy-inventory-recognizer/backend/app/api/routes`
- [Authentication](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/services/auth_service.py): `pharmacy-inventory-recognizer/backend/app/services/auth_service.py`
- [Token security](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/core/security.py): `pharmacy-inventory-recognizer/backend/app/core/security.py`

### Inventory domain

- [Product management](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/services/product_service.py): `pharmacy-inventory-recognizer/backend/app/services/product_service.py`
- [Inventory services](https://github.com/kaela122/pharmacy-inventory-recognizer/tree/main/pharmacy-inventory-recognizer/backend/app/services): `pharmacy-inventory-recognizer/backend/app/services`
- [Inventory records](https://github.com/kaela122/pharmacy-inventory-recognizer/tree/main/pharmacy-inventory-recognizer/backend/app/models): `pharmacy-inventory-recognizer/backend/app/models`
- [SQL database](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/db/session.py): `pharmacy-inventory-recognizer/backend/app/db/session.py`
- [Runtime settings](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/core/config.py): `pharmacy-inventory-recognizer/backend/app/core/config.py`
- [Demo data setup](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/db/seed.py): `pharmacy-inventory-recognizer/backend/app/db/seed.py`

### Code recognition

- [SKU language](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/automata/definitions.py): `pharmacy-inventory-recognizer/backend/app/automata/definitions.py`
- [DFA construction](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/automata/construction.py): `pharmacy-inventory-recognizer/backend/app/automata/construction.py`
- [DFA execution](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/automata/dfa.py): `pharmacy-inventory-recognizer/backend/app/automata/dfa.py`
- [SKU recognizer](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/backend/app/automata/recognizer.py): `pharmacy-inventory-recognizer/backend/app/automata/recognizer.py`
- [Theory walkthrough](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/frontend/src/pages/TheoryPage.tsx): `pharmacy-inventory-recognizer/frontend/src/pages/TheoryPage.tsx`
- [CLI simulator](https://github.com/kaela122/pharmacy-inventory-recognizer/blob/main/pharmacy-inventory-recognizer/cli/simulator.py): `pharmacy-inventory-recognizer/cli/simulator.py`

### Other components

- **Pharmacy staff**

## Connections

- Pharmacy staff → React app shell: uses (evidence: `README.md`)
- React app shell → Operations screens: selects (evidence: `pharmacy-inventory-recognizer/frontend/src/App.tsx`)
- Operations screens → API client: requests (evidence: `pharmacy-inventory-recognizer/frontend/src/api/index.ts`)
- API client → Browser auth state: loads token (evidence: `pharmacy-inventory-recognizer/frontend/src/api/index.ts`)
- API client → API routes: calls API
- FastAPI app → API routes: registers (evidence: `pharmacy-inventory-recognizer/backend/app/main.py`)
- API routes → Authentication: login handler (evidence: `pharmacy-inventory-recognizer/backend/app/api/routes/auth.py`)
- Authentication → Token security: verifies and signs (evidence: `pharmacy-inventory-recognizer/backend/app/services/auth_service.py`)
- Product management → SKU recognizer: validates SKU (evidence: `pharmacy-inventory-recognizer/backend/app/services/product_service.py`)
- Product management → Inventory records: reads and writes (evidence: `pharmacy-inventory-recognizer/backend/app/services/product_service.py`)
- Inventory services → Inventory records: uses records (evidence: `pharmacy-inventory-recognizer/backend/app/services/auth_service.py`)
- FastAPI app → Demo data setup: seeds startup (evidence: `pharmacy-inventory-recognizer/backend/app/main.py`)
- Demo data setup → SQL database: opens session (evidence: `pharmacy-inventory-recognizer/backend/app/db/seed.py`)
- SQL database → Runtime settings: reads URL (evidence: `pharmacy-inventory-recognizer/backend/app/db/session.py`)
- DFA construction → SKU language: builds from (evidence: `pharmacy-inventory-recognizer/backend/app/automata/construction.py`)
- DFA execution → SKU language: uses definition (evidence: `pharmacy-inventory-recognizer/backend/app/automata/dfa.py`)
- SKU recognizer → DFA execution: runs (evidence: `pharmacy-inventory-recognizer/backend/app/automata/recognizer.py`)
- Operations screens → Theory walkthrough: opens walkthrough
- Theory walkthrough → API client: fetches theory (evidence: `pharmacy-inventory-recognizer/frontend/src/api/index.ts`)
- CLI simulator → DFA construction: demonstrates build (evidence: `pharmacy-inventory-recognizer/cli/simulator.py`)
- CLI simulator → SKU recognizer: simulates codes (evidence: `pharmacy-inventory-recognizer/cli/simulator.py`)
