# ezegatica/que-me-pongo architecture

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

- Interactive diagram: https://gitdiagram.com/ezegatica/que-me-pongo
- Repository: https://github.com/ezegatica/que-me-pongo

## Overview

##### Project Type and Purpose
- The project is a full-stack web application built with Next.js (using the new “app” directory structure). The purpose is to assist users by recommending clothing choices based on real-time temperature data from the OpenWeatherMap API and historical user responses.
- It integrates user onboarding, personalized recording of responses, and several forms of user interaction (e.g., login, settings, form submissions).

##### Analyzing the File Structure
- Top-Level Directories and Files:
- The “app” folder holds the React components, pages, layouts, and API routes.
- “app/api” contains API endpoints including routes for authentication (using NextAuth, as suggested by the [...nextauth] route), health checks (e.g., DB health), open graph metadata (OG), and secure revalidation endpoints.
- “app/app” and its nested directories (e.g., forms, onboarding, pronostico, respuestas, etc.) show that the application is segmented into various functional modules.
- The “prisma” folder holds the database schema and migrations, revealing that Prisma is used for ORM/database management.
- Configuration files such as next.config.js, tsconfig.json, tailwind.config.ts, and various linting/prettier configuration files indicate standard project setup and stylistic enforcement.

##### Key System Components
a. Frontend Components:
- Next.js Pages & Layouts: Represented under “app/landing”, “app/app”, “app/auth”, etc.
- Shared and reusable components under “app/(components)” (e.g., banners, buttons, toast notifications, headers, etc.).
- Onboarding UI flows and settings pages that customize the user experience.

b. Backend/API Components:
- API Routes: Under “app/api”, grouped by functionality (authentication, health, OG metadata, secure revalidation), these endpoints provide RESTful interfaces or Next.js server-side endpoints.
- Authentication System: Clearly indicated by the “auth” folder and NextAuth route handling.

c. Database and ORM:
- Prisma ORM: With migrations in the “prisma/migrations” folder and schema defined in “prisma/schema.prisma”; stores user responses, preferences, and related data.
- Database: The physical persistence layer that Prisma communicates with (likely PostgreSQL, MySQL, or another relational database) though that isn’t directly mentioned but can be inferred.

d. External Services and Integration:
- Weather API Integration: Utilizing OpenWeatherMap API as described in the README; this data drives the recommendation logic.
- Possibly additional integrations for authentication or other services, as hinted by security-related API endpoints.

e. Middleware & Global Configurations:
- Middleware found in “middleware.ts” that may handle authentication, logging, or routing pre-processing.
- Global styles and configurations (e.g., “app/globals.css”, tailwind.config.ts) consolidating the app’s visual and style management.

##### Relationships and Data Flow
- The Frontend (React components/pages) makes calls to the API endpoints which handle data logic and communicate with the database.
- The API layer authenticates users (via NextAuth) and also processes incoming weather information and user input (e.g., form actions for onboarding, settings, and “¿Qué me pongo?” queries).
- Prisma serves as a bridge between the API and the underlying database, handling migrations and queries.
- External API integration (OpenWeatherMap) feeds current and forecast weather data into the recommendation logic, influencing the UI responses and records.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clear division between UI (components and pages), API logic (serverless API routes), and data persistence (Prisma with migrations).
- Integration Pattern: Use of external REST APIs (OpenWeatherMap) within the backend to enhance data-driven decisions.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend (UI/Pages)
    subgraph "Frontend (UI/Pages)"
        FP["Landing Page"]:::frontend
        FA["Main App Layout & Pages"]:::frontend
        FC["Shared Components"]:::frontend
        WA["Weather Alerts Component"]:::frontend
    end

    %% Backend (API Endpoints)
    subgraph "Backend (API Endpoints)"
        A1["Authentication (NextAuth)"]:::api
        A2["Health Check API"]:::api
        A3["Open Graph API"]:::api
        A4["Secure Revalidation API"]:::api
    end

    %% Database & ORM
    subgraph "Database & ORM"
        PS["Prisma Schema"]:::db
        PM["Prisma Migrations"]:::db
        DB["Database"]:::db
    end

    %% Global Configurations
    subgraph "Global Config"
        GM["Global Middleware"]:::config
        GS["Global Styles"]:::config
        TC["Tailwind Config"]:::config
    end

    %% External Services
    subgraph "External Services"
        EW["OpenWeatherMap API"]:::external
    end

    %% Relationships: Frontend -> Backend
    FP -->|"calls"| A1
    FA -->|"calls"| A2
    FC -->|"calls"| A3
    WA -->|"requests"| EW
    EW -->|"returns"| WA

    %% Relationships: Backend -> Database
    A1 -->|"queries"| PS
    A2 -->|"queries"| DB
    A3 -->|"queries"| PS
    A4 -->|"queries"| PS

    %% Relationships: Global Middleware influences API Endpoints
    GM -->|"handles"| A1
    GM -->|"handles"| A2
    GM -->|"handles"| A3
    GM -->|"handles"| A4

    %% Relationships: Global Config influences Frontend
    GS -->|"styles"| FP
    GS -->|"styles"| FA

    %% Relationships: Prisma Integration
    PS -->|"migrates"| PM
    PM -->|"updates"| DB

    %% Click Events for Frontend Components
    click FP "https://github.com/ezegatica/que-me-pongo/blob/dev/app/(landing)/page.tsx"
    click FA "https://github.com/ezegatica/que-me-pongo/blob/dev/app/app/layout.tsx"
    click FC "https://github.com/ezegatica/que-me-pongo/tree/dev/app/(components)"
    click WA "https://github.com/ezegatica/que-me-pongo/blob/dev/app/(components)/weather-alerts.tsx"

    %% Click Events for API Endpoints
    click A1 "https://github.com/ezegatica/que-me-pongo/blob/dev/app/api/auth/[...nextauth]/route.ts"
    click A2 "https://github.com/ezegatica/que-me-pongo/blob/dev/app/api/health/db/route.ts"
    click A3 "https://github.com/ezegatica/que-me-pongo/blob/dev/app/api/og/route.tsx"
    click A4 "https://github.com/ezegatica/que-me-pongo/blob/dev/app/api/secure/revalidate/route.ts"

    %% Click Events for Database & ORM
    click PS "https://github.com/ezegatica/que-me-pongo/blob/dev/prisma/schema.prisma"
    click PM "https://github.com/ezegatica/que-me-pongo/tree/dev/prisma/migrations"

    %% Click Events for Global Configurations
    click GM "https://github.com/ezegatica/que-me-pongo/blob/dev/middleware.ts"
    click GS "https://github.com/ezegatica/que-me-pongo/blob/dev/app/globals.css"
    click TC "https://github.com/ezegatica/que-me-pongo/blob/dev/tailwind.config.ts"

    %% Styling Classes
    classDef frontend fill:#D1E8FF,stroke:#036,stroke-width:2px;
    classDef api fill:#C1F0C1,stroke:#0A3,stroke-width:2px;
    classDef db fill:#FFE6B3,stroke:#D85,stroke-width:2px;
    classDef config fill:#F4D1D1,stroke:#933,stroke-width:2px;
    classDef external fill:#FFD1DC,stroke:#D33,stroke-width:2px;
```
