# pedrogagodev/dailydietapi architecture

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

- Interactive diagram: https://gitdiagram.com/pedrogagodev/dailydietapi
- Repository: https://github.com/pedrogagodev/dailydietapi

## Overview

##### Project type and purpose
- This is a full-stack diet-tracking application:
- Backend: A RESTful API (“DailyDietAPI”) built with Node.js, Fastify and TypeScript, following Clean Architecture.
- Frontend: A React/TypeScript web app using Vite, providing UI for registration, login, meal CRUD and metrics dashboard.
- Purpose: Let users register/login, record meals (with diet compliance flag), view metrics (total, on/off diet counts, best streak).

##### File structure
- Top-level “backend” and “frontend” directories indicate clear separation.
- Backend follows Clean Architecture:
- src/core (entities, repositories interfaces)
- src/use-cases (business logic)
- src/infra (database connection)
- src/repositories (concrete adapters)
- src/http (controllers, routes, middlewares)
- Database migrations under backend/database.
- Automated tests in controllers and use-cases.
- Frontend contains:
- components, pages, layouts, hooks, contexts
- services (httpClient, authService, mealsService)
- types and utils.
- Configuration: tsconfig, biome.json, Docker Compose for local Postgres.

##### Key README insights
- Architecture: Clean Architecture, separation of concerns.
- Tech stack: Node.js, Fastify, TypeScript, PostgreSQL, React/Vite.
- Security: JWT authentication, user isolation.
- Non-functional: performance, maintainability, test coverage.

##### Detail
- Middleware between HTTP server and controllers.
- Schema validation step (zod) before controller logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend (React/Vite)"
        direction TB
        FEApp["Frontend App"]:::frontend
        subgraph "Pages"
            direction TB
            Pages["Pages"]:::frontend
        end
        subgraph "Components"
            direction TB
            Components["Components"]:::frontend
            UI["UI Components"]:::frontend
        end
        AuthCtx["AuthContext"]:::frontend
        Hooks["Custom Hooks"]:::frontend
        Layouts["Layouts"]:::frontend
        subgraph "Services"
            direction TB
            HttpClient["HTTP Client"]:::frontend
            AuthService["Auth Service"]:::frontend
            MealsService["Meals Service"]:::frontend
            UsersService["Users Service"]:::frontend
            QueryClient["Query Client"]:::frontend
        end
        Types["Types"]:::frontend
        Utils["Utils"]:::frontend
    end

    subgraph "Backend (Fastify API)"
        direction TB
        Server["API Entry Points"]:::backend
        Routes["HTTP Routes"]:::backend
        Middlewares["Middlewares"]:::backend
        Validation["Request Validation (zod)"]:::backend
        Controllers["Controllers"]:::backend
        subgraph "Clean Architecture"
            direction TB
            UseCaseFactory["Use-Case Factories"]:::backend
            subgraph "Use Cases"
                direction TB
                UserUseCases["User Use-Case Impl."]:::backend
                MealUseCases["Meal Use-Case Impl."]:::backend
            end
            subgraph "Repositories"
                direction TB
                RepoInterfaces["Repository Interfaces"]:::backend
                DbRepos["DB Repositories"]:::backend
                InMemRepos["In-Memory Repos (testing)"]:::backend
            end
            Entities["Core Entities"]:::backend
        end
        DBConn["DB Connection"]:::backend
    end

    DB["PostgreSQL Database"]:::db

    subgraph "External Services (Future)"
        direction TB
        Stripe["Stripe (payments)"]:::external
        Nutritionix["Nutritionix API"]:::external
    end

    FEApp --> Pages
    FEApp --> Components
    Components --> UI
    FEApp --> AuthCtx
    FEApp --> Hooks
    FEApp --> Layouts
    FEApp --> HttpClient
    FEApp --> Types
    FEApp --> Utils

    HttpClient -->|calls| Server
    AuthService --> HttpClient
    MealsService --> HttpClient
    UsersService --> HttpClient
    QueryClient --> HttpClient

    Server -->|registers| Routes
    Routes --> Validation
    Validation --> Controllers
    Controllers --> Middlewares
    Middlewares --> Controllers
    Controllers --> UseCaseFactory
    UseCaseFactory --> UserUseCases
    UseCaseFactory --> MealUseCases
    UserUseCases --> RepoInterfaces
    MealUseCases --> RepoInterfaces
    RepoInterfaces --> DbRepos
    RepoInterfaces --> InMemRepos
    DbRepos --> DBConn
    DBConn --> DB

    Stripe -.->|future| Server
    Nutritionix -.->|future| Server

    click FEApp "https://github.com/pedrogagodev/dailydietapi/tree/main/frontend/src"
    click Pages "https://github.com/pedrogagodev/dailydietapi/tree/main/frontend/src/pages"
    click Components "https://github.com/pedrogagodev/dailydietapi/tree/main/frontend/src/components"
    click UI "https://github.com/pedrogagodev/dailydietapi/tree/main/frontend/src/components/ui"
    click AuthCtx "https://github.com/pedrogagodev/dailydietapi/blob/main/frontend/src/contexts/AuthContext.tsx"
    click Hooks "https://github.com/pedrogagodev/dailydietapi/tree/main/frontend/src/hooks"
    click Layouts "https://github.com/pedrogagodev/dailydietapi/tree/main/frontend/src/layouts"
    click HttpClient "https://github.com/pedrogagodev/dailydietapi/blob/main/frontend/src/services/httpClient.ts"
    click AuthService "https://github.com/pedrogagodev/dailydietapi/tree/main/frontend/src/services/authService"
    click MealsService "https://github.com/pedrogagodev/dailydietapi/tree/main/frontend/src/services/mealsService"
    click UsersService "https://github.com/pedrogagodev/dailydietapi/tree/main/frontend/src/services/usersService"
    click QueryClient "https://github.com/pedrogagodev/dailydietapi/blob/main/frontend/src/services/query-client.ts"
    click Types "https://github.com/pedrogagodev/dailydietapi/tree/main/frontend/src/types"
    click Utils "https://github.com/pedrogagodev/dailydietapi/blob/main/frontend/src/lib/utils.ts"

    click Server "https://github.com/pedrogagodev/dailydietapi/blob/main/backend/src/server.ts"
    click Routes "https://github.com/pedrogagodev/dailydietapi/blob/main/backend/src/routes/user-routes.ts"
    click Controllers "https://github.com/pedrogagodev/dailydietapi/tree/main/backend/src/http/controllers"
    click Validation "https://github.com/pedrogagodev/dailydietapi/tree/main/backend/src/schemas"
    click Middlewares "https://github.com/pedrogagodev/dailydietapi/tree/main/backend/src/http/middlewares"
    click UseCaseFactory "https://github.com/pedrogagodev/dailydietapi/tree/main/backend/src/use-cases/factories"
    click UserUseCases "https://github.com/pedrogagodev/dailydietapi/tree/main/backend/src/use-cases/users"
    click MealUseCases "https://github.com/pedrogagodev/dailydietapi/tree/main/backend/src/use-cases/meals"
    click RepoInterfaces "https://github.com/pedrogagodev/dailydietapi/tree/main/backend/src/core/repositories"
    click DbRepos "https://github.com/pedrogagodev/dailydietapi/tree/main/backend/src/repositories"
    click InMemRepos "https://github.com/pedrogagodev/dailydietapi/tree/main/backend/src/repositories/in-memory"
    click Entities "https://github.com/pedrogagodev/dailydietapi/tree/main/backend/src/core/entities"
    click DBConn "https://github.com/pedrogagodev/dailydietapi/blob/main/backend/src/infra/database/connection.ts"

    classDef frontend fill:#D6E8FF,stroke:#4A90E2,stroke-width:1px
    classDef backend fill:#E8F8E8,stroke:#27AE60,stroke-width:1px
    classDef db fill:#FFE8CC,stroke:#E67E22,stroke-width:1px
    classDef external fill:#F0F0F0,stroke:#95A5A6,stroke-width:1px
```
