# nirant-nk/smart-growth-tracker architecture

> Architecture diagram of the GitHub repository nirant-nk/smart-growth-tracker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nirant-nk/smart-growth-tracker
- Repository: https://github.com/nirant-nk/smart-growth-tracker

## Overview

##### Project type and purpose
- This is a two-fold project:
- A backend RESTful API implemented in Node.js/Express (under the “api” folder)
- A placeholder for a frontend/UI (under the “ui” folder)
- Its domain: tracking child growth metrics (z-scores, growth standards) and providing recommendations via CRUD endpoints (users, children, growth records, alerts, recommendations).

##### File structure
- Top-level:
- api/ — contains a typical MVC-style Express service
- ui/ — an empty folder for the eventual front end
- Inside api/:
- package.json & package-lock.json — dependencies and scripts
- public/ — static assets (currently empty)
- src/
– assets/growthStandards.js — domain data source for WHO growth charts
– constants.js — app-wide constants
– controllers/ — route handlers (child, growth, recommendation, user)
– database/connect.js — DB connection logic
– index.js — server entrypoint
– middlewares/ — auth, error handling
– models/ — Mongoose (or similar) schemas for alerts, children, growth, recommendations, users
– routes/ — Express route definitions linking paths to controllers
– utils/ — validators, z-score calculator
- No external services beyond a database (likely MongoDB).

a. Main components
- Frontend (UI) – a web or mobile client
- API Server – Node.js + Express application
- Database – MongoDB (or similar document store)
- Static Data Module – growthStandards.js loaded by the API
- External Auth (optional) – JWT verification in authMiddleware
b. Relationships and data flow
- Frontend sends HTTP(S) requests (REST calls) → API Server
- API Server:
– routes → controller → business logic (utils, assets) → models
– controllers read/write → Database
– middlewares handle auth & errors on both inbound and outbound
- Database returns data → API Server → Frontend
c. Architectural patterns and principles
- MVC/Layered architecture
- Separation of concerns:
– Routes define API surface
– Controllers handle orchestration
– Models handle persistence
– Utils and assets are pure functions/data modules
– Middlewares handle cross-cutting concerns (auth, error handling)
- RESTful design for endpoints
d. Key technologies
- Node.js & Express
- Mongoose (implied) or another MongoDB client
- JWT or similar token-based auth
- WHO growth standard data (in assets module)
- Validation logic (validators.js)

##### Detail
- Module (authMiddleware, errorHandler, validators) as separate components
- Interactions with the static asset module for z-score computation
- Five resource domains (user, child, growth, recommendation, alert) either as sub-modules in the controller layer or individual route clusters

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        Browser["Web/Mobile Client"]:::presentation
    end
    click Browser "https://github.com/nirant-nk/smart-growth-tracker/tree/main/ui/"

    %% API Entry Point
    API["API Server\n(index.js)"]:::api
    click API "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/index.js"

    Browser -->|"HTTP JSON"| API

    %% API Middleware Layer
    AuthMiddleware["Authentication Middleware"]:::middleware
    click AuthMiddleware "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/middlewares/authMiddleware.js"
    ErrorMiddleware["Error Handling Middleware"]:::middleware
    click ErrorMiddleware "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/middlewares/errorHandler.js"

    API --> AuthMiddleware
    API --> ErrorMiddleware

    %% Public Static Assets
    Public["Static Assets"]:::asset
    click Public "https://github.com/nirant-nk/smart-growth-tracker/tree/main/api/public/"

    API --> Public

    %% Configuration & Connection
    Constants["Application Constants"]:::config
    click Constants "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/constants.js"
    DBConn["Database Connection"]:::config
    click DBConn "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/database/connect.js"

    %% Package Management
    Pkg["package.json"]:::config
    click Pkg "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/package.json"
    PkgLock["package-lock.json"]:::config
    click PkgLock "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/package-lock.json"

    %% Routes Layer
    subgraph "Routes Layer"
        ChildRoute["Child Routes"]:::route
        click ChildRoute "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/routes/child.route.js"
        GrowthRoute["Growth Routes"]:::route
        click GrowthRoute "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/routes/growth.route.js"
        RecommendationRoute["Recommendation Routes"]:::route
        click RecommendationRoute "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/routes/recommendation.route.js"
        UserRoute["User Routes"]:::route
        click UserRoute "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/routes/user.route.js"
    end

    AuthMiddleware --> ChildRoute
    AuthMiddleware --> GrowthRoute
    AuthMiddleware --> RecommendationRoute
    AuthMiddleware --> UserRoute

    ErrorMiddleware --> ChildRoute
    ErrorMiddleware --> GrowthRoute
    ErrorMiddleware --> RecommendationRoute
    ErrorMiddleware --> UserRoute

    %% Controllers Layer
    subgraph "Controllers Layer"
        ChildCtrl["Child Controller"]:::controller
        click ChildCtrl "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/controllers/child.controller.js"
        GrowthCtrl["Growth Controller"]:::controller
        click GrowthCtrl "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/controllers/growth.controller.js"
        RecCtrl["Recommendation Controller"]:::controller
        click RecCtrl "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/controllers/recommendation.controller.js"
        UserCtrl["User Controller"]:::controller
        click UserCtrl "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/controllers/user.controller.js"
    end

    ChildRoute --> ChildCtrl
    GrowthRoute --> GrowthCtrl
    RecommendationRoute --> RecCtrl
    UserRoute --> UserCtrl

    %% Business Logic Modules
    GrowthStandards["growthStandards.js"]:::asset
    click GrowthStandards "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/assets/growthStandards.js"
    ZScoreCalc["Z-Score Calculator"]:::util
    click ZScoreCalc "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/utils/zscoreCalculator.js"
    Validators["Data Validators"]:::util
    click Validators "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/utils/validators.js"

    ChildCtrl --> Validators
    ChildCtrl --> GrowthStandards
    ChildCtrl --> ZScoreCalc
    GrowthCtrl --> ZScoreCalc
    RecCtrl --> ZScoreCalc

    %% Models Layer
    subgraph "Models Layer"
        AlertModel["Alert Model"]:::model
        click AlertModel "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/models/alert.model.js"
        ChildModel["Child Model"]:::model
        click ChildModel "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/models/child.model.js"
        GrowthModel["Growth Model"]:::model
        click GrowthModel "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/models/growth.model.js"
        RecModel["Recommendation Model"]:::model
        click RecModel "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/models/recommendation.model.js"
        UserModel["User Model"]:::model
        click UserModel "https://github.com/nirant-nk/smart-growth-tracker/blob/main/api/src/models/user.model.js"
    end

    ChildCtrl --> ChildModel
    GrowthCtrl --> GrowthModel
    RecCtrl --> RecModel
    UserCtrl --> UserModel
    ChildCtrl --> AlertModel

    %% Persistence Layer
    ChildModel --> DBConn
    GrowthModel --> DBConn
    RecModel --> DBConn
    UserModel --> DBConn
    AlertModel --> DBConn
    DBConn --> Database

    %% Database
    Database["MongoDB"]:::db

    %% Constants usage
    ChildCtrl --> Constants
    GrowthCtrl --> Constants
    RecCtrl --> Constants
    UserCtrl --> Constants

    %% Classes for styling
    classDef presentation fill:#f9f,stroke:#333,stroke-width:2px
    classDef api fill:#bbf,stroke:#333,stroke-width:2px
    classDef middleware fill:#f96,stroke:#333,stroke-width:2px
    classDef route fill:#9cf,stroke:#333,stroke-width:2px
    classDef controller fill:#fc9,stroke:#333,stroke-width:2px
    classDef util fill:#acf,stroke:#333,stroke-width:2px
    classDef asset fill:#cfa,stroke:#333,stroke-width:2px
    classDef model fill:#faa,stroke:#333,stroke-width:2px
    classDef config fill:#eee,stroke:#333,stroke-width:2px
    classDef db fill:#afa,stroke:#333,stroke-width:2px
```
