# lelecodedev/borrowly architecture

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

- Interactive diagram: https://gitdiagram.com/lelecodedev/borrowly
- Repository: https://github.com/lelecodedev/borrowly

## Overview

Borrowly manages item lending across borrower, officer, and admin roles. The main workflow is a borrower browsing inventory and requesting an item, an officer or admin reviewing the request, and the borrower returning the item while staff monitor return status. The frontend routes role-specific pages through authentication and API hooks; the Go backend is organized into handlers, services, repositories, and database access. README features also include catalog/user/category administration, dashboards, activity logs, and officer reports. Backend internals were not excerpted, so their links are shown only as unverified where needed.

Main entry points: [`frontend/src/App.tsx`](https://github.com/lelecodedev/borrowly/blob/main/frontend/src/App.tsx) (Role-based routes), [`backend/cmd/server/main.go`](https://github.com/lelecodedev/borrowly/blob/main/backend/cmd/server/main.go) (HTTP server), [`backend/internal/repository`](https://github.com/lelecodedev/borrowly/tree/main/backend/internal/repository) (Data repositories), [`backend/internal/handler`](https://github.com/lelecodedev/borrowly/tree/main/backend/internal/handler) (Handlers and services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_app["Role-based routes<br/>[App.tsx]"]
  node_guard["Role guard<br/>[AuthGuard.tsx]"]
  node_auth["Authentication state<br/>[useAuth.ts]"]
  node_borrow_ui["Borrow requests"]
  node_return_ui["Return views"]
  node_catalog_ui["Catalog and admin<br/>[AdminItemPage.tsx]"]
  node_dashboard_ui["Role dashboards<br/>[AdminDashboard.tsx]"]
  node_activity_ui["Activity log<br/>[AdminLogPage.tsx]"]
  node_borrow_hook["Borrow queries<br/>[useBorrow.ts]"]
  node_return_hook["Return queries<br/>[useReturn.ts]"]
  node_auth_api["Auth API client<br/>[authApi.ts]"]
  node_borrow_api["Borrow API client<br/>[borrowApi.ts]"]
  node_return_api["Return API client<br/>[returnApi.ts]"]
end

subgraph group_backend["Backend API"]
  node_server["HTTP server<br/>[main.go]"]
  node_http_layers["Handlers and services"]
  node_repositories["Data repositories"]
end

subgraph group_domain["Lending operations"]
  node_lending_services["Borrow and return rules"]
  node_catalog_services["Catalog and users"]
  node_reports["Officer reports"]
end

subgraph group_storage["Persistence"]
  node_mysql[("MySQL database<br/>[database.go]")]
end

node_user(("Borrower / staff"))

node_user -.->|"uses"| node_app
node_app -->|"protects routes"| node_guard
node_guard -->|"checks identity"| node_auth
node_auth -->|"calls"| node_auth_api
node_app -->|"routes to"| node_borrow_ui
node_app -->|"routes to"| node_return_ui
node_app -->|"routes to"| node_catalog_ui
node_app -->|"routes to"| node_dashboard_ui
node_app -->|"routes to"| node_activity_ui
node_borrow_ui -->|"queries"| node_borrow_hook
node_return_ui -->|"queries"| node_return_hook
node_borrow_hook -->|"calls"| node_borrow_api
node_return_hook -->|"calls"| node_return_api
node_auth_api -.->|"HTTP requests"| node_server
node_borrow_api -.->|"HTTP requests"| node_server
node_return_api -.->|"HTTP requests"| node_server
node_server -.->|"dispatches"| node_http_layers
node_http_layers -.->|"delegates"| node_lending_services
node_http_layers -.->|"delegates"| node_catalog_services
node_lending_services -.->|"uses"| node_repositories
node_catalog_services -.->|"uses"| node_repositories
node_reports -.->|"reads data"| node_repositories
node_repositories -.->|"persists data"| node_mysql

click node_app "https://github.com/lelecodedev/borrowly/blob/main/frontend/src/App.tsx"
click node_guard "https://github.com/lelecodedev/borrowly/blob/main/frontend/src/guards/AuthGuard.tsx"
click node_auth "https://github.com/lelecodedev/borrowly/blob/main/frontend/src/hooks/api/useAuth.ts"
click node_borrow_ui "https://github.com/lelecodedev/borrowly/blob/main/frontend/src/pages/admin/AdminBorrowRequestPage.tsx"
click node_return_ui "https://github.com/lelecodedev/borrowly/blob/main/frontend/src/pages/admin/AdminReturnPage.tsx"
click node_catalog_ui "https://github.com/lelecodedev/borrowly/blob/main/frontend/src/pages/admin/AdminItemPage.tsx"
click node_dashboard_ui "https://github.com/lelecodedev/borrowly/blob/main/frontend/src/pages/admin/AdminDashboard.tsx"
click node_activity_ui "https://github.com/lelecodedev/borrowly/blob/main/frontend/src/pages/admin/AdminLogPage.tsx"
click node_borrow_hook "https://github.com/lelecodedev/borrowly/blob/main/frontend/src/hooks/api/useBorrow.ts"
click node_return_hook "https://github.com/lelecodedev/borrowly/blob/main/frontend/src/hooks/api/useReturn.ts"
click node_auth_api "https://github.com/lelecodedev/borrowly/blob/main/frontend/src/api/authApi.ts"
click node_borrow_api "https://github.com/lelecodedev/borrowly/blob/main/frontend/src/api/borrowApi.ts"
click node_return_api "https://github.com/lelecodedev/borrowly/blob/main/frontend/src/api/returnApi.ts"
click node_server "https://github.com/lelecodedev/borrowly/blob/main/backend/cmd/server/main.go"
click node_http_layers "https://github.com/lelecodedev/borrowly/tree/main/backend/internal/handler"
click node_lending_services "https://github.com/lelecodedev/borrowly/tree/main/backend/internal/service"
click node_catalog_services "https://github.com/lelecodedev/borrowly/tree/main/backend/internal/service"
click node_repositories "https://github.com/lelecodedev/borrowly/tree/main/backend/internal/repository"
click node_mysql "https://github.com/lelecodedev/borrowly/blob/main/backend/internal/database/database.go"
click node_reports "https://github.com/lelecodedev/borrowly/tree/main/backend/internal/service"

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_app,node_guard,node_auth,node_borrow_ui,node_return_ui,node_catalog_ui,node_dashboard_ui,node_activity_ui,node_borrow_hook,node_return_hook,node_auth_api,node_borrow_api,node_return_api toneBlue
class node_server,node_http_layers,node_repositories toneAmber
class node_lending_services,node_catalog_services,node_reports toneMint
class node_mysql toneRose
class node_user toneIndigo
```

## Components

### Web application

- [Role-based routes](https://github.com/lelecodedev/borrowly/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Role guard](https://github.com/lelecodedev/borrowly/blob/main/frontend/src/guards/AuthGuard.tsx): `frontend/src/guards/AuthGuard.tsx`
- [Authentication state](https://github.com/lelecodedev/borrowly/blob/main/frontend/src/hooks/api/useAuth.ts): `frontend/src/hooks/api/useAuth.ts`
- [Borrow requests](https://github.com/lelecodedev/borrowly/blob/main/frontend/src/pages/admin/AdminBorrowRequestPage.tsx): `frontend/src/pages/admin/AdminBorrowRequestPage.tsx`
- [Return views](https://github.com/lelecodedev/borrowly/blob/main/frontend/src/pages/admin/AdminReturnPage.tsx): `frontend/src/pages/admin/AdminReturnPage.tsx`
- [Catalog and admin](https://github.com/lelecodedev/borrowly/blob/main/frontend/src/pages/admin/AdminItemPage.tsx): `frontend/src/pages/admin/AdminItemPage.tsx`
- [Role dashboards](https://github.com/lelecodedev/borrowly/blob/main/frontend/src/pages/admin/AdminDashboard.tsx): `frontend/src/pages/admin/AdminDashboard.tsx`
- [Activity log](https://github.com/lelecodedev/borrowly/blob/main/frontend/src/pages/admin/AdminLogPage.tsx): `frontend/src/pages/admin/AdminLogPage.tsx`
- [Borrow queries](https://github.com/lelecodedev/borrowly/blob/main/frontend/src/hooks/api/useBorrow.ts): `frontend/src/hooks/api/useBorrow.ts`
- [Return queries](https://github.com/lelecodedev/borrowly/blob/main/frontend/src/hooks/api/useReturn.ts): `frontend/src/hooks/api/useReturn.ts`
- [Auth API client](https://github.com/lelecodedev/borrowly/blob/main/frontend/src/api/authApi.ts): `frontend/src/api/authApi.ts`
- [Borrow API client](https://github.com/lelecodedev/borrowly/blob/main/frontend/src/api/borrowApi.ts): `frontend/src/api/borrowApi.ts`
- [Return API client](https://github.com/lelecodedev/borrowly/blob/main/frontend/src/api/returnApi.ts): `frontend/src/api/returnApi.ts`

### Backend API

- [HTTP server](https://github.com/lelecodedev/borrowly/blob/main/backend/cmd/server/main.go): `backend/cmd/server/main.go`
- [Handlers and services](https://github.com/lelecodedev/borrowly/tree/main/backend/internal/handler): `backend/internal/handler`
- [Data repositories](https://github.com/lelecodedev/borrowly/tree/main/backend/internal/repository): `backend/internal/repository`

### Lending operations

- [Borrow and return rules](https://github.com/lelecodedev/borrowly/tree/main/backend/internal/service): `backend/internal/service`
- [Catalog and users](https://github.com/lelecodedev/borrowly/tree/main/backend/internal/service): `backend/internal/service`
- [Officer reports](https://github.com/lelecodedev/borrowly/tree/main/backend/internal/service): `backend/internal/service`

### Persistence

- [MySQL database](https://github.com/lelecodedev/borrowly/blob/main/backend/internal/database/database.go): `backend/internal/database/database.go`

### Other components

- **Borrower / staff**

## Connections

- Borrower / staff → Role-based routes: uses (evidence: `README.md`)
- Role-based routes → Role guard: protects routes (evidence: `frontend/src/App.tsx`)
- Role guard → Authentication state: checks identity (evidence: `frontend/src/guards/AuthGuard.tsx`)
- Authentication state → Auth API client: calls (evidence: `frontend/src/hooks/api/useAuth.ts`)
- Role-based routes → Borrow requests: routes to (evidence: `frontend/src/App.tsx`)
- Role-based routes → Return views: routes to (evidence: `frontend/src/App.tsx`)
- Role-based routes → Catalog and admin: routes to (evidence: `frontend/src/App.tsx`)
- Role-based routes → Role dashboards: routes to (evidence: `frontend/src/App.tsx`)
- Role-based routes → Activity log: routes to (evidence: `frontend/src/App.tsx`)
- Borrow requests → Borrow queries: queries (evidence: `frontend/src/pages/admin/AdminBorrowRequestPage.tsx`)
- Return views → Return queries: queries (evidence: `frontend/src/pages/admin/AdminReturnPage.tsx`)
- Borrow queries → Borrow API client: calls (evidence: `frontend/src/hooks/api/useBorrow.ts`)
- Return queries → Return API client: calls (evidence: `frontend/src/hooks/api/useReturn.ts`)
- Auth API client → HTTP server: HTTP requests
- Borrow API client → HTTP server: HTTP requests
- Return API client → HTTP server: HTTP requests
- HTTP server → Handlers and services: dispatches
- Handlers and services → Borrow and return rules: delegates
- Handlers and services → Catalog and users: delegates
- Borrow and return rules → Data repositories: uses
- Catalog and users → Data repositories: uses
- Officer reports → Data repositories: reads data
- Data repositories → MySQL database: persists data
