# jakecooke98/calf-care architecture

> Architecture diagram of the GitHub repository jakecooke98/calf-care, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jakecooke98/calf-care
- Repository: https://github.com/jakecooke98/calf-care

## Overview

##### Project Type & Purpose
- This is a full-stack application designed for dairy farmers and ranchers to monitor and manage calf herds.
- The backend manages authentication, user and calf data with NestJS and PostgreSQL, while the frontend provides a Next.js-based interface for dashboards, details, and watchlist views.

##### File Structure and Key Components
- Backend:
- The “backend” directory is structured with NestJS modules. Key modules include the “auth” module (handles login/signup, JWT strategy, DTOs) and the “users” module (manages user entities and logic).
- Notice configuration files (e.g., .env.example, docker-compose.yml, tsconfig.json) which indicate how the backend is set up for development, testing, and deployment.
- Tests and build config files indicate that the system is designed with quality and modularity in mind.
- Frontend:
- The “frontend” directory, using Next.js, is divided into pages (like dashboard, details, and watchlist) and additional components for shared UI elements.
- It integrates with third-party libraries (Tailwind CSS, Shadcn UI, Recharts) for styling and visualizing data.
- API endpoints under “pages/api” indicate that some requests might be proxied or directly handled on the frontend framework, or possibly serve as helpers in the overall flow.
- Shared Concepts:
- Authentication is a common gateway; the frontend’s auth routes connect to the backend’s auth service.

a. Main Components:
- Frontend (Next.js based)
- Pages and layouts for authentication (signin/signup), dashboard, details, and watchlist.
- Supporting UI components and libraries (components folder, Tailwind CSS, Recharts).
- Integration with API endpoints (typically through fetch calls to the backend).
- Backend (NestJS based)
- Core application module (app.module.ts) aggregating submodules.
- Auth Module: handles user authentication and JWT token validation.
- Users Module: manages user data transactions.
- Other potential modules (extendable with more features, e.g., for managing calf data if implemented further).
- Infrastructure elements like configuration, environment setup, and error handling.
- Database:
- PostgreSQL (managed via Docker as suggested by the docker-compose file).
- Interfaced using TypeORM for data persistence.

b. Relationships & Interactions:
- The Frontend communicates with the Backend via RESTful API calls:
- Authentication calls reach the backend’s auth endpoints.
- Data requests for dashboards, calf details, and watchlist information are forwarded to corresponding backend endpoints.
- The Backend processes the requests, interacts with the PostgreSQL database, and returns the results.
- Docker Compose plays a role in setting up the database container, which is crucial for the backend’s data layer.
- There is a clear request-response data flow, potentially with stateful sessions managed via JWTs.

c. Architectural Patterns & Design Principles:
- Separation of Concerns: Clear division between UI (frontend), application logic (backend modules), and data persistence (PostgreSQL).
- Modular Design: The use of NestJS modules (auth, users, etc.) enforces a modular architecture.
- MVC (or a similar layered architecture) on the backend, where controllers handle routes, services handle business logic, and entities represent database models.
- Use of API-first or RESTful design in component interactions.
- Emphasis on scalability using containerized services (via Docker).

d. Mention Relevant Technologies:
- Frontend: Next.js 14, React, TypeScript, Tailwind CSS, Shadcn UI, Recharts.
- Backend: NestJS, TypeScript, PostgreSQL, TypeORM.
- Additional: Docker for containerizing and orchestrating the database service.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend"
        F_UI["Frontend (Next.js UI Layer)"]:::frontend
        F_Auth["Authentication Pages"]:::frontend
        F_Dashboard["Dashboard View"]:::frontend
        F_Details["Details View"]:::frontend
        F_Watchlist["Watchlist View"]:::frontend
        F_Shared["Shared UI Components"]:::frontend
        F_Calves["Calves Components"]:::frontend
        F_DashboardComp["Dashboard Components"]:::frontend
    end

    subgraph "Backend"
        B_Core["Backend Core Module"]:::backend
        B_Auth["Authentication Module"]:::backend
        B_Users["Users Module"]:::backend
        B_Auth_Controller["Auth Controller"]:::backend
        B_Users_Controller["Users Controller"]:::backend
    end

    DB["PostgreSQL Database"]:::database

    %% Frontend Pages aggregated under the UI layer
    F_UI --> F_Auth
    F_UI --> F_Dashboard
    F_UI --> F_Details
    F_UI --> F_Watchlist
    F_UI --> F_Shared
    F_UI --> F_Calves
    F_UI --> F_DashboardComp

    %% Frontend to Backend API calls
    F_Auth -->|"HTTP"| B_Auth_Controller
    F_Dashboard -->|"HTTP"| B_Users_Controller
    F_Details -->|"HTTP"| B_Users_Controller
    F_Watchlist -->|"HTTP"| B_Users_Controller

    %% Backend module relations
    B_Core --> B_Auth
    B_Core --> B_Users
    B_Auth --> B_Auth_Controller
    B_Users --> B_Users_Controller

    %% Backend to Database interactions
    B_Auth -->|"TypeORM"| DB
    B_Users -->|"TypeORM"| DB

    %% Click Events for Frontend
    click F_UI "https://github.com/jakecooke98/calf-care/tree/master/frontend/app"
    click F_Auth "https://github.com/jakecooke98/calf-care/tree/master/frontend/app/(auth)"
    click F_Dashboard "https://github.com/jakecooke98/calf-care/tree/master/frontend/app/dashboard"
    click F_Details "https://github.com/jakecooke98/calf-care/tree/master/frontend/app/details"
    click F_Watchlist "https://github.com/jakecooke98/calf-care/tree/master/frontend/app/watchlist"
    click F_Shared "https://github.com/jakecooke98/calf-care/tree/master/frontend/components/ui"
    click F_Calves "https://github.com/jakecooke98/calf-care/tree/master/frontend/components/calves"
    click F_DashboardComp "https://github.com/jakecooke98/calf-care/tree/master/frontend/components/dashboard"

    %% Click Events for Backend
    click B_Core "https://github.com/jakecooke98/calf-care/blob/master/backend/src/app.module.ts"
    click B_Auth "https://github.com/jakecooke98/calf-care/tree/master/backend/src/auth"
    click B_Auth_Controller "https://github.com/jakecooke98/calf-care/blob/master/backend/src/auth/auth.controller.ts"
    click B_Users "https://github.com/jakecooke98/calf-care/tree/master/backend/src/users"
    click B_Users_Controller "https://github.com/jakecooke98/calf-care/blob/master/backend/src/users/users.controller.ts"

    %% Click Event for Database Setup
    click DB "https://github.com/jakecooke98/calf-care/blob/master/backend/docker-compose.yml"

    %% Styles
    classDef frontend fill:#AEC6CF,stroke:#333,stroke-width:2px;
    classDef backend fill:#77DD77,stroke:#333,stroke-width:2px;
    classDef database fill:#FDFD96,stroke:#333,stroke-width:2px;
```
