# domtes/once architecture

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

- Interactive diagram: https://gitdiagram.com/domtes/once
- Repository: https://github.com/domtes/once

## Overview

##### Project Type Identification
This is a serverless application running on AWS that provides one-time file sharing capabilities. The architecture should emphasize:
- Serverless components
- API-driven interactions
- Temporary storage mechanisms
- Security and access control

##### Main Components

a) Client Layer:
- CLI client (found in `/client` directory)
- Interaction with the API Gateway

b) API Layer:
- AWS API Gateway as the entry point
- Three main Lambda functions (found in `/once` directory):
- get-upload-ticket
- download-and-delete
- delete-served-files

c) Storage Layer:
- S3 bucket for file storage
- DynamoDB for metadata/state management

##### Client Layer (Top)
**┌─────────────┐**
- CLI Client  │
- ┘

##### API Layer (Middle)
**┌─────────────┐**
- API Gateway │
- ┘

**┌─────┴─────┬─────────────┬─────────────┐**
- Upload   │  Download   │   Delete    │
- Ticket   │    File     │   Files     │
- Lambda   │   Lambda    │   Lambda    │
- ┴─────────────┴─────────────┘

##### Storage Layer (Bottom)
**┌─────────────┐    ┌─────────────┐**
- S3 Bucket  │    │  DynamoDB   │
- ┘    └─────────────┘

##### Key Elements to Highlight

a) Flow Directions:
- One-time download mechanism

b) Security Components:
- IAM roles and permissions
- API Gateway authentication
- Temporary URL generation

c) Data Flow:
##### Upload Flow
- Client → API Gateway → get-upload-ticket Lambda
- Ticket generation and S3 presigned URL
- Direct file upload to S3

##### Download Flow
- Client → API Gateway → download-and-delete Lambda
- File retrieval from S3
- Automatic deletion after download

##### Cleanup Flow
- CloudWatch Events → delete-served-files Lambda
- Cleanup of expired/downloaded files

##### Additional Notes
- Timing indicators for temporary access
- Resource cleanup mechanisms
- Scaling capabilities

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph Client
        CLI["CLI Client"]:::client
    end

    %% API Layer
    subgraph APIGateway["API Gateway Layer"]
        APIG["REST API Gateway"]:::aws
    end

    %% Lambda Functions Layer
    subgraph LambdaFunctions["Lambda Functions"]
        UploadLambda["Get Upload Ticket Lambda"]:::lambda
        DownloadLambda["Download and Delete Lambda"]:::lambda
        CleanupLambda["Delete Served Files Lambda"]:::lambda
    end

    %% Storage Layer
    subgraph Storage["Storage Layer"]
        S3["S3 Bucket"]:::storage
        DDB["DynamoDB"]:::storage
    end

    %% Infrastructure Layer
    subgraph Infrastructure["Infrastructure"]
        CDK["CDK Stack"]:::infra
        Config["Configuration"]:::infra
    end

    %% Supporting Services
    CW["CloudWatch Events"]:::aws
    IAM["IAM Roles & Policies"]:::aws

    %% Connections
    CLI --> APIG
    APIG --> UploadLambda
    APIG --> DownloadLambda
    UploadLambda --> S3
    UploadLambda --> DDB
    DownloadLambda --> S3
    DownloadLambda --> DDB
    CW --> CleanupLambda
    CleanupLambda --> S3
    CleanupLambda --> DDB
    IAM --> UploadLambda
    IAM --> DownloadLambda
    IAM --> CleanupLambda

    %% Click Events
    click CLI "https://github.com/domtes/once/blob/master/client/__init__.py"
    click UploadLambda "https://github.com/domtes/once/blob/master/once/get-upload-ticket/handler.py"
    click DownloadLambda "https://github.com/domtes/once/blob/master/once/download-and-delete/handler.py"
    click CleanupLambda "https://github.com/domtes/once/blob/master/once/delete-served-files/handler.py"
    click CDK "https://github.com/domtes/once/blob/master/once/once_stack.py"
    click Config "https://github.com/domtes/once/blob/master/cdk.json"

    %% Styles
    classDef aws fill:#FF9900,stroke:#232F3E,color:white
    classDef lambda fill:#FF9900,stroke:#232F3E,color:white
    classDef storage fill:#3F8624,stroke:#232F3E,color:white
    classDef client fill:#1EC9E8,stroke:#232F3E,color:white
    classDef infra fill:#999999,stroke:#232F3E,color:white

    %% Legend
    subgraph Legend
        L1["AWS Services"]:::aws
        L2["Lambda Functions"]:::lambda
        L3["Storage Services"]:::storage
        L4["Client Components"]:::client
        L5["Infrastructure"]:::infra
    end
```
