How muchen31415926/line-file-assistant works
1. This repository is a Firebase-backed LINE bot/application. The top-level firebase.json, .firebaserc, public/404.html, and the functions/ directory indicate a Firebase Hosting + Cloud Functions deployment, with the real application logic living in serverless functions.
2. The main runtime boundary is functions/src/index.js, which appears to bootstrap the function entrypoints. From there, the app is split into two major concerns: LINE message/command handling and a file-processing assistant pipeline.
3. Incoming requests are routed through functions/src/routes/. routes/index.js likely wires the HTTP endpoints, while routes/line_file_assistant.js is a dedicated route for the file-assistant flow. The route layer is thin and delegates to controllers/services.
4. The controller layer is in functions/src/controllers/line_cotroller.js and acts as the orchestration point between transport-level requests and domain services. It likely translates LINE webhook events into internal actions and selects the right command or file workflow.
5. Text command handling is separated into functions/src/commands/. A dispatcher fans out to handlers in commands/handlers/ such as help, find, and match. This is a clear domain boundary for user intent parsing: simple commands are handled directly, while more complex file-related interactions are routed elsewhere.
6. The file-oriented domain is centered on functions/src/services/line_file_service.js and especially functions/src/services/line_file_pipeline/. That pipeline is decomposed into ordered steps, suggesting a staged workflow for processing an uploaded LINE file message.
7. The pipeline steps show the end-to-end data flow for files: extract message buffer, detect file type, compute file size, create a filename and storage path, build a file reference, upload the file, make it public, generate a public URL, derive an embedding, and finally save metadata in the database. This indicates the system is doing both file storage and AI/vector-style indexing.
8. External integration boundaries matter here. functions/src/lib/client.js and functions/src/config/ likely centralize clients and credentials for LINE, storage, and database services. The presence of functions/sql/supabase_rpc.sql and functions/sql/line_file.sql strongly suggests Supabase is the persistence/query layer, including RPC support for file lookup or similarity/search functions.
9. The “AI” aspect is likely implemented through embeddings rather than a full chat model orchestration. The pipeline step get_embedding.js implies uploaded content is transformed into vector data for later retrieval, and the find/match command handlers likely expose that search capability to users.
10. Response rendering is isolated in functions/src/templates/. Builders such as build_help_menu.js, build_file_bubble.js, and build_file_carousel.js suggest LINE rich-message templates are generated centrally, keeping presentation separate from the business logic.
11. In terms of data flow, the two dominant paths are:
- command path: LINE event → dispatcher → command handler → template response
- file path: LINE file message → controller/service → pipeline steps → storage + Supabase metadata + embedding → searchable file records
These are the key arrows to show in an architecture diagram.
12. Overall, the repo is structured as a serverless LINE integration with clear layers: transport/routes, controller/orchestration, command handlers, a multi-step file ingestion pipeline, and persistence/search via Supabase. The important boundaries are between webhook handling, file processing, and database-backed retrieval.
Main entry points: templates/index.js Templates · client.js Clients · steps/index.js Steps · handlers/index.js Command handlers
Components 29
Firebase Deploy
Hosting and Cloud Functions deployment boundary
Functions App
Serverless LINE application runtime
- Entry · Cloud Functions entrypoint
functions/src/index.js - Routes · Wires request endpoints
functions/src/routes/index.js - File route · Dedicated file-assistant endpoint
functions/src/routes/line_file_assistant.js - LINE controller · Translates LINE events into internal actions
functions/src/controllers/line_cotroller.js - Dispatcher · Fans out text commands to handlers
functions/src/commands/dispatcher.js - Command handlers · Command entrypoint collection
functions/src/commands/handlers/index.js - Help · Builds help response
functions/src/commands/handlers/help.js - Find · Searches stored files
functions/src/commands/handlers/find.js - Match · Matches file or content records
functions/src/commands/handlers/match.js - Reply service · Sends LINE responses
functions/src/services/line_reply_service.js - File service · Coordinates file ingestion workflow
functions/src/services/line_file_service.js - Clients · Centralized external service clients
functions/src/lib/client.js - Config · Application configuration and credentials
functions/src/config/index.js - Templates · Central template exports
functions/src/templates/index.js - Help menu · Builds help bubble content
functions/src/templates/build_help_menu.js - File bubble · Builds file result card
functions/src/templates/build_file_bubble.js - File carousel · Builds multi-file result cards
functions/src/templates/build_file_carousel.js
File Pipeline
Staged ingestion and enrichment flow
- Pipeline · Runs ordered file-processing steps
functions/src/services/line_file_pipeline/index.js - Steps · Step registry for the ingestion pipeline
functions/src/services/line_file_pipeline/steps/index.js - Buffer · Reads the LINE message payload
functions/src/services/line_file_pipeline/steps/get_line_message_buffer.js - Type · Determines file type
functions/src/services/line_file_pipeline/steps/detect_file_type.js - Embedding · Creates vector representation
functions/src/services/line_file_pipeline/steps/get_embedding.js - Upload · Stores the file in remote storage
functions/src/services/line_file_pipeline/steps/upload_file.js - Save record · Persists file metadata and embedding
functions/src/services/line_file_pipeline/steps/save_in_db.js
Persistence
Supabase-backed database and SQL assets
- Supabase SQL · RPC and file-table SQL
functions/sql/supabase_rpc.sql - File SQL · File persistence/query definitions
functions/sql/line_file.sql
Connections 35
- Entry → Routes: mounts · Bootstraps HTTP routes and function entrypoints
- Routes → LINE controller: delegates · Routes webhook events into controller logic
- Routes → File route: mounts · Exposes file-assistant endpoint
- LINE controller → Dispatcher: dispatches · Sends text intents to command routing
- LINE controller → File service: orchestrates · Hands file events to ingestion workflow
- Dispatcher → Command handlers: fans out · Selects concrete command handler
- Command handlers → Help: includes · Help intent implementation
- Command handlers → Find: includes · Search intent implementation
- Command handlers → Match: includes · Match intent implementation
- Help → Templates: renders · Uses response template builders
- Find → Clients: queries · Searches through service clients
- Find → Templates: renders · Formats search results for LINE
- Match → Clients: queries · Looks up matching file records
- Match → Templates: renders · Formats match results for LINE
- File service → Pipeline: runs · Invokes staged file-processing pipeline
- Pipeline → Steps: uses · Executes registered processing steps
- Steps → Buffer: starts with · Extracts incoming file payload
- Steps → Type: includes · Classifies uploaded file
- Steps → Embedding: includes · Produces searchable embedding
- Steps → Upload: includes · Uploads binary to storage
- Steps → Save record: ends with · Persists metadata and vectors
- Buffer → Clients: reads · Uses integration client access
- Type → Config: uses · Relies on runtime settings
- Embedding → Clients: calls · Uses embedding or external service client
- Upload → Clients: stores via · Writes to storage backend
- Save record → Clients: persists via · Writes metadata to persistence layer
- Clients → Config: configured by · Loads service credentials and endpoints
- Save record → Supabase SQL: matches · Backed by Supabase RPC/schema
- Save record → File SQL: matches · Backed by file metadata queries
- File service → Templates: responds with · Builds file result messages
- Templates → Help menu: exports · Help UI builder
- Templates → File bubble: exports · Single-file result builder
- Templates → File carousel: exports · Multi-file result builder
- Entry → Firebase: deployed by · Deployment configuration boundary
- Entry → 404 page: serves · Hosting fallback asset