How sentozenxi-cmd/file2linken works
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: app.ts API Server · files.ts Files Route · broadcasts.ts Broadcasts Route · telegramStream.ts Telegram Stream
Components 18
API Server
Backend runtime and request handling
- API Server · Central HTTP service for files and broadcasts
artifacts/api-server/src/app.ts - Home Route · Landing page and entry response
artifacts/api-server/src/routes/home.ts - Health Route · Liveness and status checks
artifacts/api-server/src/routes/health.ts - Files Route · Upload, persist, and download files
artifacts/api-server/src/routes/files.ts - Broadcasts Route · Broadcast and streaming endpoints
artifacts/api-server/src/routes/broadcasts.ts - Push Bot · Bot entrypoint for push notifications
artifacts/api-server/src/bot/pushBot.ts
Mockup Sandbox
Preview UI and component sandbox
- Mockup Sandbox · Vite/React preview environment for UI components
artifacts/mockup-sandbox/src/App.tsx
Shared Libraries
Contract, schema, and server helpers
- File Utils · Shared file persistence and lookup helpers
artifacts/api-server/src/lib/fileUtils.ts - Video Cache · Cached handling for repeated media access
artifacts/api-server/src/lib/videoCache.ts - Telegram Stream · Telegram media ingestion and relay
artifacts/api-server/src/lib/telegramStream.ts - FFmpeg Stream · Media conversion and stream processing
artifacts/api-server/src/lib/ffmpegStream.ts - GramJS Client · Telegram API/session access layer
artifacts/api-server/src/lib/gramjsClient.ts - SSE Clients · Server-sent event connections and fanout
artifacts/api-server/src/lib/sseClients.ts - DB Schema · Shared Drizzle tables for files and broadcasts
lib/db/src/schema/index.ts - OpenAPI Spec · Source API contract for server and clients
lib/api-spec/openapi.yaml - Zod API · Generated validation and shared types
lib/api-zod/src/index.ts - React Client · Generated browser client for API consumers
lib/api-client-react/src/index.ts
Deployment
Managed hosting and packaging
- Replit/Railway · Managed deployment and execution environment
Connections 22
- 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