Project File Structure
Relevant source files
The following files were used as context for generating this wiki page:
The medical-calculators project is built using Next.js 14 with the App Router, TypeScript, and Tailwind CSS. Its file structure is organized to separate concerns, making it scalable and maintainable. The core logic is centered around individual calculator components, supported by shared UI components, type definitions, and internationalization services.
This structure facilitates the addition of new calculators by providing a clear pattern for creating new components, defining their types, and integrating them into the main application.
Sources: README.md, CONTRIBUTING.md, PROJECT_SUMMARY.md
High-Level Directory Overview
The project's source code is primarily located within the src/ directory. The following diagram illustrates the main directories and their relationships.
This diagram shows the top-level project structure, highlighting the key directories within the src folder.
Sources: README.md:29-43, CONTRIBUTING.md:105-111, PROJECT_SUMMARY.md:95-106
Core Directories
The following table provides a summary of the main directories within the src/ folder and their responsibilities.
| Directory | Description | Source Files |
|---|---|---|
app/ | Contains the Next.js App Router files, including the root layout, main page, and global styles. | README.md:30 |
calculators/ | Houses the core logic and UI for each individual medical calculator component. | README.md:39 |
components/ | Stores reusable React components like Card, Button, and NumberInput used across different calculators. | README.md:35 |
types/ | Defines shared TypeScript interfaces and types for calculator inputs and results. | README.md:42 |
i18n/ | Manages internationalization, including translation strings for different languages. | PROJECT_SUMMARY.md:103, src/i18n/translations.ts |
data/ | Contains static data sources, such as the database of pediatric medications. | PROJECT_SUMMARY.md:105, src/calculators/PediatricDoseCalculator.tsx:8 |
utils/ | A designated folder for utility functions, though its usage is optional. | CONTRIBUTING.md:110 |
src/app
This directory is the entry point for the Next.js application.
layout.tsx: The root layout component that wraps all pages. It sets up the HTML structure, applies global fonts (Geist,Geist_Mono), and includes theLanguageProviderfor internationalization.page.tsx: The main page of the application, responsible for rendering the navigation between different calculators and displaying the active calculator component.globals.css: Contains global styles and Tailwind CSS custom variables for the application's dark theme.
Sources: README.md:31-34, src/app/layout.tsx, CONTRIBUTING.md:57-64
src/calculators
This is the most critical directory, containing the business logic for each calculator. Each file is a self-contained React component that manages its own state for inputs and results.
- Example Calculators:
BloodGasAnalysisCalculator.tsx,InfusionTherapyCalculator.tsx,PediatricDoseCalculator.tsx. - Structure: Each calculator component typically includes:
- State management for user inputs (
useState). - Calculation logic encapsulated in functions.
- UI elements for input fields and result display, built using shared components from
src/components.
- State management for user inputs (
Sources: README.md:39-41, src/calculators/BloodGasAnalysisCalculator.tsx, src/calculators/InfusionTherapyCalculator.tsx, src/calculators/PediatricDoseCalculator.tsx
src/components
This directory promotes code reuse by providing a library of common UI elements.
- Available Components:
Card,Button,Checkbox,NumberInput,Select. - Purpose: To ensure a consistent look and feel across the application and to simplify the development of new calculators.
Sources: README.md:35-38, CONTRIBUTING.md:71-77
src/i18n
This directory handles the multi-language support for the application.
translations.ts: Exports atranslationsobject containing key-value pairs for different languages (e.g., 'en', 'ru', 'uk'). It also defines theTranslationsinterface for type safety.LanguageContext.tsx: Provides the language context to the application, allowing components to access the correct translation strings via theuseLanguagehook.
Sources: src/i18n/translations.ts, src/app/layout.tsx:4,24-26
Adding a New Calculator
The project structure is designed to make adding new features straightforward. The process for adding a new calculator is documented in CONTRIBUTING.md and follows a clear pattern.
The following flowchart illustrates the development workflow for adding a new calculator.
This workflow ensures that new features are modular and consistently integrated into the existing architecture.
Sources: CONTRIBUTING.md:3-55
Configuration and Dependencies
The root package.json file defines the project's metadata, scripts, and dependencies.
- Scripts:
dev: Starts the development server with Turbopack.build: Creates a production build of the application.start: Runs the production server.lint: Lints the codebase using ESLint.
- Dependencies:
next: The core Next.js framework.react,react-dom: The React library for building the UI.
- Dev Dependencies:
typescript: For static typing.tailwindcss: For utility-first CSS styling.eslint: For code linting.
Sources: package.json, DEPLOYMENT.md:12-24
Conclusion
The file structure of medical-calculators is logical and leverages the conventions of the Next.js framework. By separating application pages (app), core logic (calculators), reusable UI (components), data types (types), and static assets (data), the project remains organized and easy to extend. This modular design is crucial for maintaining code quality and simplifying the process for contributors to add new medical calculators.
Sources: README.md:29-43, CONTRIBUTING.md:105-111