# atom2048/connect architecture

> Architecture diagram of the GitHub repository atom2048/connect, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/atom2048/connect
- Repository: https://github.com/atom2048/connect

## Overview

Connect is a social networking application: users authenticate, browse a feed, publish and interact with posts, and use profiles, friends, search, and notifications. Its primary client is a TypeScript web app backed by Firebase; separate Worker and API code provides AI, media, search, and notification capabilities. The graph includes documented product branches even where their implementation was not sampled. Edges are limited to relationships visible in excerpts, the SOURCE INDEX, or README; some subsystem internals remain unverified.

Main entry points: [`src/db.ts`](https://github.com/atom2048/connect/blob/master/src/db.ts) (Firestore data access), [`src/main.ts`](https://github.com/atom2048/connect/blob/master/src/main.ts) (App startup), [`src/pageModules/explore.ts`](https://github.com/atom2048/connect/blob/master/src/pageModules/explore.ts) (Explore and search), [`worker/ai/handler.ts`](https://github.com/atom2048/connect/blob/master/worker/ai/handler.ts) (AI request handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web application"]
  node_app["App startup<br/>[main.ts]"]
  node_auth_ui["Authentication pages<br/>[auth.ts]"]
  node_state["Client state<br/>[state.ts]"]
  node_components["Shared UI<br/>[components.ts]"]
end

subgraph group_social["Social features"]
  node_home["Home feed<br/>[home.ts]"]
  node_explore["Explore and search<br/>[explore.ts]"]
  node_friends["Friend management<br/>[friends.ts]"]
  node_profile["Profiles<br/>[profile.ts]"]
  node_moderation["Moderation UI<br/>[moderation.ts]"]
end

subgraph group_firebase["Firebase services"]
  node_auth["Authentication<br/>[auth.ts]"]
  node_data["Firestore data access<br/>[db.ts]"]
  node_firestore[("Cloud Firestore")]
  node_firebase_auth["Firebase Auth"]
end

subgraph group_services["Platform services"]
  node_search_api["Post search API<br/>[posts.js]"]
  node_news_api["News service<br/>[news.js]"]
  node_notifications["Notifications<br/>[notifications.js]"]
  node_push["Push delivery<br/>[push-dispatch.js]"]
  node_functions["Firebase functions<br/>[index.js]"]
  node_worker["Worker routes<br/>[index.ts]"]
  node_media["Media access<br/>[mediaAccess.ts]"]
  node_d1[("D1 database")]
end

subgraph group_ai["Ask AI"]
  node_ai_handler["AI request handler<br/>[handler.ts]"]
  node_ai_context["AI context builder<br/>[context.ts]"]
  node_ai_provider["AI provider client<br/>[openrouter.ts]"]
end

node_user(("User"))
node_ai_service["OpenRouter"]

node_user -->|"uses"| node_app
node_app -->|"routes to"| node_auth_ui
node_auth_ui -->|"calls"| node_auth
node_auth -->|"authenticates with"| node_firebase_auth
node_app -->|"initializes"| node_state
node_app -->|"routes to"| node_home
node_app -->|"routes to"| node_explore
node_home -->|"reads and writes"| node_data
node_explore -->|"queries"| node_data
node_friends -.->|"uses"| node_data
node_profile -.->|"uses"| node_data
node_moderation -.->|"uses"| node_data
node_home -->|"renders"| node_components
node_auth_ui -->|"renders"| node_components
node_data -->|"reads and writes"| node_firestore
node_explore -.->|"searches posts"| node_search_api
node_explore -.->|"searches news"| node_news_api
node_user -.->|"receives"| node_notifications
node_notifications -.->|"dispatches"| node_push
node_firestore -.->|"triggers"| node_functions
node_worker -->|"routes media to"| node_media
node_worker -->|"routes AI to"| node_ai_handler
node_ai_handler -->|"builds context with"| node_ai_context
node_ai_handler -->|"reads and writes"| node_d1
node_ai_context -->|"queries"| node_d1
node_ai_handler -.->|"generates with"| node_ai_provider
node_ai_provider -.->|"calls"| node_ai_service

click node_app "https://github.com/atom2048/connect/blob/master/src/main.ts"
click node_auth_ui "https://github.com/atom2048/connect/blob/master/src/pageModules/auth.ts"
click node_auth "https://github.com/atom2048/connect/blob/master/src/auth.ts"
click node_state "https://github.com/atom2048/connect/blob/master/src/state.ts"
click node_home "https://github.com/atom2048/connect/blob/master/src/pageModules/home.ts"
click node_explore "https://github.com/atom2048/connect/blob/master/src/pageModules/explore.ts"
click node_friends "https://github.com/atom2048/connect/blob/master/src/pageModules/friends.ts"
click node_profile "https://github.com/atom2048/connect/blob/master/src/pageModules/profile.ts"
click node_moderation "https://github.com/atom2048/connect/blob/master/src/pageModules/moderation.ts"
click node_components "https://github.com/atom2048/connect/blob/master/src/components.ts"
click node_data "https://github.com/atom2048/connect/blob/master/src/db.ts"
click node_search_api "https://github.com/atom2048/connect/blob/master/api/search/posts.js"
click node_news_api "https://github.com/atom2048/connect/blob/master/api/news.js"
click node_notifications "https://github.com/atom2048/connect/blob/master/api/notifications.js"
click node_push "https://github.com/atom2048/connect/blob/master/api/push-dispatch.js"
click node_functions "https://github.com/atom2048/connect/blob/master/functions/index.js"
click node_worker "https://github.com/atom2048/connect/blob/master/worker/index.ts"
click node_media "https://github.com/atom2048/connect/blob/master/worker/mediaAccess.ts"
click node_ai_handler "https://github.com/atom2048/connect/blob/master/worker/ai/handler.ts"
click node_ai_context "https://github.com/atom2048/connect/blob/master/worker/ai/context.ts"
click node_ai_provider "https://github.com/atom2048/connect/blob/master/worker/ai/openrouter.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_auth_ui,node_state,node_components,node_user toneBlue
class node_home,node_explore,node_friends,node_profile,node_moderation toneAmber
class node_auth,node_data,node_firestore,node_firebase_auth,node_ai_service toneMint
class node_search_api,node_news_api,node_notifications,node_push,node_functions,node_worker,node_media,node_d1 toneRose
class node_ai_handler,node_ai_context,node_ai_provider toneIndigo
```

## Components

### Web application

- [App startup](https://github.com/atom2048/connect/blob/master/src/main.ts): `src/main.ts`
- [Authentication pages](https://github.com/atom2048/connect/blob/master/src/pageModules/auth.ts): `src/pageModules/auth.ts`
- [Client state](https://github.com/atom2048/connect/blob/master/src/state.ts): `src/state.ts`
- [Shared UI](https://github.com/atom2048/connect/blob/master/src/components.ts): `src/components.ts`

### Social features

- [Home feed](https://github.com/atom2048/connect/blob/master/src/pageModules/home.ts): `src/pageModules/home.ts`
- [Explore and search](https://github.com/atom2048/connect/blob/master/src/pageModules/explore.ts): `src/pageModules/explore.ts`
- [Friend management](https://github.com/atom2048/connect/blob/master/src/pageModules/friends.ts): `src/pageModules/friends.ts`
- [Profiles](https://github.com/atom2048/connect/blob/master/src/pageModules/profile.ts): `src/pageModules/profile.ts`
- [Moderation UI](https://github.com/atom2048/connect/blob/master/src/pageModules/moderation.ts): `src/pageModules/moderation.ts`

### Firebase services

- [Authentication](https://github.com/atom2048/connect/blob/master/src/auth.ts): `src/auth.ts`
- [Firestore data access](https://github.com/atom2048/connect/blob/master/src/db.ts): `src/db.ts`
- **Cloud Firestore**
- **Firebase Auth**

### Platform services

- [Post search API](https://github.com/atom2048/connect/blob/master/api/search/posts.js): `api/search/posts.js`
- [News service](https://github.com/atom2048/connect/blob/master/api/news.js): `api/news.js`
- [Notifications](https://github.com/atom2048/connect/blob/master/api/notifications.js): `api/notifications.js`
- [Push delivery](https://github.com/atom2048/connect/blob/master/api/push-dispatch.js): `api/push-dispatch.js`
- [Firebase functions](https://github.com/atom2048/connect/blob/master/functions/index.js): `functions/index.js`
- [Worker routes](https://github.com/atom2048/connect/blob/master/worker/index.ts): `worker/index.ts`
- [Media access](https://github.com/atom2048/connect/blob/master/worker/mediaAccess.ts): `worker/mediaAccess.ts`
- **D1 database**

### Ask AI

- [AI request handler](https://github.com/atom2048/connect/blob/master/worker/ai/handler.ts): `worker/ai/handler.ts`
- [AI context builder](https://github.com/atom2048/connect/blob/master/worker/ai/context.ts): `worker/ai/context.ts`
- [AI provider client](https://github.com/atom2048/connect/blob/master/worker/ai/openrouter.ts): `worker/ai/openrouter.ts`

### Other components

- **User**
- **OpenRouter**

## Connections

- User → App startup: uses
- App startup → Authentication pages: routes to (evidence: `src/main.ts`)
- Authentication pages → Authentication: calls (evidence: `src/pageModules/auth.ts`)
- Authentication → Firebase Auth: authenticates with (evidence: `src/auth.ts`)
- App startup → Client state: initializes (evidence: `src/main.ts`)
- App startup → Home feed: routes to (evidence: `src/main.ts`)
- App startup → Explore and search: routes to (evidence: `src/main.ts`)
- Home feed → Firestore data access: reads and writes (evidence: `src/pageModules/home.ts`)
- Explore and search → Firestore data access: queries (evidence: `src/pageModules/explore.ts`)
- Friend management → Firestore data access: uses
- Profiles → Firestore data access: uses
- Moderation UI → Firestore data access: uses
- Home feed → Shared UI: renders (evidence: `src/pageModules/home.ts`)
- Authentication pages → Shared UI: renders (evidence: `src/pageModules/auth.ts`)
- Firestore data access → Cloud Firestore: reads and writes (evidence: `src/db.ts`)
- Explore and search → Post search API: searches posts
- Explore and search → News service: searches news
- User → Notifications: receives
- Notifications → Push delivery: dispatches
- Cloud Firestore → Firebase functions: triggers
- Worker routes → Media access: routes media to (evidence: `worker/index.ts`)
- Worker routes → AI request handler: routes AI to (evidence: `worker/index.ts`)
- AI request handler → AI context builder: builds context with (evidence: `worker/ai/handler.ts`)
- AI request handler → D1 database: reads and writes (evidence: `worker/ai/handler.ts`)
- AI context builder → D1 database: queries (evidence: `worker/ai/context.ts`)
- AI request handler → AI provider client: generates with
- AI provider client → OpenRouter: calls
