How bidhanji/veterinary-dose-calculator works
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”