Skip to content

Instantly share code, notes, and snippets.

@neilsh
Last active June 15, 2023 17:45
Show Gist options
  • Save neilsh/e5deb434622204e9141b45f67571a55b to your computer and use it in GitHub Desktop.
Save neilsh/e5deb434622204e9141b45f67571a55b to your computer and use it in GitHub Desktop.
GPT4-generated MermaidJS for Flask CRUD app with cache
sequenceDiagram
    participant C as Client
    participant S as Server
    participant R as Redis Cache
    participant DB as Database

    Note over C,S: Create
    C->>S: POST /resource
    S->>DB: db.session.add(resource)
    DB-->>S: Acknowledge
    S->>S: db.session.commit()
    S->>R: cache.set(resource_key, resource)
    S-->>C: jsonify(resource), 201

    Note over C,S: Read
    C->>S: GET /resource/{id}
    S->>R: cache.get(resource_key)
    R-->>S: Cached data
    alt Cached data not found
        S->>DB: Resource.query.get(id)
        DB-->>S: Resource instance
        S->>R: cache.set(resource_key, resource)
    end
    S-->>C: jsonify(resource), 200

    Note over C,S: Update
    C->>S: PUT /resource/{id}
    S->>DB: Resource.query.get(id)
    DB-->>S: Resource instance
    S->>S: Update resource instance
    S->>DB: db.session.commit()
    DB-->>S: Acknowledge
    S->>R: cache.set(resource_key, resource)
    S-->>C: jsonify(resource), 200

    Note over C,S: Delete
    C->>S: DELETE /resource/{id}
    S->>DB: Resource.query.get(id)
    DB-->>S: Resource instance
    S->>S: db.session.delete(resource)
    S->>DB: db.session.commit()
    DB-->>S: Acknowledge
    S->>R: cache.delete(resource_key)
    S-->>C: jsonify(message: 'Resource deleted'), 200
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment