# sentozenxi-cmd/file2linken architecture

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

- Interactive diagram: https://gitdiagram.com/sentozenxi-cmd/file2linken
- Repository: https://github.com/sentozenxi-cmd/file2linken

## Overview

1. **Repository shape**
   - This is a TypeScript monorepo managed with pnpm workspaces.
   - The code splits into a backend runtime (`artifacts/api-server`), a UI sandbox (`artifacts/mockup-sandbox`), and shared libraries under `lib/`.

2. **Primary product boundary**
   - The core user-facing flow is file-to-link sharing: upload a file, persist it on the server, generate a unique download link, and serve that link back to users.
   - The README describes this as a lightweight self-hostable file sharing tool.

3. **Backend runtime: `api-server`**
   - `artifacts/api-server` is the central execution service.
   - It exposes HTTP routes for `home`, `health`, `files`, and `broadcasts`, so the server is responsible for both the file-sharing API and additional broadcast-related functionality.

4. **File handling subsystem**
   - File storage and download behavior likely lives behind `routes/files.ts` and shared helpers in `lib/fileUtils.ts`.
   - `lib/videoCache.ts` suggests cached handling for media files, implying the server may optimize repeated access to generated or converted video assets.
   - The architectural boundary here is: client requests hit the server, and the server owns file persistence and retrieval.

5. **Persistence layer**
   - `lib/db` contains Drizzle schema definitions for `files` and `broadcasts`.
   - This indicates the application persists metadata in a database rather than using ephemeral in-memory state.
   - The DB layer is shared as a separate package, which helps keep schema definitions consistent across runtime and generated clients.

6. **Broadcast / streaming subsystem**
   - Several server-side libraries point to a second major pipeline: `telegramStream.ts`, `ffmpegStream.ts`, `gramjsClient.ts`, `sseClients.ts`, and the `bot/pushBot.ts` entrypoint.
   - This suggests the app can ingest or relay Telegram-based media, possibly convert it with FFmpeg, and push updates to connected clients over Server-Sent Events.
   - For an architecture diagram, this is a distinct subsystem from file upload/download and should be drawn with its own external dependency boundary.

7. **External services and protocols**
   - Telegram is a meaningful integration point: `gramjsClient.ts`, `telegram_session.txt`, and the bot code indicate Telegram API access.
   - FFmpeg is an execution dependency for stream/media conversion.
   - SSE is the server-to-client push mechanism used for real-time updates to listeners.

8. **API contract generation**
   - `lib/api-spec/openapi.yaml` is the source of the API contract.
   - `lib/api-zod` and `lib/api-client-react` are generated artifacts derived from that contract, providing shared validation/types and a React-oriented client.
   - This creates a contract-first boundary between backend and consumer code.

9. **UI and preview environment**
   - `artifacts/mockup-sandbox` is a separate frontend sandbox built with Vite/React.
   - It contains a large UI component library and preview tooling, but it appears to be a design/mockup environment rather than the production backend.
   - It likely consumes the shared API client rather than talking to storage directly.

10. **Operational and deployment context**
   - The repo includes Replit and Railway config files, plus build scripts and a post-merge script, which implies it is meant to be deployed in managed hosting environments.
   - The backend artifact layout suggests the server is packaged independently from the mockup sandbox.
   - In a diagram, show deployment/hosting as an outer layer around the server and any client preview environment.

11. **Most important data flows to diagram**
   - File upload flow: client/UI → API server → DB/file storage → generated download link → client sharing/download.
   - Broadcast flow: external Telegram/media source → Telegram/FFmpeg processing in the server → SSE push and/or bot notifications → connected clients.
   - Contract flow: OpenAPI schema → generated API types/client packages → consumers and server code staying aligned.

Main entry points: [`artifacts/api-server/src/app.ts`](https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/app.ts) (API Server), [`artifacts/api-server/src/routes/files.ts`](https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/routes/files.ts) (Files Route), [`artifacts/api-server/src/routes/broadcasts.ts`](https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/routes/broadcasts.ts) (Broadcasts Route), [`artifacts/api-server/src/lib/telegramStream.ts`](https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/lib/telegramStream.ts) (Telegram Stream)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime_api["API Server"]
  node_api_server["API Server<br/>runtime<br/>[app.ts]"]
  node_route_home["Home Route<br/>[home.ts]"]
  node_route_health["Health Route<br/>[health.ts]"]
  node_route_files["Files Route<br/>[files.ts]"]
  node_route_broadcasts["Broadcasts Route<br/>[broadcasts.ts]"]
  node_push_bot["Push Bot<br/>[pushBot.ts]"]
end

subgraph group_runtime_ui["Mockup Sandbox"]
  node_mockup_sandbox["Mockup Sandbox<br/>ui runtime<br/>[App.tsx]"]
end

subgraph group_shared_lib["Shared Libraries"]
  node_file_utils["File Utils<br/>storage helper<br/>[fileUtils.ts]"]
  node_video_cache["Video Cache<br/>media cache<br/>[videoCache.ts]"]
  node_telegram_stream["Telegram Stream<br/>ingest pipeline<br/>[telegramStream.ts]"]
  node_ffmpeg_stream["FFmpeg Stream<br/>transcode pipeline<br/>[ffmpegStream.ts]"]
  node_gramjs_client["GramJS Client<br/>telegram client<br/>[gramjsClient.ts]"]
  node_sse_clients["SSE Clients<br/>push channel<br/>[sseClients.ts]"]
  node_db_schema[("DB Schema<br/>[index.ts]")]
  node_api_spec["OpenAPI Spec<br/>contract<br/>[openapi.yaml]"]
  node_api_zod["Zod API<br/>generated types<br/>[index.ts]"]
  node_api_client["React Client<br/>generated client<br/>[index.ts]"]
end

subgraph group_external["External Dependencies"]
end

subgraph group_ops["Deployment"]
  node_hosting(("Replit/Railway<br/>hosting"))
end

node_api_server -->|"serves"| node_route_home
node_api_server -->|"serves"| node_route_health
node_api_server -->|"serves"| node_route_files
node_api_server -->|"serves"| node_route_broadcasts
node_route_files -->|"uses"| node_file_utils
node_route_files -->|"persists"| node_db_schema
node_route_files -->|"optimizes"| node_video_cache
node_route_broadcasts -->|"ingests"| node_telegram_stream
node_route_broadcasts -->|"transcodes"| node_ffmpeg_stream
node_route_broadcasts -->|"pushes"| node_sse_clients
node_push_bot -->|"connects"| node_gramjs_client
node_push_bot -->|"notifies"| node_sse_clients
node_telegram_stream -->|"reads from"| node_gramjs_client
node_telegram_stream -->|"feeds"| node_ffmpeg_stream
node_telegram_stream -->|"announces"| node_sse_clients
node_db_schema -->|"shared by"| node_api_server
node_api_spec -->|"generates"| node_api_zod
node_api_spec -->|"generates"| node_api_client
node_api_zod -->|"aligns"| node_api_server
node_api_client -->|"consumed by"| node_mockup_sandbox
node_api_server -->|"deployed on"| node_hosting
node_mockup_sandbox -->|"previewed on"| node_hosting

click node_api_server "https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/app.ts"
click node_route_home "https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/routes/home.ts"
click node_route_health "https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/routes/health.ts"
click node_route_files "https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/routes/files.ts"
click node_route_broadcasts "https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/routes/broadcasts.ts"
click node_file_utils "https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/lib/fileUtils.ts"
click node_video_cache "https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/lib/videoCache.ts"
click node_telegram_stream "https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/lib/telegramStream.ts"
click node_ffmpeg_stream "https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/lib/ffmpegStream.ts"
click node_gramjs_client "https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/lib/gramjsClient.ts"
click node_sse_clients "https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/lib/sseClients.ts"
click node_push_bot "https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/bot/pushBot.ts"
click node_db_schema "https://github.com/sentozenxi-cmd/file2linken/blob/main/lib/db/src/schema/index.ts"
click node_api_spec "https://github.com/sentozenxi-cmd/file2linken/blob/main/lib/api-spec/openapi.yaml"
click node_api_zod "https://github.com/sentozenxi-cmd/file2linken/blob/main/lib/api-zod/src/index.ts"
click node_api_client "https://github.com/sentozenxi-cmd/file2linken/blob/main/lib/api-client-react/src/index.ts"
click node_mockup_sandbox "https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/mockup-sandbox/src/App.tsx"

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_api_server,node_route_home,node_route_health,node_route_files,node_route_broadcasts,node_push_bot toneBlue
class node_mockup_sandbox toneAmber
class node_file_utils,node_video_cache,node_telegram_stream,node_ffmpeg_stream,node_gramjs_client,node_sse_clients,node_db_schema,node_api_spec,node_api_zod,node_api_client toneMint
class node_hosting toneIndigo
```

## Components

### API Server

Backend runtime and request handling

- [API Server](https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/app.ts): runtime · Central HTTP service for files and broadcasts · `artifacts/api-server/src/app.ts`
- [Home Route](https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/routes/home.ts): route · Landing page and entry response · `artifacts/api-server/src/routes/home.ts`
- [Health Route](https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/routes/health.ts): route · Liveness and status checks · `artifacts/api-server/src/routes/health.ts`
- [Files Route](https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/routes/files.ts): route · Upload, persist, and download files · `artifacts/api-server/src/routes/files.ts`
- [Broadcasts Route](https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/routes/broadcasts.ts): route · Broadcast and streaming endpoints · `artifacts/api-server/src/routes/broadcasts.ts`
- [Push Bot](https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/bot/pushBot.ts): bot · Bot entrypoint for push notifications · `artifacts/api-server/src/bot/pushBot.ts`

### Mockup Sandbox

Preview UI and component sandbox

- [Mockup Sandbox](https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/mockup-sandbox/src/App.tsx): ui runtime · Vite/React preview environment for UI components · `artifacts/mockup-sandbox/src/App.tsx`

### Shared Libraries

Contract, schema, and server helpers

- [File Utils](https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/lib/fileUtils.ts): storage helper · Shared file persistence and lookup helpers · `artifacts/api-server/src/lib/fileUtils.ts`
- [Video Cache](https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/lib/videoCache.ts): media cache · Cached handling for repeated media access · `artifacts/api-server/src/lib/videoCache.ts`
- [Telegram Stream](https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/lib/telegramStream.ts): ingest pipeline · Telegram media ingestion and relay · `artifacts/api-server/src/lib/telegramStream.ts`
- [FFmpeg Stream](https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/lib/ffmpegStream.ts): transcode pipeline · Media conversion and stream processing · `artifacts/api-server/src/lib/ffmpegStream.ts`
- [GramJS Client](https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/lib/gramjsClient.ts): telegram client · Telegram API/session access layer · `artifacts/api-server/src/lib/gramjsClient.ts`
- [SSE Clients](https://github.com/sentozenxi-cmd/file2linken/blob/main/artifacts/api-server/src/lib/sseClients.ts): push channel · Server-sent event connections and fanout · `artifacts/api-server/src/lib/sseClients.ts`
- [DB Schema](https://github.com/sentozenxi-cmd/file2linken/blob/main/lib/db/src/schema/index.ts): schema · Shared Drizzle tables for files and broadcasts · `lib/db/src/schema/index.ts`
- [OpenAPI Spec](https://github.com/sentozenxi-cmd/file2linken/blob/main/lib/api-spec/openapi.yaml): contract · Source API contract for server and clients · `lib/api-spec/openapi.yaml`
- [Zod API](https://github.com/sentozenxi-cmd/file2linken/blob/main/lib/api-zod/src/index.ts): generated types · Generated validation and shared types · `lib/api-zod/src/index.ts`
- [React Client](https://github.com/sentozenxi-cmd/file2linken/blob/main/lib/api-client-react/src/index.ts): generated client · Generated browser client for API consumers · `lib/api-client-react/src/index.ts`

### Deployment

Managed hosting and packaging

- **Replit/Railway**: hosting · Managed deployment and execution environment

## Connections

- API Server → Home Route: serves · Registers the home route
- API Server → Health Route: serves · Registers health checks
- API Server → Files Route: serves · Registers file upload/download endpoints
- API Server → Broadcasts Route: serves · Registers broadcast endpoints
- Files Route → File Utils: uses · Delegates file persistence and retrieval
- Files Route → DB Schema: persists · Stores file metadata in the database
- Files Route → Video Cache: optimizes · Reuses cached media assets when available
- Broadcasts Route → Telegram Stream: ingests · Pulls media and updates from Telegram
- Broadcasts Route → FFmpeg Stream: transcodes · Processes media through FFmpeg
- Broadcasts Route → SSE Clients: pushes · Streams updates to connected clients
- Push Bot → GramJS Client: connects · Uses Telegram API/session access
- Push Bot → SSE Clients: notifies · Broadcasts bot-driven updates
- Telegram Stream → GramJS Client: reads from · Consumes Telegram media and events
- Telegram Stream → FFmpeg Stream: feeds · Hands media to conversion pipeline
- Telegram Stream → SSE Clients: announces · Publishes stream state changes
- DB Schema → API Server: shared by · Schema used by server runtime
- OpenAPI Spec → Zod API: generates · Contract generates shared validators
- OpenAPI Spec → React Client: generates · Contract generates React client
- Zod API → API Server: aligns · Keeps server payloads consistent
- React Client → Mockup Sandbox: consumed by · UI sandbox uses the generated client
- API Server → Replit/Railway: deployed on · Packaged and run in managed hosting
- Mockup Sandbox → Replit/Railway: previewed on · Sandbox runs in hosted preview environments
