# josephclintonsahaya-byte/audit_trail architecture

> Architecture diagram of the GitHub repository josephclintonsahaya-byte/audit_trail, 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/josephclintonsahaya-byte/audit_trail
- Repository: https://github.com/josephclintonsahaya-byte/audit_trail

## Overview

TrackFlow is an audit-trail API and client for warehouse inventory and shipment workflows. Users authenticate, manage products, warehouses, and stock, then create and track shipments; stock moves only when a shipment is delivered. Shipment workflows are available through a legacy API and a CQRS interface: commands append versioned events with optimistic concurrency, while queries reconstruct state from the event stream. A separate audit log records general business activity. The excerpts show key route, controller, service, and persistence relationships; unsampled capabilities and wiring are included only where documented in the README.

Main entry points: [`server/src/app.ts`](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/app.ts) (API router), [`server/src/controllers/inventory.controller.ts`](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/controllers/inventory.controller.ts) (Inventory management), [`server/src/services/shipment.service.ts`](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/services/shipment.service.ts) (Shipment operations), [`server/src/services/event-sourcing/event-store.service.ts`](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/services/event-sourcing/event-store.service.ts) (Event store service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and identity"]
  node_client["Client API<br/>[api.ts]"]
  node_app["API router<br/>[app.ts]"]
  node_auth["Authentication<br/>[auth.service.ts]"]
  node_userdb[("User records<br/>[User.ts]")]
end

subgraph group_operations["Warehouse operations"]
  node_products["Product catalog"]
  node_productdb[("Products<br/>[Product.ts]")]
  node_warehouse["Warehouse management"]
  node_warehousedb[("Warehouses<br/>[Warehouse.ts]")]
  node_inventory["Inventory management"]
  node_inventoryclient["Inventory client"]
  node_inventorydb[("Inventory records<br/>[Inventory.ts]")]
  node_legacyship["Legacy shipments"]
  node_shipmentservice["Shipment operations"]
  node_shipmentdb[("Shipment snapshots<br/>[Shipment.ts]")]
end

subgraph group_sourcing["Shipment event sourcing"]
  node_commands["Shipment commands"]
  node_commandservice["Command handling"]
  node_eventstore["Event store service"]
  node_reducer["State replay"]
  node_queries["Shipment queries"]
  node_eventdb[("Shipment event store<br/>[EventStore.ts]")]
end

subgraph group_audit["Audit and persistence"]
  node_auditservice["Audit logging<br/>[event.service.ts]"]
  node_auditdb[("Business audit log<br/>[Event.ts]")]
  node_auditclient["Audit client<br/>[auditService.ts]"]
end

node_operator(("User"))

node_operator -.->|"uses"| node_client
node_client -.->|"requests API"| node_app
node_app -.->|"routes auth"| node_auth
node_auth -->|"reads and writes"| node_userdb
node_app -->|"routes products"| node_products
node_products -->|"accesses"| node_productdb
node_app -->|"routes warehouses"| node_warehouse
node_warehouse -.->|"manages"| node_warehousedb
node_app -->|"routes inventory"| node_inventory
node_inventoryclient -->|"calls"| node_client
node_inventory -->|"reads and writes"| node_inventorydb
node_inventory -->|"checks product"| node_productdb
node_inventory -->|"checks warehouse"| node_warehousedb
node_inventory -->|"records activity"| node_auditservice
node_app -->|"routes shipments"| node_legacyship
node_legacyship -->|"delegates"| node_shipmentservice
node_shipmentservice -->|"updates snapshot"| node_shipmentdb
node_shipmentservice -->|"transfers stock"| node_inventorydb
node_shipmentservice -->|"records activity"| node_auditservice
node_app -->|"routes commands"| node_commands
node_commands -->|"dispatches"| node_commandservice
node_commandservice -.->|"appends events"| node_eventstore
node_app -->|"routes queries"| node_queries
node_queries -->|"loads and reconstructs"| node_eventstore
node_eventstore -->|"reads and writes"| node_eventdb
node_eventstore -->|"replays events"| node_reducer
node_shipmentservice -->|"appends and reads stream"| node_eventstore
node_auditservice -->|"saves events"| node_auditdb
node_auditclient -.->|"uses API"| node_client

click node_client "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/client/src/services/api.ts"
click node_app "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/app.ts"
click node_auth "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/services/auth.service.ts"
click node_userdb "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/models/User.ts"
click node_products "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/controllers/product.controller.ts"
click node_productdb "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/models/Product.ts"
click node_warehouse "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/controllers/warehouse.controller.ts"
click node_warehousedb "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/models/Warehouse.ts"
click node_inventory "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/controllers/inventory.controller.ts"
click node_inventoryclient "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/client/src/services/inventoryService.ts"
click node_inventorydb "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/models/Inventory.ts"
click node_legacyship "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/controllers/shipment.controller.ts"
click node_shipmentservice "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/services/shipment.service.ts"
click node_shipmentdb "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/models/Shipment.ts"
click node_commands "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/controllers/shipment.command.controller.ts"
click node_commandservice "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/services/event-sourcing/shipment.commands.service.ts"
click node_eventstore "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/services/event-sourcing/event-store.service.ts"
click node_reducer "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/services/event-sourcing/shipment.reducer.ts"
click node_queries "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/controllers/shipment.query.controller.ts"
click node_eventdb "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/models/EventStore.ts"
click node_auditservice "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/services/event.service.ts"
click node_auditdb "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/models/Event.ts"
click node_auditclient "https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/client/src/services/auditService.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_client,node_app,node_auth,node_userdb,node_operator toneBlue
class node_products,node_productdb,node_warehouse,node_warehousedb,node_inventory,node_inventoryclient,node_inventorydb,node_legacyship,node_shipmentservice,node_shipmentdb toneAmber
class node_commands,node_commandservice,node_eventstore,node_reducer,node_queries,node_eventdb toneMint
class node_auditservice,node_auditdb,node_auditclient toneRose
```

## Components

### API and identity

- [Client API](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/client/src/services/api.ts): `client/src/services/api.ts`
- [API router](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/app.ts): `server/src/app.ts`
- [Authentication](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/services/auth.service.ts): `server/src/services/auth.service.ts`
- [User records](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/models/User.ts): `server/src/models/User.ts`

### Warehouse operations

- [Product catalog](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/controllers/product.controller.ts): `server/src/controllers/product.controller.ts`
- [Products](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/models/Product.ts): `server/src/models/Product.ts`
- [Warehouse management](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/controllers/warehouse.controller.ts): `server/src/controllers/warehouse.controller.ts`
- [Warehouses](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/models/Warehouse.ts): `server/src/models/Warehouse.ts`
- [Inventory management](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/controllers/inventory.controller.ts): `server/src/controllers/inventory.controller.ts`
- [Inventory client](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/client/src/services/inventoryService.ts): `client/src/services/inventoryService.ts`
- [Inventory records](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/models/Inventory.ts): `server/src/models/Inventory.ts`
- [Legacy shipments](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/controllers/shipment.controller.ts): `server/src/controllers/shipment.controller.ts`
- [Shipment operations](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/services/shipment.service.ts): `server/src/services/shipment.service.ts`
- [Shipment snapshots](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/models/Shipment.ts): `server/src/models/Shipment.ts`

### Shipment event sourcing

- [Shipment commands](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/controllers/shipment.command.controller.ts): `server/src/controllers/shipment.command.controller.ts`
- [Command handling](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/services/event-sourcing/shipment.commands.service.ts): `server/src/services/event-sourcing/shipment.commands.service.ts`
- [Event store service](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/services/event-sourcing/event-store.service.ts): `server/src/services/event-sourcing/event-store.service.ts`
- [State replay](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/services/event-sourcing/shipment.reducer.ts): `server/src/services/event-sourcing/shipment.reducer.ts`
- [Shipment queries](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/controllers/shipment.query.controller.ts): `server/src/controllers/shipment.query.controller.ts`
- [Shipment event store](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/models/EventStore.ts): `server/src/models/EventStore.ts`

### Audit and persistence

- [Audit logging](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/services/event.service.ts): `server/src/services/event.service.ts`
- [Business audit log](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/server/src/models/Event.ts): `server/src/models/Event.ts`
- [Audit client](https://github.com/josephclintonsahaya-byte/audit_trail/blob/main/client/src/services/auditService.ts): `client/src/services/auditService.ts`

### Other components

- **User**

## Connections

- User → Client API: uses
- Client API → API router: requests API
- API router → Authentication: routes auth (evidence: `server/src/app.ts`)
- Authentication → User records: reads and writes (evidence: `server/src/services/auth.service.ts`)
- API router → Product catalog: routes products (evidence: `server/src/app.ts`)
- Product catalog → Products: accesses (evidence: `server/src/controllers/product.controller.ts`)
- API router → Warehouse management: routes warehouses (evidence: `server/src/app.ts`)
- Warehouse management → Warehouses: manages
- API router → Inventory management: routes inventory (evidence: `server/src/app.ts`)
- Inventory client → Client API: calls (evidence: `client/src/services/inventoryService.ts`)
- Inventory management → Inventory records: reads and writes (evidence: `server/src/controllers/inventory.controller.ts`)
- Inventory management → Products: checks product (evidence: `server/src/controllers/inventory.controller.ts`)
- Inventory management → Warehouses: checks warehouse (evidence: `server/src/controllers/inventory.controller.ts`)
- Inventory management → Audit logging: records activity (evidence: `server/src/controllers/inventory.controller.ts`)
- API router → Legacy shipments: routes shipments (evidence: `server/src/app.ts`)
- Legacy shipments → Shipment operations: delegates (evidence: `server/src/controllers/shipment.controller.ts`)
- Shipment operations → Shipment snapshots: updates snapshot (evidence: `server/src/services/shipment.service.ts`)
- Shipment operations → Inventory records: transfers stock (evidence: `server/src/services/shipment.service.ts`)
- Shipment operations → Audit logging: records activity (evidence: `server/src/services/shipment.service.ts`)
- API router → Shipment commands: routes commands (evidence: `server/src/app.ts`)
- Shipment commands → Command handling: dispatches (evidence: `server/src/controllers/shipment.command.controller.ts`)
- Command handling → Event store service: appends events
- API router → Shipment queries: routes queries (evidence: `server/src/app.ts`)
- Shipment queries → Event store service: loads and reconstructs (evidence: `server/src/controllers/shipment.query.controller.ts`)
- Event store service → Shipment event store: reads and writes (evidence: `server/src/services/event-sourcing/event-store.service.ts`)
- Event store service → State replay: replays events (evidence: `server/src/services/event-sourcing/event-store.service.ts`)
- Shipment operations → Event store service: appends and reads stream (evidence: `server/src/services/shipment.service.ts`)
- Audit logging → Business audit log: saves events (evidence: `server/src/services/event.service.ts`)
- Audit client → Client API: uses API
