# bidhanji/veterinary-dose-calculator architecture

> Architecture diagram of the GitHub repository bidhanji/veterinary-dose-calculator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bidhanji/veterinary-dose-calculator
- Repository: https://github.com/bidhanji/veterinary-dose-calculator

## Overview

##### Project type and purpose
- This is a monorepo hosting a full-stack veterinary drug dose calculator.
- It comprises:
- A NestJS backend (in `/backend`) exposing REST endpoints.
- A React frontend (in `/frontend`) built with Vite, consuming those endpoints.
- A shared design-system library (in `/components`, `hooks`, `lib`) used by the frontend.

##### File structure
- Top-level directories:
- `backend/` – NestJS API modules, controllers, services, DTOs, interfaces, and raw drug_data.csv.
- `frontend/` – React app with Vite, API wrappers, type definitions, and UI assets.
- `components/`, `hooks/`, `lib/` – Shared React UI components, custom hooks, and utility functions.
- Configuration files:
- `package.json`, `pnpm-lock.yaml` – monorepo root package config.
- `next.config.mjs`, `tsconfig*.json`, `tailwind.config.ts`, `postcss.config.mjs` – build, TS, and styling configs.

##### README for additional insights
- Tech stack: NestJS + CSV Parser + Class Validator + CORS for backend; React + Axios + Vite + Responsive CSS for frontend.
- API endpoints:
- `GET /drugs` – fetch list of drugs & species.
- `POST /dose/calculate` – calculate total dose and volume.
- Drug database is loaded at startup from `drug_data.csv`.

##### Components
a. Main components:
1) Monorepo Root
2) Backend Service (NestJS)
– Modules: AppModule, DoseModule
– Controllers: AppController (GET `/drugs`), DoseController (POST `/dose/calculate`)
– Services: AppService (drug list loader), DoseService (calculator)
– Data source: drug_data.csv (CSV Parser)
3) Frontend App (React + Vite)
– Pages: main form, results view
– Services: `api.ts` (Axios wrapper)
– Types: `dose.types.ts`
– UI: imports from shared `components/ui` and custom `hooks`
4) Shared Component Library (`components/`, `hooks/`, `lib/`)
– UI primitives (buttons, inputs, dialogs, etc.)
– Theme provider, utility hooks (`use-mobile`, `use-toast`)
5) External Dependencies
– npm registry (package install)
– Browser (user agent)

b. Relationships and interactions:
- The React frontend imports UI primitives and hooks from the shared component library.
- On user action, the frontend calls the NestJS backend via HTTP (Axios).
- The NestJS backend:
- Reads/parses `drug_data.csv` at startup.
- Serves GET `/drugs` for dropdown data.
- Accepts POST `/dose/calculate`, validates input (class-validator), applies business logic (DoseService), and returns JSON.
- Frontend displays results and errors appropriately.

c. Architectural patterns and design principles:
- Monorepo structure for co-located frontend, backend, and shared libs.
- NestJS’s modular pattern (Modules→Controllers→Providers).
- Separation of concerns: UI library vs. app vs. backend domain logic.
- DTOs and interfaces enforce input/output contracts.
- Single source of truth for drug data (CSV file loaded server-side).
- API layer clearly decoupled from UI.

d. Relevant technologies/frameworks:
- Backend: NestJS, TypeScript, CSV Parser, Class-Validator, CORS.
- Frontend: React, Vite, TypeScript, Axios, Tailwind CSS (via PostCSS), shared UI library.
- Monorepo tools: pnpm or npm workspaces, TS project references.

##### Elements
- Clear labels:
- “React Frontend (Vite)”
- “Shared UI Library & Hooks”
- “NestJS Backend”
- “Drug Data CSV”
- “Controllers”, “Services”, “DTOs/Interfaces”

## Diagram (Mermaid)

```mermaid
flowchart TD
    MR["Monorepo Root"]:::root
    click MR "https://github.com/bidhanji/veterinary-dose-calculator/tree/main//"

    subgraph "Backend Service (NestJS)"
        direction TB
        BE_Main["main.ts"]:::backend
        BE_AppModule["AppModule\n(app.module.ts)"]:::backend
        BE_AppController["AppController\n(GET /drugs)\n(app.controller.ts)"]:::backend
        BE_AppService["AppService\n(drug list loader)\n(app.service.ts)"]:::backend
        BE_DoseModule["DoseModule\n(dose.module.ts)"]:::backend
        BE_DoseController["DoseController\n(POST /dose/calculate)\n(dose.controller.ts)"]:::backend
        BE_DoseService["DoseService\n(calculation logic)\n(dose.service.ts)"]:::backend
        BE_CalculateDto["CalculateDoseDto\n(calculate-dose.dto.ts)"]:::backend
        BE_DoseInterface["DoseCalculationInterface\n(dose-calculation.interface.ts)"]:::backend
        BE_DrugInterface["DrugDataInterface\n(drug-data.interface.ts)"]:::backend
        CSV["Drug Data CSV\n(drug_data.csv)"]:::data
    end
    click BE_Main "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//backend/src/main.ts"
    click BE_AppModule "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//backend/src/app.module.ts"
    click BE_AppController "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//backend/src/app.controller.ts"
    click BE_AppService "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//backend/src/app.service.ts"
    click BE_DoseModule "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//backend/src/dose/dose.module.ts"
    click BE_DoseController "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//backend/src/dose/dose.controller.ts"
    click BE_DoseService "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//backend/src/dose/dose.service.ts"
    click BE_CalculateDto "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//backend/src/dose/dto/calculate-dose.dto.ts"
    click BE_DoseInterface "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//backend/src/dose/interfaces/dose-calculation.interface.ts"
    click BE_DrugInterface "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//backend/src/dose/interfaces/drug-data.interface.ts"
    click CSV "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//backend/src/data/drug_data.csv"

    subgraph "Frontend App (React + Vite)"
        direction TB
        FE_HTML["index.html"]:::frontend
        FE_MainTsx["main.tsx"]:::frontend
        FE_RootComp["App.tsx"]:::frontend
        FE_API["api.ts"]:::frontend
        FE_Types["dose.types.ts"]:::frontend
        FE_FormPage["MainForm & Results"]:::frontend
    end
    click FE_HTML "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//frontend/index.html"
    click FE_MainTsx "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//frontend/src/main.tsx"
    click FE_RootComp "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//frontend/src/App.tsx"
    click FE_API "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//frontend/src/services/api.ts"
    click FE_Types "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//frontend/src/types/dose.types.ts"

    subgraph "Shared UI Library & Hooks"
        direction TB
        LIB_Theme["ThemeProvider\n(theme-provider.tsx)"]:::lib
        LIB_UI["UI Primitives\n(/components/ui)"]:::lib
        LIB_UseMobile["use-mobile\n(use-mobile.tsx)"]:::lib
        LIB_UseToast["use-toast\n(use-toast.ts)"]:::lib
        LIB_Utils["utils\n(utils.ts)"]:::lib
    end
    click LIB_Theme "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//components/theme-provider.tsx"
    click LIB_UI "https://github.com/bidhanji/veterinary-dose-calculator/tree/main//components/ui"
    click LIB_UseMobile "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//hooks/use-mobile.tsx"
    click LIB_UseToast "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//hooks/use-toast.ts"
    click LIB_Utils "https://github.com/bidhanji/veterinary-dose-calculator/blob/main//lib/utils.ts"

    subgraph "External Dependencies"
        direction TB
        NPM["npm Registry"]:::external
        Browser["Browser"]:::external
    end

    %% Flows
    Browser --> FE_HTML
    FE_HTML --> FE_MainTsx
    FE_MainTsx --> FE_RootComp
    FE_RootComp --> LIB_UI
    FE_RootComp --> LIB_Theme
    FE_RootComp --> LIB_UseMobile
    FE_RootComp --> LIB_UseToast
    FE_RootComp --> LIB_Utils
    FE_RootComp --> FE_API
    FE_API --> FE_Types

    FE_RootComp -->|"1: GET /drugs"| BE_AppController
    FE_RootComp -->|"2: POST /dose/calculate"| BE_DoseController
    BE_AppController --> BE_AppService
    BE_AppService --> CSV
    BE_DoseController --> BE_DoseService
    BE_DoseService --> BE_CalculateDto
    BE_DoseService --> BE_DoseInterface
    BE_AppService --> BE_DrugInterface

    NPM --> MR
    classDef frontend fill:#D0E8FF,stroke:#333,stroke-width:1px
    classDef backend fill:#FFE4B5,stroke:#333,stroke-width:1px
    classDef data fill:#E8E8E8,stroke:#333,stroke-width:1px
    classDef lib fill:#E0FFE0,stroke:#333,stroke-width:1px
    classDef external fill:none,stroke:#666,stroke-dasharray: 5 5,stroke-width:1px
    classDef root fill:#F0F0F0,stroke:#333,stroke-width:1px
```
