# astashov/liftosaur architecture

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

- Interactive diagram: https://gitdiagram.com/astashov/liftosaur
- Repository: https://github.com/astashov/liftosaur

## Overview

##### Main Components

a. Client-Side (Frontend):
- PWA Application (Preact/TypeScript)
- Service Worker (for offline functionality)
- Local Storage/IndexedDB (for offline data persistence)
- CodeMirror Editor (for Liftoscript)
- uPlot (for graphs/charts)
- Tailwind CSS (for styling)

b. Server-Side (Backend):
- AWS Lambda Functions
- API Gateway
- DynamoDB (main database)
- S3 (static assets and storage)
- AWS Secrets Manager
- CloudFront (CDN)
- SES (email services)

##### Architecture Patterns

- Serverless Architecture (AWS Lambda)
- PWA Architecture (Service Worker, caching)
- Event-driven Architecture (for real-time updates)
- Custom State Management (Redux-like with lens-shmens)

##### Key Flows

a. Authentication Flow:
- Google Auth
- Apple Auth
- Session Management

b. Data Synchronization:
- Offline/Online sync mechanism
- Cloud storage sync
- Progress tracking

c. Program Management:
- Custom program creation
- Program sharing
- Exercise tracking

**[Client Layer]**

- PWA Container
- Service Worker
- Local Storage
- State Management
- UI Components

**[API Layer]**

- API Gateway
- Lambda Functions
- Auth Handler
- Program Handler
- Exercise Handler
- Stats Handler

**[Storage Layer]**

- DynamoDB Tables
- Users
- Programs
- Progress
- Statistics

- S3 Buckets
- Static Assets
- User Data
- Program Data

**[External Services]**

- CloudFront CDN
- SES Email Service
- Secrets Manager
- Auth Providers

##### Important Details

- Offline capability mechanism
- Liftoscript evaluation flow
- Data synchronization patterns
- Security boundaries
- Cache layers
- API endpoints structure

##### Interactions to Highlight

- How the PWA handles offline/online transitions
- Program creation and sharing flow
- Exercise tracking and progress monitoring
- Authentication and authorization flow
- Data backup and recovery processes

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        PWA[PWA Application]
        SW[Service Worker]
        LS[Local Storage/IndexedDB]
        LSE[Liftoscript Editor]
        SM[State Management]
        UI[UI Components]
        Sync[Data Sync]
        
        PWA --> SW
        PWA --> LS
        PWA --> LSE
        PWA --> SM
        PWA --> UI
        PWA --> Sync
    end

    subgraph API
        APIG[API Gateway]
        
        subgraph Lambda
            AuthH[Auth Handler]
            ProgH[Program Handler]
            ExH[Exercise Handler]
            StatsH[Stats Handler]
        end
        
        APIG --> AuthH
        APIG --> ProgH
        APIG --> ExH
        APIG --> StatsH
    end

    subgraph Storage
        DDB[(DynamoDB)]
        S3[(S3 Buckets)]
    end

    subgraph External
        CF[CloudFront CDN]
        SES[SES Email]
        SM2[Secrets Manager]
        Auth[Auth Providers]
        CW[CloudWatch]
    end

    PWA --> APIG
    Lambda --> DDB
    Lambda --> S3
    Lambda --> SES
    Lambda --> SM2
    Lambda --> CW
    CF --> PWA
    Auth --> AuthH

    classDef frontend fill:#3498db
    classDef aws fill:#2ecc71
    classDef storage fill:#e67e22
    classDef external fill:#9b59b6
    classDef security fill:#e74c3c

    class PWA,SW,LS,LSE,SM,UI,Sync frontend
    class APIG,AuthH,ProgH,ExH,StatsH,CF,SES,CW aws
    class DDB,S3 storage
    class Auth,SM2 security

    click PWA "https://github.com/astashov/liftosaur/tree/master/src"
    click SW "https://github.com/astashov/liftosaur/blob/master/src/webpushr-sw.ts"
    click LSE "https://github.com/astashov/liftosaur/blob/master/src/liftoscriptCodemirror.ts"
    click SM "https://github.com/astashov/liftosaur/tree/master/src/ducks"
    click AuthH "https://github.com/astashov/liftosaur/blob/master/lambda/login.tsx"
    click DDB "https://github.com/astashov/liftosaur/tree/master/lambda/dao"
    click S3 "https://github.com/astashov/liftosaur/blob/master/lambda/utils/s3.ts"
    click SM2 "https://github.com/astashov/liftosaur/blob/master/lambda/utils/secrets.ts"
    click SES "https://github.com/astashov/liftosaur/blob/master/lambda/utils/ses.ts"
    click CW "https://github.com/astashov/liftosaur/blob/master/lambda/utils/cloudwatch.ts"
    click APIG "https://github.com/astashov/liftosaur/blob/master/src/api/service.ts"
    click UI "https://github.com/astashov/liftosaur/tree/master/src/components"
    click LS "https://github.com/astashov/liftosaur/blob/master/src/utils/indexeddb.ts"
    click Sync "https://github.com/astashov/liftosaur/blob/master/src/utils/sync.ts"
```
