# techops-recsys-lateral-hiring/developer-joi-delivery-golang architecture

> Architecture diagram of the GitHub repository techops-recsys-lateral-hiring/developer-joi-delivery-golang, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-03-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang
- Repository: https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang

## Overview

##### What this project is (type + purpose)

From the file tree + README, this is a **Go backend HTTP API** for a delivery domain (“JOI Delivery”) with initial capabilities around:

- **Cart**: add product to cart, view cart
- **Inventory**: health endpoint stub (to be implemented)
- Domain entities: users, outlets (stores/restaurants), products (grocery/food), carts

There is **no obvious database adapter/repository layer** in the tree; instead there’s `internal/service/test_data.go` suggesting **seeded/in-memory data** for development/testing. So architecturally, it’s a **layered monolith** (single service) with packages separated by concern.

##### Entrypoints / runtime
- `cmd/app/main.go` — likely the executable entrypoint (starts server)
- `cmd/server/server.go` (+ `server_test.go`) — server creation/configuration
- `cmd/api/routes.go` — route registration
- `cmd/api/handler/*` — HTTP handlers (cart, inventory, common handler wiring)

##### Core application / domain
- `internal/service/*` — business logic/services
- `cart_service.go` (+ tests)
- `product_service.go`
- `user_service.go`
- `test_data.go` (seed data / in-memory store)
- `internal/models/*` — domain models/entities
- cart, user, product hierarchy, outlets (grocery_store/restaurant/etc.)
- `internal/dto/request/*` and `internal/dto/response/*` — API contracts

##### Project/build artifacts
- `Makefile` — build/test/run entry points

This maps cleanly to a **typical HTTP layering**:

**Client → Router → Handler → Service → (in-memory data / models) → Response DTO**

##### Routing
- `cmd/api/routes.go`
##### Handlers (HTTP layer)
- `cmd/api/handler/cart_handler.go`
- `cmd/api/handler/inventory_handler.go`
- `cmd/api/handler/handler.go` (shared wiring/structs)
##### DTOs (API contracts)
- Requests: `internal/dto/request/add_to_cart.go`
- Responses: `internal/dto/response/cart.go`
##### Services (business logic)
- `internal/service/cart_service.go`
- `internal/service/product_service.go`
- `internal/service/user_service.go`
##### Domain Models
- `internal/models/cart.go`, `user.go`
- `product.go`, `grocery_product.go`, `food_product.go`
- `outlet.go`, `grocery_store.go`, `restaurant.go`
##### Data Source (current implementation)
- `internal/service/test_data.go` (seed/in-memory)
- Make it a distinct component to avoid implying persistence exists.
##### Server bootstrap
- `cmd/app/main.go` → `cmd/server/server.go` → registers routes/handlers

##### CartHandler
- parses JSON into `AddToCartRequest` (`internal/dto/request/add_to_cart.go`)
- calls **CartService.AddProduct(...)** (method name inferred; use “Cart Service” if unsure)
##### CartService
- queries **UserService** (validate/find user) and **ProductService** (validate/find product + outlet/store relationship)
- updates **Cart** model (add product)
- reads/writes to **Seed Data / In-Memory Store** (`test_data.go`) if that’s how it’s done
4. Service returns domain objects → Handler maps to **response DTO** (`internal/dto/response/cart.go`)

##### Flow 3: Inventory Health (`GET /inventory/health`)
It routed to `inventory_handler.go`, and annotate as:
- “Not implemented” / “stub” (based on README response body comment)

- **Layered architecture**: HTTP (handlers/routes) → services → domain models/data
- **DTO boundary**: `internal/dto` indicates API contracts separated from domain models
- **Domain modeling**: product/outlet polymorphism via separate model files (food vs grocery, store vs restaurant)
- **Single deployable**: all code runs in one Go server process
- **Testability**: service and server tests exist (`*_test.go`)—indicates separable components and dependency boundaries

##### (Optional) Sequence: Add-to-cart and View-cart request lifecycle

This combination will be the most accurate reflection of what exists in the repository today, while still being detailed enough for principal-level review.

## Diagram (Mermaid)

```mermaid
flowchart TD

%% =========================
%% Level 1 — System Context
%% =========================
subgraph "System Context (L1)"
direction TB
Client["Client App\n(Web/Mobile/CLI)"]:::external
API["JOI Delivery API\n(Go HTTP JSON)"]:::system
Client -->|"HTTP/JSON"| API
end

%% =========================
%% Level 2 — Container
%% =========================
subgraph "Container (L2)"
direction TB
GoServer["Go HTTP Server\n(listens on :8080)"]:::container
InMem[("In-memory Seed Data\n(not persistent; no DB in repo)")]:::datastore
GoServer -->|"reads/writes"| InMem
end

API -->|"runs as"| GoServer

%% =========================
%% Level 3 — Components (Monolith)
%% =========================
subgraph "Component View (L3) — Layered Monolith"
direction TB

%% --- Bootstrap & Server ---
subgraph "Bootstrap & Server"
direction TB
Main["Entrypoint\ncmd/app/main.go"]:::bootstrap
Server["Server Setup/Config\ncmd/server/server.go"]:::bootstrap
ServerTests["Server Tests\ncmd/server/server_test.go"]:::test

Main -->|"creates"| Server
Server -.->|"tested by"| ServerTests
end

%% --- Routing ---
subgraph "Routing"
direction TB
Routes["Route Registration / Router\ncmd/api/routes.go"]:::http
end

%% --- HTTP Handlers ---
subgraph "HTTP Layer (Handlers)"
direction TB
HandlerWiring["Shared Handler Wiring\ncmd/api/handler/handler.go"]:::http
CartHandler["Cart Handler\ncmd/api/handler/cart_handler.go"]:::http
InventoryHandler["Inventory Handler\ncmd/api/handler/inventory_handler.go"]:::http

HandlerWiring -->|"wires"| CartHandler
HandlerWiring -->|"wires"| InventoryHandler
end

%% --- DTOs ---
subgraph "DTO Boundary (API Contracts)"
direction TB
AddToCartReq["Request DTO\nAddToCart\ninternal/dto/request/add_to_cart.go"]:::dto
CartRespDTO["Response DTO\nCart\ninternal/dto/response/cart.go"]:::dto
end

%% --- Services ---
subgraph "Business Logic (Services)"
direction TB
CartService["Cart Service\ninternal/service/cart_service.go"]:::service
CartServiceTests["Cart Service Tests\ninternal/service/cart_service_test.go"]:::test
ProductService["Product Service\ninternal/service/product_service.go"]:::service
UserService["User Service\ninternal/service/user_service.go"]:::service
SeedData["Seed Data / In-Memory Store\ninternal/service/test_data.go"]:::datastore

CartService -.->|"tested by"| CartServiceTests
CartService -->|"reads/writes"| SeedData
ProductService -->|"reads"| SeedData
UserService -->|"reads"| SeedData
end

%% --- Domain Models ---
subgraph "Domain Models"
direction TB
CartModel["Cart\ninternal/models/cart.go"]:::domain
UserModel["User\ninternal/models/user.go"]:::domain

subgraph "Product Hierarchy"
direction TB
ProductBase["Product (base)\ninternal/models/product.go"]:::domain
GroceryProduct["Grocery Product\ninternal/models/grocery_product.go"]:::domain
FoodProduct["Food Product\ninternal/models/food_product.go"]:::domain
ProductBase -->|"specializes"| GroceryProduct
ProductBase -->|"specializes"| FoodProduct
end

subgraph "Outlet Hierarchy"
direction TB
OutletBase["Outlet (base)\ninternal/models/outlet.go"]:::domain
GroceryStore["Grocery Store\ninternal/models/grocery_store.go"]:::domain
Restaurant["Restaurant\ninternal/models/restaurant.go"]:::domain
OutletBase -->|"specializes"| GroceryStore
OutletBase -->|"specializes"| Restaurant
end
end

%% --- Docs & Dev Artifacts ---
subgraph "Build / Docs / Examples"
direction TB
MakefileNode["Build/Run Automation\nMakefile"]:::ops
APIRequests["Example API Requests\napi_requests.http"]:::ops
Readme["Documentation\nREADME.md"]:::ops
end

end

%% =========================
%% Connections across L3
%% =========================
Server -->|"registers"| Routes
Routes -->|"routes to"| HandlerWiring

%% Endpoints (explicit)
Routes -->|"POST /cart/product"| CartHandler
Routes -->|"GET /cart/view?userId=..."| CartHandler
Routes -->|"GET /inventory/health?storeid=..."| InventoryHandler

%% Flow 1: Add Product to Cart
CartHandler -->|"parses JSON to DTO"| AddToCartReq
CartHandler -->|"calls"| CartService
CartService -->|"validates user via"| UserService
CartService -->|"validates product via"| ProductService
CartService -->|"updates"| CartModel
CartService -->|"uses"| UserModel
CartService -->|"uses"| ProductBase
ProductService -->|"uses"| ProductBase
UserService -->|"uses"| UserModel

CartHandler -->|"maps to response DTO"| CartRespDTO
CartRespDTO -.->|"represents"| CartModel

%% Flow 2: View Cart
CartHandler -->|"fetches by userId"| CartService

%% Flow 3: Inventory Health (stub)
InventoryHandler -->|"returns stub / not implemented"| InventoryStubNote["Inventory Health\n(stubbed behavior)"]:::note

%% Tie container data store to component store
SeedData -.->|"implements"| InMem

%% Helpful references
APIRequests -.->|"documents flows"| Routes
Readme -.->|"describes"| API
MakefileNode -.->|"build/test/run"| Main

%% =========================
%% Click Events (mapped paths)
%% =========================
click Main "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/cmd/app/main.go"
click Server "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/cmd/server/server.go"
click ServerTests "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/cmd/server/server_test.go"
click Routes "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/cmd/api/routes.go"
click HandlerWiring "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/cmd/api/handler/handler.go"
click CartHandler "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/cmd/api/handler/cart_handler.go"
click InventoryHandler "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/cmd/api/handler/inventory_handler.go"
click CartService "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/internal/service/cart_service.go"
click CartServiceTests "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/internal/service/cart_service_test.go"
click ProductService "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/internal/service/product_service.go"
click UserService "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/internal/service/user_service.go"
click SeedData "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/internal/service/test_data.go"
click AddToCartReq "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/internal/dto/request/add_to_cart.go"
click CartRespDTO "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/internal/dto/response/cart.go"
click CartModel "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/internal/models/cart.go"
click UserModel "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/internal/models/user.go"
click ProductBase "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/internal/models/product.go"
click GroceryProduct "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/internal/models/grocery_product.go"
click FoodProduct "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/internal/models/food_product.go"
click OutletBase "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/internal/models/outlet.go"
click GroceryStore "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/internal/models/grocery_store.go"
click Restaurant "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/internal/models/restaurant.go"
click MakefileNode "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/tree/main/Makefile"
click APIRequests "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/api_requests.http"
click Readme "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-golang/blob/main/README.md"

%% =========================
%% Styles
%% =========================
classDef external fill:#F2F6FF,stroke:#2B59C3,stroke-width:2px,color:#0B1F52
classDef system fill:#E8F0FE,stroke:#1A73E8,stroke-width:2px,color:#0B1F52
classDef container fill:#D7F3FF,stroke:#0284C7,stroke-width:2px,color:#073B4C

classDef http fill:#DCEBFF,stroke:#2563EB,stroke-width:2px,color:#0B1F52
classDef service fill:#D9FBE7,stroke:#16A34A,stroke-width:2px,color:#052E16
classDef dto fill:#FFF4CC,stroke:#F59E0B,stroke-width:2px,color:#4A2C00
classDef domain fill:#FFE6D5,stroke:#F97316,stroke-width:2px,color:#4A1D00
classDef datastore fill:#E5E7EB,stroke:#374151,stroke-width:2px,color:#111827
classDef ops fill:#F3E8FF,stroke:#7C3AED,stroke-width:2px,color:#2E1065
classDef test fill:#FFE4E6,stroke:#E11D48,stroke-width:2px,color:#4C0519
classDef note fill:#FFF7ED,stroke:#FB923C,stroke-width:1px,color:#7C2D12,stroke-dasharray: 4 3
```
