Architecture Overview
Relevant source files
The following files were used as context for generating this wiki page:
- src/app/layout.tsx
- src/app/page.tsx
- package.json
- src/app/globals.css
- CONTRIBUTING.md
- README.md
- src/i18n/translations.ts
- src/calculators/PediatricDoseCalculator.tsx
- src/calculators/AntibioticProphylaxisCalculator.tsx
- src/calculators/InfusionTherapyCalculator.tsx
- src/calculators/BloodGasAnalysisCalculator.tsx
The Medical Calculators application is a web-based tool built using Next.js, TypeScript, and Tailwind CSS. It provides a suite of calculators for healthcare professionals. The architecture is designed as a client-rendered single-page application (SPA) where different calculator components are dynamically displayed based on user selection. This approach allows for a fast, responsive user experience within a modular and extensible structure.
The core of the application is centered around the page.tsx component, which acts as a controller to manage which calculator is active. The overall structure is defined by the Next.js App Router, with a root layout that provides a consistent shell, styling, and internationalization context for the entire application.
Technology Stack
The project utilizes a modern frontend technology stack focused on React and its ecosystem. The primary dependencies are defined in package.json.
| Technology | Version | Purpose |
|---|---|---|
| Next.js | 15.4.5 | React framework for web applications. |
| React | 19.1.0 | UI library for building components. |
| React DOM | 19.1.0 | React package for DOM rendering. |
| TypeScript | ^5 | Static typing for JavaScript. |
| Tailwind CSS | ^4 | Utility-first CSS framework. |
| ESLint | ^9 | Code linting and quality checks. |
Sources: package.json:10-24
Project Structure
The project follows a standard Next.js App Router structure, organizing files by feature and type within the src directory. This modular organization is documented in both the README.md and CONTRIBUTING.md files.
This diagram shows the main directories within the src folder and their relationships.
| Directory | Description |
|---|---|
src/app | Contains core application routing, the root layout (layout.tsx), and the main page component (page.tsx). |
src/calculators | Houses the individual React components for each medical calculator. |
src/components | Contains reusable UI components like Button, Card, NumberInput, and Select. |
src/i18n | Manages internationalization, including the language context and translation strings. |
src/types | Defines shared TypeScript interfaces and types for the application. |
src/data | Stores static data, such as the pediatric medications database. |
Sources: README.md:31-47, CONTRIBUTING.md:100-106, PROJECT_SUMMARY.md:88-99
Frontend Architecture
The application is built as a Single-Page Application (SPA) managed by the main page.tsx component. This component uses a React state variable to control which calculator is currently rendered on the screen.
Root Layout
The root layout, defined in src/app/layout.tsx, wraps the entire application. Its primary responsibilities are:
- Defining the main HTML structure (
<html>and<body>). - Applying global fonts (
GeistandGeist_Mono). - Importing global stylesheets (
globals.css). - Wrapping the application in the
LanguageProviderto enable internationalization.
Sources: src/app/layout.tsx:1-35
Main Page and State Management
The file src/app/page.tsx serves as the application's entry point and orchestrator. It uses a simple state management pattern with the useState hook to control the user interface.
- State: A state variable
activeCalculatorof typeCalculatorTypeis used to track which calculator is visible.// src/app/page.tsx:12 type CalculatorType = 'home' | 'electrolyte' | 'antibiotic' | 'pediatric' | 'bloodGas' | 'infusionTherapy'; // src/app/page.tsx:15 const [activeCalculator, setActiveCalculator] = useState<CalculatorType>('home'); - Navigation: A series of
<button>elements in the header updates this state, causing a different calculator component to render. - Conditional Rendering: The body of the page uses conditional rendering to display the selected calculator component.
The following diagram illustrates the rendering flow managed by page.tsx.
Sources: src/app/page.tsx:12-321
Component-Based Design
The application is highly modular, with each calculator implemented as a self-contained React component in the src/calculators/ directory. This design is explicitly encouraged in the CONTRIBUTING.md guide for adding new calculators.
Calculator Component Structure
Each calculator component follows a consistent pattern:
- State Management: Uses
useStateto manage user inputs and calculation results. - Input Handling: Contains functions to update the state as the user enters data.
- Calculation Logic: A primary
calculatefunction that performs the medical calculations based on the input state. - UI Rendering: Uses shared components from
src/components/(e.g.,Card,NumberInput,Button) to build the user interface. - Result Display: Conditionally renders the results after a successful calculation.
This standardized structure makes it easy to add new calculators without affecting existing ones.
Sources: CONTRIBUTING.md:10-58, src/calculators/PediatricDoseCalculator.tsx, src/calculators/AntibioticProphylaxisCalculator.tsx
Styling and Theming
The application uses Tailwind CSS for styling, with a custom dark theme defined through CSS variables in src/app/globals.css.
Theme Variables
The root element :root defines a set of CSS variables for colors, which are then used throughout the application. This allows for easy theme adjustments.
| Variable | Value | Description |
|---|---|---|
--background | #1a202c | Main background color. |
--foreground | #ffffff | Main text color. |
--card | #2d3748 | Card background color. |
--primary | #63b3ed | Primary accent color. |
--border | #4a5568 | Border color. |
--input | #2d3748 | Input background color. |
The file also includes responsive design considerations using @media queries for mobile devices.
Sources: src/app/globals.css:3-28, 80-120
Internationalization (i18n)
The application supports multiple languages (English, Russian, Ukrainian) through a custom i18n implementation.
- Language Context:
LanguageProviderinsrc/app/layout.tsxmakes the current language and translation function available to all components via theuseLanguagehook. - Translations: The
src/i18n/translations.tsfile contains a nested object with translation strings for each supported language. - Usage: Components use the
tfunction from theuseLanguagehook to retrieve the correct string for the active language.
// src/app/page.tsx:16
const { t } = useLanguage();
// Example usage
// src/app/page.tsx:39
<button>
{t.home}
</button>
Sources: src/app/layout.tsx:4, 29-31, src/app/page.tsx:16, 39, src/i18n/translations.ts:1-741
Summary
The architecture of the Medical Calculators project is a straightforward and effective implementation of a modern frontend application. It leverages the strengths of Next.js, TypeScript, and Tailwind CSS to create a scalable and maintainable codebase. The component-based design, combined with a simple state management system, allows for easy extension with new calculators. The centralized styling and internationalization systems ensure a consistent user experience across the entire application.