# adamblackman/briefo-public architecture

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

- Interactive diagram: https://gitdiagram.com/adamblackman/briefo-public
- Repository: https://github.com/adamblackman/briefo-public

## Overview

##### Project type and purpose
- Briefo is a full-stack, cross-platform mobile social app built with React Native/Expo Router (TypeScript) that delivers AI-generated newsfeeds, enables chat & comments, tracks stock portfolios, and provides AI-driven research.
- Backend is powered by Supabase (PostgreSQL, Auth, Realtime) plus a suite of Supabase Edge Functions (TypeScript on Deno) that implement serverless micro-services calling external APIs (Perplexity, Alpaca, Alpha Vantage, LinkPreview).

##### File structure
- app/ – Expo Router pages & layouts, React Native entry points for chat, tabs, article, profile, stock research, etc.
- components/ – Reusable UI pieces organized by feature (chat, news, portfolio, profile, notifications, friends, stocks).
- context/, hooks/, lib/ – State contexts (Auth, Theme, NavigationFocus), custom hooks and utility functions (Supabase client, data-fetch wrappers).
- supabase/functions/ – Edge Functions grouped by feature (perplexity-news, perplexity-chat, stock-detail, portfolio-tab-data, notifications helpers).
- types/, data/ – TypeScript interfaces reflecting Supabase tables and mock data for tests/demo.
- Configuration – metro.config.js, tsconfig.json, bolt & npm config, eas.json for Expo Application Services.

##### README for additional insights
- Clearly states tech stack tiers: Frontend (Expo + React Native), Backend (Supabase core + Edge Functions), Third-party APIs.
- Describes feature-specific Edge Functions (daily-news cron, research reports, live quotes, notifications).
- Mentions scheduling/cron and realtime flows via Supabase Realtime & triggers.

a. Main components
– Mobile Client (iOS/Android/Web)
– Supabase Auth & Realtime (WebSocket subscriptions)
– Supabase PostgreSQL Database (with RLS policies)
– Supabase Edge Functions (serverless microservices)
– Third-Party APIs (Perplexity AI, LinkPreview, Alpaca, Alpha Vantage)
– Optional CI/CD for function deployment (Supabase CLI, GitHub Actions)
b. Relationships and interactions
– Mobile Client ↔ Supabase Auth (login, token refresh)
– Mobile Client ↔ Supabase Database (CRUD via Supabase JS, realtime updates)
– Mobile Client ↔ Edge Functions (RPC calls via REST endpoints for heavy AI work)
– Edge Functions ↔ Third-Party APIs (HTTP calls to Perplexity, Alpaca, etc.)
– Edge Functions ↔ Database (write results back into tables)
c. Architectural patterns & design principles
– Client-Server separation: UI vs. data/business logic
– Microservices: each Edge Function encapsulates one domain action
– Event-driven / cron jobs for scheduled news generation
– Realtime subscriptions for chat and notifications
– RLS and service-role key segregation for security
d. Key technologies, frameworks & libraries
– Frontend: Expo Router, React Navigation, React Context, custom hooks
– Backend: Supabase JS client, Deno runtime (Edge Functions)
– Utilities: React-Query style data-fetch in lib/ & hooks/
– CI/CD: Expo Application Services (EAS), Supabase CLI

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Tier
    subgraph "Client Tier"
        subgraph "UI Routing"
            AuthScreen["Authentication Screen"]:::frontend
            TabsNav["Tabs Navigation"]:::frontend
            ChatRouting["Chat Feature Routing"]:::frontend
            ArticlePages["Article Pages"]:::frontend
            StockResearch["Stock Research Pages"]:::frontend
            UserProfile["User Profile Pages"]:::frontend
        end
        subgraph "State Management"
            AuthCtx["AuthContext"]:::frontend
            NavFocusCtx["NavigationFocusContext"]:::frontend
            ThemeCtx["ThemeContext"]:::frontend
            UseFramework["useFrameworkReady Hook"]:::frontend
            SupabaseLib["supabase.ts"]:::frontend
            ProfileUtils["profileUtils.ts"]:::frontend
        end
    end

    %% Backend Tier
    subgraph "Backend Tier"
        subgraph "Supabase Core"
            AuthDB["Supabase Auth & DB"]:::backend
        end
        subgraph "Serverless Microservices (Edge Functions)"
            PNews["perplexity-news Fn"]:::functions
            DailyNews["daily-news-suggestions Fn"]:::functions
            PChat["perplexity-chat Fn"]:::functions
            PResearch["perplexity-research Fn"]:::functions
            PortfolioData["portfolio-tab-data Fn"]:::functions
            StockDetailFn["stock-detail Fn"]:::functions
            ChatNotif["create-chat-notification Fn"]:::functions
            FriendReq["create-friend-request-notification Fn"]:::functions
            AcceptedReq["create-accepted-request-notification Fn"]:::functions
            SharedUtils["Shared Fn Utilities"]:::functions
        end
        subgraph "External APIs"
            Perplexity["Perplexity AI"]:::external
            LinkPreview["LinkPreview"]:::external
            Alpaca["Alpaca API"]:::external
            AlphaV["Alpha Vantage"]:::external
        end
    end

    %% Data Flows
    AuthScreen -->|"login/token"| AuthDB
    TabsNav -->|"CRUD & Realtime"| AuthDB
    ChatRouting -->|"CRUD & Realtime"| AuthDB
    ChatRouting -->|"calls"| PChat
    ArticlePages -->|"calls"| PNews
    StockResearch -->|"calls"| PResearch
    StockResearch -->|"calls"| StockDetailFn
    UserProfile -->|"CRUD"| AuthDB

    AuthDB -->|"Realtime updates"| ChatRouting
    AuthDB -->|"Realtime updates"| TabsNav

    AuthScreen -->|"data-fetch"| SupabaseLib
    TabsNav -->|"data-fetch"| SupabaseLib
    ChatRouting -->|"data-fetch"| SupabaseLib
    ArticlePages -->|"data-fetch"| SupabaseLib

    SupabaseLib -->|"uses"| ProfileUtils
    AuthCtx -->|"provides"| AuthScreen
    NavFocusCtx -->|"provides"| TabsNav
    ThemeCtx -->|"provides"| TabsNav

    %% Edge Functions flows
    PNews -->|"HTTP"| Perplexity
    PNews -->|"writes"| AuthDB
    DailyNews -->|"cron trigger"| PNews
    PChat -->|"HTTP"| Perplexity
    PChat -->|"writes"| AuthDB
    PResearch -->|"HTTP"| Perplexity
    PResearch -->|"writes"| AuthDB
    PortfolioData -->|"HTTP"| AlphaV
    PortfolioData -->|"writes"| AuthDB
    StockDetailFn -->|"HTTP"| Alpaca
    StockDetailFn -->|"writes"| AuthDB
    ChatNotif -->|"writes"| AuthDB
    FriendReq -->|"writes"| AuthDB
    AcceptedReq -->|"writes"| AuthDB

    %% Click Events
    click AuthScreen "https://github.com/adamblackman/briefo-public/blob/main/app/auth.tsx"
    click TabsNav "https://github.com/adamblackman/briefo-public/blob/main/app/(tabs)/_layout.tsx"
    click ChatRouting "https://github.com/adamblackman/briefo-public/blob/main/app/(chat)/_layout.tsx"
    click ArticlePages "https://github.com/adamblackman/briefo-public/blob/main/app/article/[id].tsx"
    click StockResearch "https://github.com/adamblackman/briefo-public/blob/main/app/stock-research.tsx"
    click UserProfile "https://github.com/adamblackman/briefo-public/blob/main/app/user/[id].tsx"
    click AuthCtx "https://github.com/adamblackman/briefo-public/blob/main/context/AuthContext.tsx"
    click NavFocusCtx "https://github.com/adamblackman/briefo-public/blob/main/context/NavigationFocusContext.tsx"
    click ThemeCtx "https://github.com/adamblackman/briefo-public/blob/main/context/ThemeContext.tsx"
    click UseFramework "https://github.com/adamblackman/briefo-public/blob/main/hooks/useFrameworkReady.ts"
    click SupabaseLib "https://github.com/adamblackman/briefo-public/blob/main/lib/supabase.ts"
    click ProfileUtils "https://github.com/adamblackman/briefo-public/blob/main/lib/profileUtils.ts"
    click PNews "https://github.com/adamblackman/briefo-public/blob/main/supabase/functions/perplexity-news/index.ts"
    click DailyNews "https://github.com/adamblackman/briefo-public/blob/main/supabase/functions/daily-news-suggestions/index.ts"
    click PChat "https://github.com/adamblackman/briefo-public/blob/main/supabase/functions/perplexity-chat/index.ts"
    click PResearch "https://github.com/adamblackman/briefo-public/blob/main/supabase/functions/perplexity-research/index.ts"
    click PortfolioData "https://github.com/adamblackman/briefo-public/blob/main/supabase/functions/portfolio-tab-data/index.ts"
    click StockDetailFn "https://github.com/adamblackman/briefo-public/blob/main/supabase/functions/stock-detail/index.ts"
    click ChatNotif "https://github.com/adamblackman/briefo-public/blob/main/supabase/functions/create-chat-notification/index.ts"
    click FriendReq "https://github.com/adamblackman/briefo-public/blob/main/supabase/functions/create-friend-request-notification/index.ts"
    click AcceptedReq "https://github.com/adamblackman/briefo-public/blob/main/supabase/functions/create-accepted-request-notification/index.ts"
    click SharedUtils "https://github.com/adamblackman/briefo-public/tree/main/supabase/functions/_shared/"

    %% Styles
    classDef frontend fill:#e0f7fa,stroke:#00838f,color:#006064
    classDef backend fill:#c8e6c9,stroke:#2e7d32,color:#1b5e20
    classDef functions fill:#ffe0b2,stroke:#ef6c00,color:#e65100
    classDef external fill:#e1bee7,stroke:#6a1b9a,color:#4a148c
```
