# hedavam/midd-laundry architecture

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

- Interactive diagram: https://gitdiagram.com/hedavam/midd-laundry
- Repository: https://github.com/hedavam/midd-laundry

## Overview

##### Main Components

A. Frontend Layer:
- Client-side Components (src/components/)
- Calendar
- Machine
- Notifications
- UserForm components
- Pages (src/pages/)
- Room views
- API routes

B. Backend Layer:
- API Routes (/api)
- Loads endpoints
- Machines endpoints
- Rooms endpoints
- Database Models
- BaseModel
- Loads
- Machines
- Rooms

C. External Services:
- SendGrid (Email notifications)
- PostgreSQL Database
- Docker (development environment)

**[Client Layer]**

- ▼
**[Next.js Server Layer]**

- ▼
**[Data Layer]**

##### Detailed Component Relationships

A. Client Layer (Top):
- Page routing structure (rooms.js, [room].js)
- Material-UI theming system

B. Next.js Server Layer (Middle):
- API Routes structure showing endpoints for:
- /api/loads
- /api/machines
- /api/rooms
- Middleware handling
- Authentication flow (if implemented)

C. Data Layer (Bottom):
- PostgreSQL Database
- Knex.js Query Builder
- Migration system
- Seeding process

##### Data Flow Indicators

- Client-to-Server API calls
- Server-to-Database queries
- Email notification flow through SendGrid

##### Architectural Patterns to Highlight
- API-first design
- Model-View-Controller pattern in API routes
- Database migration strategy
- Component-based frontend architecture

##### Integration points with external services

Remember to:
- Keep the main flow clear and centered
- Related components together
- Version/environment indicators
- Scaling considerations

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Calendar["Calendar Component"]:::frontend
        Machine["Machine Component"]:::frontend
        Notifications["Notifications Component"]:::frontend
        UserForm["UserForm Components"]:::frontend
        Pages["Page Routes"]:::frontend
        Theme["Material UI Theme"]:::frontend
    end

    subgraph "Next.js Server"
        direction TB
        API["API Layer"]:::api
        subgraph "API Routes"
            LoadsAPI["Loads API"]:::api
            MachinesAPI["Machines API"]:::api
            RoomsAPI["Rooms API"]:::api
        end
        Middleware["API Middleware"]:::middleware
    end

    subgraph "Data Layer"
        direction TB
        subgraph "Database Models"
            BaseModel["Base Model"]:::model
            LoadsModel["Loads Model"]:::model
            MachinesModel["Machines Model"]:::model
            RoomsModel["Rooms Model"]:::model
        end
        
        subgraph "Database"
            PostgreSQL[(PostgreSQL)]:::database
            Migrations["Migrations"]:::database
            Seeds["Seeds"]:::database
        end
    end

    subgraph "External Services"
        SendGrid["SendGrid Email"]:::external
        Docker["Docker Environment"]:::external
    end

    %% Relationships
    Calendar --> API
    Machine --> API
    Notifications --> API
    UserForm --> API
    Pages --> API
    
    API --> Middleware
    Middleware --> LoadsAPI & MachinesAPI & RoomsAPI
    
    LoadsAPI --> LoadsModel
    MachinesAPI --> MachinesModel
    RoomsAPI --> RoomsModel
    
    LoadsModel & MachinesModel & RoomsModel --> BaseModel
    BaseModel --> PostgreSQL
    
    Migrations --> PostgreSQL
    Seeds --> PostgreSQL
    
    API --> SendGrid

    %% Click Events
    click Calendar "https://github.com/Hedavam/Midd-Laundry/blob/main/src/components/Calendar.js"
    click Machine "https://github.com/Hedavam/Midd-Laundry/blob/main/src/components/Machine.js"
    click Notifications "https://github.com/Hedavam/Midd-Laundry/blob/main/src/components/Notifications.js"
    click UserForm "https://github.com/Hedavam/Midd-Laundry/blob/main/src/components/UserForm.js"
    click Pages "https://github.com/Hedavam/Midd-Laundry/tree/main/src/pages"
    click Theme "https://github.com/Hedavam/Midd-Laundry/blob/main/src/material/theme.js"
    click LoadsAPI "https://github.com/Hedavam/Midd-Laundry/tree/main/src/pages/api/loads"
    click MachinesAPI "https://github.com/Hedavam/Midd-Laundry/tree/main/src/pages/api/machines"
    click RoomsAPI "https://github.com/Hedavam/Midd-Laundry/tree/main/src/pages/api/rooms"
    click Middleware "https://github.com/Hedavam/Midd-Laundry/blob/main/src/lib/middleware.js"
    click BaseModel "https://github.com/Hedavam/Midd-Laundry/blob/main/models/BaseModel.js"
    click LoadsModel "https://github.com/Hedavam/Midd-Laundry/blob/main/models/Loads.js"
    click MachinesModel "https://github.com/Hedavam/Midd-Laundry/blob/main/models/Machines.js"
    click RoomsModel "https://github.com/Hedavam/Midd-Laundry/blob/main/models/Rooms.js"
    click Migrations "https://github.com/Hedavam/Midd-Laundry/tree/main/knex/migrations"
    click Seeds "https://github.com/Hedavam/Midd-Laundry/tree/main/knex/seeds"

    %% Styling
    classDef frontend fill:#2196f3,stroke:#1565c0,color:white
    classDef api fill:#4caf50,stroke:#2e7d32,color:white
    classDef model fill:#ff9800,stroke:#ef6c00,color:white
    classDef database fill:#fdd835,stroke:#fbc02d,color:black
    classDef external fill:#f44336,stroke:#c62828,color:white
    classDef middleware fill:#9c27b0,stroke:#6a1b9a,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend"]:::frontend
        APIComponent["API"]:::api
        ModelComponent["Model"]:::model
        DatabaseComponent["Database"]:::database
        ExternalComponent["External Service"]:::external
        MiddlewareComponent["Middleware"]:::middleware
    end
```
