# homeycommunity/web architecture

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

- Interactive diagram: https://gitdiagram.com/homeycommunity/web
- Repository: https://github.com/homeycommunity/web

## Overview

##### Main Components

a. Frontend Layer:
- Next.js App Router Structure
- Public Pages (/app/store, /app/docs, /app/control)
- Authentication Pages
- Control Panel Interface
- UI Components Layer (/components)
- Theme Provider & Global Styles

b. API Layer:
- REST API Routes (/app/api)
- Authentication endpoints
- HCS (Homey Control System) endpoints
- Device control endpoints
- Version management
- API key management

c. Database Layer:
- Prisma ORM
- Database migrations
- Data models (visible in prisma/schema.prisma)

d. External Integrations:
- Homey Device Integration
- Authentication Provider
- Discord Integration
- Sentry for monitoring

**[Client Layer (Browser)]**
- ↕
**[Next.js Frontend Layer]**
- ↕
**[API Router Layer]**
- ↕
**[Business Logic Layer]**
- ↕
**[Database Layer]**

##### Key Relationships to Highlight

- Authentication flow between frontend and auth provider
- API request flow through middleware
- Database interactions through Prisma
- External service communications
- Homey device management flow

##### Specific Implementation Details

a. Create separate sections for:
- Core application features (/app/control, /app/store)
- API documentation system (/app/docs)
- Authentication system
- Device management system
- Version control system

b. Specialized components:
- API key management
- Homey device integration
- File handling system
- Token encryption

**⬡ Frontend Component**
**⬢ API Endpoint**
**○ External Service**
**□ Database Table**
**↔ Two-way Communication**
**→ One-way Data Flow**

##### Additional Notes

- Environment configuration handling
- API versioning structure (v1)
- Security boundaries
- Feature flags and configuration points
- Caching layers if implemented

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph FrontendLayer["Frontend Layer"]
        direction TB
        AppRouter["App Router"]:::frontend
        ThemeProvider["Theme Provider"]:::frontend
        UIComponents["UI Components"]:::frontend
        Pages["Public Pages"]:::frontend
        SignIn["Sign In Component"]:::frontend
        
        subgraph PublicPages
            Store["Store"]:::frontend
            Docs["Documentation"]:::frontend
            Control["Control Panel"]:::frontend
        end
    end

    subgraph APILayer["API Layer"]
        direction TB
        AuthAPI["Authentication API"]:::api
        HCSEndpoints["HCS Endpoints"]:::api
        DeviceControl["Device Control"]:::api
        VersionMgmt["Version Management"]:::api
        APIKeysMgmt["API Keys Management"]:::api
        HomeyAPI["Homey API"]:::api
    end

    subgraph CoreUtils["Core Utilities"]
        TokenEncryption["Token Encryption"]:::util
        APIKeyLib["API Key Library"]:::util
        SessionMgmt["Session Management"]:::util
    end

    subgraph DBLayer["Database Layer"]
        PrismaORM["Prisma ORM"]:::db
        DBMigrations["Database Migrations"]:::db
        DBClient["Database Client"]:::db
    end

    subgraph ExternalServices["External Services"]
        HomeyDevice["Homey Device"]:::external
        Discord["Discord"]:::external
        Sentry["Sentry Monitoring"]:::external
        AuthProvider["Auth Provider"]:::external
    end

    %% Relationships
    Browser <--> AppRouter
    AppRouter --> Pages
    AppRouter --> ThemeProvider
    AppRouter --> UIComponents
    Pages --> SignIn
    
    AppRouter <--> APILayer
    AuthAPI <--> AuthProvider
    HomeyAPI <--> HomeyDevice
    APILayer <--> CoreUtils
    APILayer <--> DBLayer
    APILayer --> Discord
    APILayer --> Sentry

    PrismaORM <--> DBMigrations
    PrismaORM <--> DBClient

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef db fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#f1c40f,stroke:#f39c12,color:black
    classDef util fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Click Events
    click AppRouter "https://github.com/homeycommunity/web/tree/main/app/*"
    click UIComponents "https://github.com/homeycommunity/web/tree/main/components/ui/*"
    click ThemeProvider "https://github.com/homeycommunity/web/blob/main/components/theme-provider.tsx"
    click Store "https://github.com/homeycommunity/web/tree/main/app/store/*"
    click Docs "https://github.com/homeycommunity/web/tree/main/app/docs/*"
    click Control "https://github.com/homeycommunity/web/tree/main/app/control/*"
    click AuthAPI "https://github.com/homeycommunity/web/blob/main/app/api/auth/[...nextauth]/route.ts"
    click HCSEndpoints "https://github.com/homeycommunity/web/tree/main/app/api/hcs/*"
    click DeviceControl "https://github.com/homeycommunity/web/tree/main/app/api/control/*"
    click VersionMgmt "https://github.com/homeycommunity/web/tree/main/app/api/version/*"
    click APIKeysMgmt "https://github.com/homeycommunity/web/blob/main/app/api/apikeys/route.ts"
    click PrismaORM "https://github.com/homeycommunity/web/blob/main/prisma/schema.prisma"
    click DBMigrations "https://github.com/homeycommunity/web/tree/main/prisma/migrations/*"
    click DBClient "https://github.com/homeycommunity/web/blob/main/lib/prisma.ts"
    click HomeyAPI "https://github.com/homeycommunity/web/tree/main/app/api/homey/*"
    click Discord "https://github.com/homeycommunity/web/blob/main/app/discord/route.tsx"
    click Sentry "https://github.com/homeycommunity/web/blob/main/sentry.client.config.ts"
    click TokenEncryption "https://github.com/homeycommunity/web/blob/main/lib/token-encryption.ts"
    click APIKeyLib "https://github.com/homeycommunity/web/blob/main/lib/api-key.ts"
    click SessionMgmt "https://github.com/homeycommunity/web/blob/main/lib/session-token.ts"
    click SignIn "https://github.com/homeycommunity/web/blob/main/components/sign-in.tsx"
```
