# youngpro718/nysc-facilities architecture

> Architecture diagram of the GitHub repository youngpro718/nysc-facilities, 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/youngpro718/nysc-facilities
- Repository: https://github.com/youngpro718/nysc-facilities

## Overview

##### Main Components
- Frontend UI Layer: Represent the overall React-based user interface. This layer includes pages (in src/pages) and a rich set of React components (found under src/components). Note that the UI is extensively componentized – from generic UI controls (in src/components/ui) to domain-specific components (e.g., issues, keys, lighting, occupants, spaces, and profile).
- Supabase for database interactions (see src/integrations/supabase, supabase folder with migrations and configuration).
- API endpoints (under src/pages/api) that might be used to communicate between the front end and the backend.
- State and Context Management: Components like AuthContext (src/contexts) and various hooks for dashboard data, notifications, and session management represent shared state management.
- Build and Configuration: While not part of runtime, note that project configuration components such as Vite, Tailwind, and Typescript settings (e.g., vite.config.ts, tailwind.config.ts, tsconfig.json) underlie the build/deployment process.

##### Relationships and Interactions
- That the domain modules interact with shared contexts (AuthContext, ThemeProvider, etc.) and use utility functions (under src/utils and src/lib) as helpers.
- That scripts and SQL files (in scripts and supabase/migrations) are used for setup and operations on the database.

##### Architectural Patterns
- Component-based Architecture/MVC: The separation between UI components, pages, and domain-specific business logic is evident. Each domain (for example, “issues” or “spaces”) encapsulates its forms, hooks, types, and services.
- Modular Organization: The project is decomposed by feature, making each domain almost self-contained.
- Utilization of Context Hooks and Custom Hooks: Patterns for state-sharing (AuthContext, Dashboard hooks, etc.) should be noted.

##### Detail Relevant Technologies
- Frontend: React, TypeScript, Vite, shadcn-ui, Tailwind CSS.
- Backend/Integration: Supabase (with migrations and client integration), SQL scripts for setting up the database.
- Build Tools: Node.js, npm, and associated configuration files (package.json, bun.lockb, etc.).
- DevOps: Scripts for deployment (e.g., npm run dev) and integration with Lovable and potentially Netlify for custom domain deployment.

##### Elements
- Clear labels for each major component (e.g., “React Frontend”, “Supabase Integration”, “Authentication & Context”, “Issues Module”, “Keys Module”, “Lighting Module”, “Occupants Module”, “Spaces Module”, “Relocations Module”, “Profile & Dashboard”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend UI Layer
    subgraph "Frontend UI Layer"
        FPages("Pages"):::frontend
        FComponents("Components"):::frontend
    end

    %% Domain Modules
    subgraph "Domain Modules"
        Issues("Issues Module"):::module
        Keys("Keys Module"):::module
        Lighting("Lighting Module"):::module
        Occupants("Occupants Module"):::module
        Relocations("Relocations Module"):::module
        Spaces("Spaces Module"):::module
        Profile("Profile Module"):::module
    end

    %% Integration Layer
    subgraph "Integration Layer"
        Supabase("Supabase Integration (DB & Auth)"):::integration
        API("API Endpoints"):::integration
    end

    %% State and Context Management
    subgraph "State and Context Management"
        AuthContext("AuthContext & Providers"):::state
        SharedHooks("Shared Hooks"):::state
    end

    %% Build and Configuration
    subgraph "Build and Configuration"
        ViteConfig("Vite Config"):::config
        TailwindConfig("Tailwind Config"):::config
        TSConfig("TypeScript Configs"):::config
        PackageConfig("Package Config"):::config
    end

    %% Connections between Frontend and State/Domain
    FPages -->|"calls"| SharedHooks
    FComponents -->|"calls"| SharedHooks
    FPages -->|"renders"| Issues
    FPages -->|"renders"| Keys
    FPages -->|"renders"| Lighting
    FPages -->|"renders"| Occupants
    FPages -->|"renders"| Relocations
    FPages -->|"renders"| Spaces
    FPages -->|"renders"| Profile
    FComponents -->|"renders"| Issues
    FComponents -->|"renders"| Keys
    FComponents -->|"renders"| Lighting
    FComponents -->|"renders"| Occupants
    FComponents -->|"renders"| Relocations
    FComponents -->|"renders"| Spaces
    FComponents -->|"renders"| Profile

    %% Domain Modules interacting with State
    Issues -->|"uses"| AuthContext
    Keys -->|"uses"| AuthContext
    Lighting -->|"uses"| AuthContext
    Occupants -->|"uses"| AuthContext
    Relocations -->|"uses"| AuthContext
    Spaces -->|"uses"| AuthContext
    Profile -->|"uses"| AuthContext

    %% State hooks fetching data via API
    SharedHooks -->|"fetches"| API

    %% Domain Modules also initiate API calls
    Issues -->|"calls"| API
    Keys -->|"calls"| API
    Lighting -->|"calls"| API
    Occupants -->|"calls"| API
    Relocations -->|"calls"| API
    Spaces -->|"calls"| API
    Profile -->|"calls"| API

    %% API interacting with Supabase
    API -->|"queries"| Supabase

    %% Build and Configuration underpins the app (foundational layer)
    ViteConfig --- FPages
    TailwindConfig --- FComponents
    TSConfig --- SharedHooks
    PackageConfig --- API

    %% Click Events for Frontend UI Layer
    click FPages "https://github.com/youngpro718/nysc-facilities/tree/main/src/pages"
    click FComponents "https://github.com/youngpro718/nysc-facilities/tree/main/src/components"

    %% Click Events for Domain Modules
    click Issues "https://github.com/youngpro718/nysc-facilities/tree/main/src/components/issues"
    click Keys "https://github.com/youngpro718/nysc-facilities/tree/main/src/components/keys"
    click Lighting "https://github.com/youngpro718/nysc-facilities/tree/main/src/components/lighting"
    click Occupants "https://github.com/youngpro718/nysc-facilities/tree/main/src/components/occupants"
    click Relocations "https://github.com/youngpro718/nysc-facilities/tree/main/src/components/relocations"
    click Spaces "https://github.com/youngpro718/nysc-facilities/tree/main/src/components/spaces"
    click Profile "https://github.com/youngpro718/nysc-facilities/tree/main/src/components/profile"

    %% Click Events for Integration Layer
    click Supabase "https://github.com/youngpro718/nysc-facilities/tree/main/src/integrations/supabase"
    click API "https://github.com/youngpro718/nysc-facilities/tree/main/src/pages/api"

    %% Click Events for State and Context Management
    click AuthContext "https://github.com/youngpro718/nysc-facilities/blob/main/src/contexts/AuthContext.tsx"
    click SharedHooks "https://github.com/youngpro718/nysc-facilities/tree/main/src/hooks"

    %% Click Events for Build and Configuration
    click ViteConfig "https://github.com/youngpro718/nysc-facilities/blob/main/vite.config.ts"
    click TailwindConfig "https://github.com/youngpro718/nysc-facilities/blob/main/tailwind.config.ts"
    click TSConfig "https://github.com/youngpro718/nysc-facilities/blob/main/tsconfig.json"
    click PackageConfig "https://github.com/youngpro718/nysc-facilities/blob/main/package.json"

    %% Class definitions for styling
    classDef frontend fill:#b3cde0,stroke:#03396c,stroke-width:2px;
    classDef module fill:#ccebc5,stroke:#006644,stroke-width:2px;
    classDef integration fill:#fff2b2,stroke:#b58900,stroke-width:2px;
    classDef state fill:#fddbc7,stroke:#cb4b16,stroke-width:2px;
    classDef config fill:#e5d8bd,stroke:#a67d3d,stroke-width:2px;
```
