# whoyoux/snapcal architecture

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

- Interactive diagram: https://gitdiagram.com/whoyoux/snapcal
- Repository: https://github.com/whoyoux/snapcal

## Overview

##### Main Components
- Layout and Pages – e.g., the root page (app/page.tsx), dashboard (app/dashboard/page.tsx & loading.tsx), and layout (app/layout.tsx).
- UI Components – e.g., header, buttons, forms, and other components under src/components/ui.
- Assets and Global Styles – e.g., src/assets and src/app/globals.css.
- API Routes – inside src/app/api (the “auth” folder with dynamic routes like route.ts).
- Actions – for business logic such as calculate-calories inside src/actions.
- Database Layer: Since Prisma is used:
- Database Integration – show a component for the database. Mention that the Prisma schema (prisma/schema.prisma) defines the data model and that the lib layer (src/lib/prisma.ts) provides access.
- Middleware/Lib Components: Add a block for libraries and utilities:
- Auth & Utilities – include src/lib files that handle authentication and other safe actions.

##### Mapping Relationships and Interactions
- From the Frontend to API endpoints: Indicate that UI components and pages make API calls (for authentication, image uploading, etc.).
- From API endpoints to the Database: Represent API services interacting with the database via Prisma.
- Between the UI and Action components: Show that actions like calculate-calories are triggered by user interactions.
- Dependency on shared libraries (e.g., auth-client, auth-server) that mediate between the UI, API, and database.

##### Recognize Architectural Patterns and Design Principles
- Next.js Ecosystem: Note the separation of concerns provided by Next.js (client vs. server).
- MVC-Like Separation: Although not a classic MVC, you have distinct UI (views in components), business logic (actions and API routes as controllers), and data models (Prisma schema representing models).
- Componentization: The “src/components” directory indicates a reusable component approach for the frontend UI.

##### Specific Technologies, Frameworks, and Tools
- Next.js for the framework and page routing.
- Prisma for database connectivity and schema management.
- ESLint, PostCSS, and TypeScript for enhanced developer experience and code quality.
- Vercel deployment hints from the README (deployment component can be noted if relevant to architecture).

- Page Components and Layout (e.g., app/page.tsx, app/layout.tsx).
- UI Components (including both common UI elements and specialized components like upload-image forms).
- “API” section by diagramming:
- Auth-related endpoints in src/app/api/auth (especially the dynamic routes defined by [...all] and their respective route.ts).
- Business actions such as calculate-calories.
- Link the “Database” section with the connection library (src/lib/prisma.ts) that abstracts the Prisma ORM interactions.
- Optionally, add a note on deployment and environment configuration given the Vercel deployment instructions mentioned in the README.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        FL1["Page (src/app/page.tsx)"]
        FL2["Layout (src/app/layout.tsx)"]
        FL3["Dashboard Page (src/app/dashboard/page.tsx)"]
        FL4["Dashboard Loading (src/app/dashboard/loading.tsx)"]
        FL5["Global Styles (src/app/globals.css)"]
        subgraph "UI Components"
            UI1a["Header (src/components/header.tsx)"]
            UI1b["Upload Image Card (src/components/upload-image-card.tsx)"]
            UI1c["Upload Image Form (src/components/upload-image-form.tsx)"]
            UI1d["Other UI Components (src/components/ui/)"]
        end
        AS1["Assets (src/assets)"]
    end

    %% API / Server-side Layer
    subgraph "API / Server-side"
        API1["Auth API Route (src/app/api/auth/[...all]/route.ts)"]
        API2["Business Action (calculate-calories) (src/actions/calculate-calories.ts)"]
    end

    %% Database Layer
    subgraph "Database (Prisma)"
        DB1["Prisma Schema (prisma/schema.prisma)"]
        DB2["Prisma Client (src/lib/prisma.ts)"]
    end

    %% Utility Libraries and Schemas
    subgraph "Utility Libraries"
        Util1["Auth & Utils (src/lib)"]
        DS1["Upload Image Schema (src/schemas/upload-image-schema.ts)"]
    end

    %% Connections
    FL1 -->|"calls"| API1
    UI1a -->|"calls"| API1
    UI1b -->|"calls"| API2
    API1 -->|"queries"| DB2
    API2 -->|"updates"| DB2
    API1 -->|"validates"| DS1
    Util1 -->|"provides"| API1
    Util1 -->|"supports"| FL1

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef api fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef database fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef utils fill:#FFB6C1,stroke:#333,stroke-width:2px;

    class FL1,FL2,FL3,FL4,FL5,UI1a,UI1b,UI1c,UI1d,AS1 frontend;
    class API1,API2 api;
    class DB1,DB2 database;
    class Util1,DS1 utils;

    %% Click Events
    click FL1 "https://github.com/whoyoux/snapcal/blob/main/src/app/page.tsx"
    click FL2 "https://github.com/whoyoux/snapcal/blob/main/src/app/layout.tsx"
    click FL3 "https://github.com/whoyoux/snapcal/blob/main/src/app/dashboard/page.tsx"
    click FL4 "https://github.com/whoyoux/snapcal/blob/main/src/app/dashboard/loading.tsx"
    click FL5 "https://github.com/whoyoux/snapcal/blob/main/src/app/globals.css"
    click UI1a "https://github.com/whoyoux/snapcal/blob/main/src/components/header.tsx"
    click UI1b "https://github.com/whoyoux/snapcal/blob/main/src/components/upload-image-card.tsx"
    click UI1c "https://github.com/whoyoux/snapcal/blob/main/src/components/upload-image-form.tsx"
    click UI1d "https://github.com/whoyoux/snapcal/tree/main/src/components/ui/"
    click AS1 "https://github.com/whoyoux/snapcal/tree/main/src/assets"
    click API1 "https://github.com/whoyoux/snapcal/blob/main/src/app/api/auth/[...all]/route.ts"
    click API2 "https://github.com/whoyoux/snapcal/blob/main/src/actions/calculate-calories.ts"
    click DB1 "https://github.com/whoyoux/snapcal/blob/main/prisma/schema.prisma"
    click DB2 "https://github.com/whoyoux/snapcal/blob/main/src/lib/prisma.ts"
    click Util1 "https://github.com/whoyoux/snapcal/tree/main/src/lib"
    click DS1 "https://github.com/whoyoux/snapcal/blob/main/src/schemas/upload-image-schema.ts"
```
