# arthurlopesmagalhaes/cinemaapp architecture

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

- Interactive diagram: https://gitdiagram.com/arthurlopesmagalhaes/cinemaapp
- Repository: https://github.com/arthurlopesmagalhaes/cinemaapp

## Overview

##### Project type and purpose
- This is a cross-platform mobile full-stack application built in React Native with TypeScript.
- Purpose: allow end users to browse movies, select sessions and seats, purchase tickets via Stripe, and enable admin users to validate tickets at entry using a QR code scanner.

##### High-level components
a. Mobile Client (React Native)
- Presentation layer: screens (src/screens/… ) and reusable components (src/components/…).
- State management: Zustand/Redux-like stores (src/stores/…) and reducer (src/reducers/ticketReducer.ts).
- Navigation: React Navigation (src/routes/…).
- Business logic & utilities: utils (src/utils/…), form schemas (src/schemas/…).
b. API Layer
- Supabase client (src/services/supabase.ts) — authentication, real-time database CRUD, and edge functions (supabase/functions).
- Stripe client (src/services/stripeAPI.ts) — payment intent creation and confirmation.
c. Backend (Supabase)
- Database: movies, sessions, seats, users, tickets tables (seeded via supabase/seed.sql).
- Auth: user sign-up, login, roles (admin vs customer).
- Edge Functions: custom server-side logic (e.g., ticket generation, QR code validation).
d. External services
- Stripe API for secure payments.
- (Optionally) any third-party Lottie animations or font assets hosted locally.

##### Relationships and data flows
- UI → State stores: user interactions update in-memory store (e.g., cart, session).
- UI/Store → Supabase client: fetch movies/sessions, sign in/up, write ticket records.
- Store → Stripe client: initiate payment, wait for confirmation → on success invoke Supabase update.
- Admin scan flow: Mobile QR scanner reads ticket ID → call Supabase function → validate and mark as used.

##### Architectural patterns and principles
- Feature-based directory structure (screens, components, services, stores) enforces separation of concerns.
- Unidirectional data flow: UI dispatches actions → updates store → triggers API calls → updates state/UI.
- Thin client model: most business rules (ticket creation/validation) live in server-side Supabase functions.
- Reusable UI components and theming (src/global/theme.ts) for consistency.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Mobile Client"
        subgraph "Presentation Layer"
            Screens["React Native Screens"]:::client
            Components["Reusable UI Components"]:::client
        end
        subgraph "State Management Layer"
            Stores["Zustand Stores"]:::client
            Reducer["Ticket Reducer"]:::client
        end
        subgraph Navigation
            RoutesIndex["Routes Index"]:::client
            RoutesStack["Stack Routes"]:::client
        end
        Theme["Global Theme & Styles"]:::client
        subgraph "Business Logic & Utilities"
            Utils["Utilities (utils)"]:::client
            Schemas["Form Schemas"]:::client
            Types["Type Definitions"]:::client
        end
        subgraph "Static Assets"
            Fonts["Font Assets"]:::client
            Lottie["Lottie Animations"]:::client
        end
        subgraph "API Clients"
            SupabaseClient["Supabase Client"]:::client
            StripeClient["Stripe Client"]:::client
            APIService["Generic HTTP Service"]:::client
        end
    end

    subgraph "Supabase Backend"
        Auth["Auth Service"]:::backend
        DB[(Database)]:::backend
        EdgeFunctions["Edge Functions"]:::backend
    end

    ExternalStripe["Stripe Service"]:::external

    Screens -->|updates| Stores
    Components -->|uses| Stores
    Stores -->|fetch/write| SupabaseClient
    Stores -->|initiate payment| StripeClient
    SupabaseClient -->|read/write| DB
    DB -->|sync| SupabaseClient
    StripeClient -->|payment requests| ExternalStripe
    ExternalStripe -->|webhooks/events| SupabaseClient
    Screens -->|scan QR| EdgeFunctions
    EdgeFunctions -->|validate/update| DB

    click Screens "https://github.com/arthurlopesmagalhaes/cinemaapp/tree/main/src/screens"
    click Components "https://github.com/arthurlopesmagalhaes/cinemaapp/tree/main/src/components"
    click Stores "https://github.com/arthurlopesmagalhaes/cinemaapp/tree/main/src/stores"
    click Reducer "https://github.com/arthurlopesmagalhaes/cinemaapp/blob/main/src/reducers/ticketReducer.ts"
    click RoutesIndex "https://github.com/arthurlopesmagalhaes/cinemaapp/blob/main/src/routes/index.tsx"
    click RoutesStack "https://github.com/arthurlopesmagalhaes/cinemaapp/blob/main/src/routes/stack.routes.tsx"
    click Theme "https://github.com/arthurlopesmagalhaes/cinemaapp/blob/main/src/global/theme.ts"
    click Utils "https://github.com/arthurlopesmagalhaes/cinemaapp/tree/main/src/utils"
    click Schemas "https://github.com/arthurlopesmagalhaes/cinemaapp/tree/main/src/schemas"
    click Types "https://github.com/arthurlopesmagalhaes/cinemaapp/tree/main/src/@types"
    click Fonts "https://github.com/arthurlopesmagalhaes/cinemaapp/tree/main/src/assets/fonts"
    click Lottie "https://github.com/arthurlopesmagalhaes/cinemaapp/tree/main/src/assets/lottie"
    click SupabaseClient "https://github.com/arthurlopesmagalhaes/cinemaapp/blob/main/src/services/supabase.ts"
    click StripeClient "https://github.com/arthurlopesmagalhaes/cinemaapp/blob/main/src/services/stripeAPI.ts"
    click APIService "https://github.com/arthurlopesmagalhaes/cinemaapp/blob/main/src/services/api.ts"
    click EdgeFunctions "https://github.com/arthurlopesmagalhaes/cinemaapp/tree/main/supabase/functions"
    click DB "https://github.com/arthurlopesmagalhaes/cinemaapp/blob/main/supabase/seed.sql"
    click DB "https://github.com/arthurlopesmagalhaes/cinemaapp/blob/main/supabase/seed.sql"
    click .env "https://github.com/arthurlopesmagalhaes/cinemaapp/blob/main/.env.example"
    click Config "https://github.com/arthurlopesmagalhaes/cinemaapp/blob/main/supabase/config.toml"

    classDef client fill:#E0F7FA,stroke:#0288D1,stroke-width:1px
    classDef backend fill:#E8F5E9,stroke:#388E3C,stroke-width:1px
    classDef external fill:#FFF3E0,stroke:#F57C00,stroke-width:1px
```
