# nilsreichardt/ankigpt architecture

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

- Interactive diagram: https://gitdiagram.com/nilsreichardt/ankigpt
- Repository: https://github.com/nilsreichardt/ankigpt

## Overview

##### Project type and purpose
- This is a Flutter-based full-stack client application (multi-platform: web, macOS, mobile) that turns lecture slides or text into flashcards using the OpenAI GPT APIs and allows export to Anki via CSV. It uses Firebase (Auth, Firestore, Storage, Cloud Functions) and integrates Stripe for payments.

##### File structure
- Top-level:
- assets/, fonts/, web/, macos/ → platform assets and configs
- lib/ → Dart source, split into src/infrastructure (data access), src/models (domain objects), src/providers (state + business logic), src/pages & widgets (presentation)
- firebase.json, .firebaserc → Firebase hosting and project setup
- build.yaml, pubspec.yaml → build & dependency management
- test/ → unit and widget tests
- Architectural patterns:
- Layered architecture: Presentation → State (Riverpod providers) → Domain (models) → Infrastructure (repositories) → External backends
- Uses code-gen (freezed, json_serializable, Riverpod code gen)
- Modular separation by feature in pages, providers, models

##### README insights
- Core flow: user uploads PDF/text → app splits text → calls AI (GPT-3.5/4) via Cloud Functions or direct API → returns list of flashcards → user edits/deletes/deploys → exports CSV or shares decks → payment handled by Stripe
- Backend (prompts) is closed source; client orchestrates calls

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Client Side
  subgraph "Flutter Client" 
    direction TB
    FC["Flutter Client"]:::frontend
    click FC "https://github.com/nilsreichardt/ankigpt/blob/main/lib/main.dart"
    subgraph "Presentation Layer"
      direction TB
      UI["UI Widgets & Pages"]:::frontend
      click UI "https://github.com/nilsreichardt/ankigpt/tree/main/lib/src/pages/"
    end
    subgraph "State & DI"
      direction TB
      SP["SharedPreferences Provider"]:::state
      click SP "https://github.com/nilsreichardt/ankigpt/blob/main/lib/src/providers/shared_preferences_provider.dart"
      SA["Firebase Auth Provider"]:::state
      click SA "https://github.com/nilsreichardt/ankigpt/blob/main/lib/src/providers/firebase_auth_provider.dart"
      SCF["Cloud Firestore Provider"]:::state
      click SCF "https://github.com/nilsreichardt/ankigpt/blob/main/lib/src/providers/cloud_firestore_provider.dart"
      SS["Firebase Storage Provider"]:::state
      click SS "https://github.com/nilsreichardt/ankigpt/blob/main/lib/src/providers/firebase_storage_provider.dart"
      SF["Functions Provider"]:::state
      click SF "https://github.com/nilsreichardt/ankigpt/blob/main/lib/src/providers/functions_provider.dart"
      SCO["Stripe Checkout Provider"]:::state
      click SCO "https://github.com/nilsreichardt/ankigpt/blob/main/lib/src/providers/stripe_checkout_provider.dart"
      SPo["Stripe Portal Provider"]:::state
      click SPo "https://github.com/nilsreichardt/ankigpt/blob/main/lib/src/providers/stripe_portal_provider.dart"
      SG["Get Stripe Portal URL Provider"]:::state
      click SG "https://github.com/nilsreichardt/ankigpt/blob/main/lib/src/providers/get_stripe_portal_url_provider.dart"
    end
    subgraph "Domain Models"
      direction TB
      DM["Immutable Models"]:::domain
      click DM "https://github.com/nilsreichardt/ankigpt/tree/main/lib/src/models/"
    end
    subgraph "Infrastructure Layer"
      direction TB
      IR["Repositories & Firestore Utils"]:::infra
      click IR "https://github.com/nilsreichardt/ankigpt/tree/main/lib/src/infrastructure/"
      SR["Session Repository"]:::infra
      click SR "https://github.com/nilsreichardt/ankigpt/blob/main/lib/src/infrastructure/session_repository.dart"
      UR["User Repository"]:::infra
      click UR "https://github.com/nilsreichardt/ankigpt/blob/main/lib/src/infrastructure/user_repository.dart"
    end
  end

  %% Firebase Configuration
  CFG["Firebase Configuration"]:::infra
  click CFG "https://github.com/nilsreichardt/ankigpt/blob/main/firebase.json"
  click CFG "https://github.com/nilsreichardt/ankigpt/blob/main/lib/firebase_options_dev.dart"
  click CFG "https://github.com/nilsreichardt/ankigpt/blob/main/lib/firebase_options_prod.dart"

  %% Backend Services
  subgraph "Firebase Backend" 
    direction TB
    FA["Authentication"]:::backend
    FS["Firestore"]:::backend
    FST["Storage"]:::backend
    FN["Cloud Functions"]:::backend
  end

  %% External Services
  subgraph "External APIs"
    direction TB
    OAI["OpenAI GPT-3.5/4"]:::external
    STR["Stripe API"]:::external
  end

  %% Flows
  FC --> UI
  UI --> SA
  SA --> IR
  SCF --> IR
  SS --> IR
  SF --> FN
  SCO --> STR
  SPo --> STR
  SG --> STR
  SP <-->|cache| DM
  IR -->|auth| FA
  IR -->|data| FS
  IR -->|storage| FST
  FN -->|generate flashcards| OAI
  FC --> CFG

  %% Styles
  classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
  classDef state fill:#DFFFD0,stroke:#3A7D00,color:#3A7D00;
  classDef domain fill:#FFF5D0,stroke:#D19A00,color:#D19A00;
  classDef infra fill:#E0E0E0,stroke:#636363,color:#636363;
  classDef backend fill:#FFE0E0,stroke:#D63636,color:#D63636;
  classDef external fill:#FFF0B3,stroke:#D69E00,color:#D69E00;
```
