# lasseklovstad/pils-app architecture

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

- Interactive diagram: https://gitdiagram.com/lasseklovstad/pils-app
- Repository: https://github.com/lasseklovstad/pils-app

## Overview

##### Main Components

A. Frontend Layer:
- React-based UI (indicated by .tsx files)
- Key sections:
- Authentication flows (/auth routes)
- Batch management (/batch routes)
- Controller management (/controller routes)
- UI Components library (/components/ui)

B. Backend Layer:
- Server-side components (/app/.server)
- Data layer services
- Authentication services
- File handling services
- Email services

C. Database Layer:
- SQLite database (indicated by migrations and schema)
- Drizzle ORM integration

D. Infrastructure:
- Fly.io deployment
- Volume storage for database persistence
- Custom domain configuration

##### Relationships to Highlight

**[Client Browser] ←→ [Frontend Layer (React)] ←→ [Backend API Layer] ←→ [Data Layer] ←→ [SQLite Database]**
- ↓
- [External Services]
- (Email, File Storage)

##### Specific Component Details

Frontend Layer (Blue):
- Auth Module: LoginPage, SignUpPage, VerifyPage
- Batch Module: BatchDetailsPage, HomePage
- Controller Module: ControllerDetailsPage
- Shared UI Components
- Client-side utilities

Backend Layer (Green):
- Data Layer Services:
- Batch management
- Temperature control
- User management
- Session handling
- API Routes
- Authentication services
- File handling services
- Email service

Database Layer (Yellow):
- SQLite Database
- Migration system
- Schema definitions
- Data persistence layer

Infrastructure Layer (Gray):
- Fly.io deployment
- Volume management
- Domain configuration
- SFTP capabilities

##### Additional Elements

A. Security Flow:
- Authentication flow
- Session management
- Verification process

B. Data Flow:
- Batch processing pipeline
- Temperature control feedback loop
- File upload/download paths

C. Integration Points:
- API endpoints
- External service connections
- Database interactions

## Diagram (Mermaid)

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

    subgraph FrontendLayer["Frontend Layer"]
        direction TB
        EntryClient["Client Entry"]:::frontend
        EntryServer["Server Entry"]:::frontend
        
        subgraph UIModules["UI Modules"]
            direction TB
            AuthModule["Authentication Module"]:::frontend
            BatchModule["Batch Management"]:::frontend
            ControllerModule["Controller Module"]:::frontend
            UIComponents["UI Components Library"]:::frontend
        end
    end

    subgraph BackendLayer["Backend Layer"]
        direction TB
        APIRoutes["API Routes"]:::backend
        
        subgraph Services["Core Services"]
            direction TB
            AuthService["Authentication Service"]:::backend
            SessionMgmt["Session Management"]:::backend
            VerificationSys["Verification System"]:::backend
            FileHandler["File Handler"]:::backend
            EmailService["Email Service"]:::backend
            DataLayer["Data Layer Services"]:::backend
        end

        subgraph Components["Specialized Components"]
            direction TB
            BatchActions["Batch Actions"]:::backend
            BatchComponents["Batch Components"]:::backend
            ControllerComponents["Controller Components"]:::backend
        end
    end

    subgraph DatabaseLayer["Database Layer"]
        direction TB
        DBConfig["Database Configuration"]:::database
        DBSchema["Database Schema"]:::database
        DBMigrations["Database Migrations"]:::database
        SQLite[(SQLite Database)]:::database
    end

    subgraph Infrastructure["Infrastructure"]
        direction TB
        FlyConfig["Fly.io Configuration"]:::infra
        VolumeStorage["Volume Storage"]:::infra
    end

    %% Relationships
    Browser <--> EntryClient
    EntryClient <--> EntryServer
    EntryServer <--> APIRoutes
    UIModules <--> APIRoutes
    APIRoutes <--> Services
    Services <--> Components
    Services <--> SQLite
    DBConfig --> SQLite
    DBSchema --> SQLite
    DBMigrations --> SQLite
    SQLite --> VolumeStorage

    %% Click Events
    click AuthModule "https://github.com/lasseklovstad/pils-app/tree/main/app/routes/auth/"
    click BatchModule "https://github.com/lasseklovstad/pils-app/tree/main/app/routes/batch/"
    click ControllerModule "https://github.com/lasseklovstad/pils-app/tree/main/app/routes/controller/"
    click UIComponents "https://github.com/lasseklovstad/pils-app/tree/main/app/components/ui/"
    click DataLayer "https://github.com/lasseklovstad/pils-app/tree/main/app/.server/data-layer/"
    click AuthService "https://github.com/lasseklovstad/pils-app/blob/main/app/lib/auth.server.ts"
    click FileHandler "https://github.com/lasseklovstad/pils-app/blob/main/app/lib/batchFileStorage.ts"
    click EmailService "https://github.com/lasseklovstad/pils-app/blob/main/app/.server/emailService.ts"
    click DBSchema "https://github.com/lasseklovstad/pils-app/blob/main/db/schema.ts"
    click DBMigrations "https://github.com/lasseklovstad/pils-app/tree/main/migrations/"
    click APIRoutes "https://github.com/lasseklovstad/pils-app/tree/main/app/routes/api/"
    click SessionMgmt "https://github.com/lasseklovstad/pils-app/blob/main/app/lib/session.server.ts"
    click VerificationSys "https://github.com/lasseklovstad/pils-app/blob/main/app/lib/verification.server.ts"
    click FlyConfig "https://github.com/lasseklovstad/pils-app/blob/main/fly.toml"
    click EntryClient "https://github.com/lasseklovstad/pils-app/blob/main/app/entry.client.tsx"
    click EntryServer "https://github.com/lasseklovstad/pils-app/blob/main/app/entry.server.tsx"
    click BatchActions "https://github.com/lasseklovstad/pils-app/tree/main/app/routes/batch/actions/"
    click ControllerComponents "https://github.com/lasseklovstad/pils-app/tree/main/app/routes/controller/shared/"
    click BatchComponents "https://github.com/lasseklovstad/pils-app/tree/main/app/routes/batch/shared/"
    click DBConfig "https://github.com/lasseklovstad/pils-app/blob/main/db/config.server.ts"

    %% Styling
    classDef frontend fill:#2196F3,color:white
    classDef backend fill:#4CAF50,color:white
    classDef database fill:#FFC107,color:black
    classDef infra fill:#9E9E9E,color:white
    classDef external fill:#F44336,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        Backend["Backend Component"]:::backend
        Database["Database Component"]:::database
        Infrastructure["Infrastructure Component"]:::infra
    end
```
