# redpangilinan/iotawise architecture

> Architecture diagram of the GitHub repository redpangilinan/iotawise, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/redpangilinan/iotawise
- Repository: https://github.com/redpangilinan/iotawise

## Overview

##### Main System Components

a. Client Layer:
- Next.js Frontend (app directory structure)
- PWA capabilities
- Authentication UI components
- Dashboard & Activity tracking interfaces

b. API Layer:
- Next.js API routes (/app/api/*)
- Authentication endpoints
- Activity management endpoints
- User management endpoints

c. Data Layer:
- Prisma ORM
- Neon PostgreSQL Database

##### Component Relationships

a. Frontend Components:
- Activity tracking components
- Dashboard components
- User components
- Charts and analytics
- Connection to the API layer

b. Authentication Flow:
- NextAuth.js integration
- Google Authentication provider
- Session management

c. Data Flow:
- API routes → Prisma ORM → Neon PostgreSQL
- Validation layer with Zod

##### Specific Implementation Details

Technical aspects:

a. Frontend Architecture:
- Route structure (/app directory)
- Authentication routes
- Dashboard and activity management routes
- Component hierarchy

b. API Structure:
- RESTful endpoints for activities
- User management endpoints
- Authentication endpoints

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        UI[Frontend UI Components]
        PWA[PWA Implementation]:::pwa
        Layout[Layout Components]:::layout
        Charts[Analytics & Charts]:::charts
    end

    subgraph Auth
        AuthUI[Authentication UI]:::auth
        NextAuth[NextAuth.js]:::auth
        GoogleAuth[Google Auth Provider]:::auth
        Session[Session Management]:::auth
    end

    subgraph API
        APIRoutes[API Routes]:::api
        AuthAPI[Auth Endpoints]:::api
        ActivityAPI[Activity Endpoints]:::api
        UserAPI[User Endpoints]:::api
        Validation[Zod Validation]:::validation
    end

    subgraph Data
        Prisma[Prisma ORM]:::data
        PostgreSQL[(Neon PostgreSQL)]:::data
    end

    subgraph Features
        ActivityTracker[Activity Tracking]:::feature
        Dashboard[Dashboard]:::feature
        StreakMonitor[Streak Monitoring]:::feature
        Analytics[Analytics System]:::feature
    end

    UI --> APIRoutes
    UI --> AuthUI
    AuthUI --> NextAuth
    NextAuth --> GoogleAuth
    NextAuth --> Session
    Session --> APIRoutes
    
    APIRoutes --> AuthAPI
    APIRoutes --> ActivityAPI
    APIRoutes --> UserAPI
    
    AuthAPI --> Validation
    ActivityAPI --> Validation
    UserAPI --> Validation
    
    Validation --> Prisma
    Prisma --> PostgreSQL

    ActivityTracker --> ActivityAPI
    Dashboard --> Analytics
    StreakMonitor --> ActivityAPI
    Analytics --> Charts

    %% Click Events
    click AuthUI "https://github.com/redpangilinan/iotawise/tree/main/app/(auth)"
    click NextAuth "https://github.com/redpangilinan/iotawise/blob/main/app/api/auth/[...nextauth]/route.ts"
    click AuthUI "https://github.com/redpangilinan/iotawise/blob/main/components/user/user-auth-form.tsx"
    click Session "https://github.com/redpangilinan/iotawise/blob/main/lib/auth.ts"
    click ActivityAPI "https://github.com/redpangilinan/iotawise/tree/main/app/api/activities"
    click ActivityTracker "https://github.com/redpangilinan/iotawise/tree/main/components/activity"
    click ActivityAPI "https://github.com/redpangilinan/iotawise/blob/main/lib/api/activities.ts"
    click Validation "https://github.com/redpangilinan/iotawise/blob/main/lib/validations/activity.ts"
    click Dashboard "https://github.com/redpangilinan/iotawise/tree/main/app/dashboard"
    click Dashboard "https://github.com/redpangilinan/iotawise/tree/main/components/pages/dashboard"
    click Analytics "https://github.com/redpangilinan/iotawise/blob/main/lib/api/dashboard.ts"
    click UserAPI "https://github.com/redpangilinan/iotawise/tree/main/app/api/users"
    click AuthUI "https://github.com/redpangilinan/iotawise/tree/main/components/user"
    click Validation "https://github.com/redpangilinan/iotawise/blob/main/lib/validations/user.ts"
    click Prisma "https://github.com/redpangilinan/iotawise/blob/main/prisma/schema.prisma"
    click PostgreSQL "https://github.com/redpangilinan/iotawise/blob/main/lib/db.ts"
    click Charts "https://github.com/redpangilinan/iotawise/tree/main/components/charts"
    click Analytics "https://github.com/redpangilinan/iotawise/blob/main/components/pages/dashboard/dashboard-cards.tsx"
    click PWA "https://github.com/redpangilinan/iotawise/blob/main/components/pwa-redirect.tsx"
    click PWA "https://github.com/redpangilinan/iotawise/blob/main/public/site.webmanifest"
    click Layout "https://github.com/redpangilinan/iotawise/tree/main/components/layout"
    click UI "https://github.com/redpangilinan/iotawise/tree/main/components/ui"
    click UI "https://github.com/redpangilinan/iotawise/blob/main/app/globals.css"
    click APIRoutes "https://github.com/redpangilinan/iotawise/tree/main/lib/api"
    click Session "https://github.com/redpangilinan/iotawise/blob/main/lib/session.ts"
    click Validation "https://github.com/redpangilinan/iotawise/tree/main/lib/validations"

    %% Styling
    classDef auth fill:#FFE873
    classDef api fill:#90EE90
    classDef data fill:#DDA0DD
    classDef feature fill:#87CEEB
    classDef validation fill:#FFA07A
    classDef charts fill:#98FB98
    classDef layout fill:#DEB887
    classDef pwa fill:#B0C4DE

    %% Legend
    subgraph Legend
        L1[Frontend Components]:::feature
        L2[Authentication]:::auth
        L3[API Layer]:::api
        L4[Data Layer]:::data
        L5[Validation]:::validation
    end
```
