# muchen31415926/line-file-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/muchen31415926/line-file-assistant
- Repository: https://github.com/muchen31415926/line-file-assistant

## Overview

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: [`functions/src/templates/index.js`](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/templates/index.js) (Templates), [`functions/src/lib/client.js`](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/lib/client.js) (Clients), [`functions/src/services/line_file_pipeline/steps/index.js`](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_file_pipeline/steps/index.js) (Steps), [`functions/src/commands/handlers/index.js`](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/commands/handlers/index.js) (Command handlers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_firebase["Firebase Deploy"]
  node_firebase_json["Firebase<br/>deploy config<br/>[firebase.json]"]
  node_firebaserc["Project<br/>firebase config<br/>[.firebaserc]"]
  node_public_404["404 page<br/>hosting asset<br/>[404.html]"]
end

subgraph group_app["Functions App"]
  node_functions_index["Entry<br/>functions bootstrap<br/>[index.js]"]
  node_routes_index["Routes<br/>http routing<br/>[index.js]"]
  node_line_file_assistant_route["File route<br/>assistant route"]
  node_line_controller["LINE controller<br/>orchestrator<br/>[line_cotroller.js]"]
  node_command_dispatcher["Dispatcher<br/>command router<br/>[dispatcher.js]"]
  node_command_handlers["Command handlers<br/>intent handlers<br/>[index.js]"]
  node_help_handler["Help<br/>command handler<br/>[help.js]"]
  node_find_handler["Find<br/>command handler<br/>[find.js]"]
  node_match_handler["Match<br/>command handler<br/>[match.js]"]
  node_reply_service["Reply service<br/>message reply"]
  node_file_service["File service<br/>file orchestration"]
  node_client_lib["Clients<br/>[client.js]"]
  node_config_index["Config<br/>[index.js]"]
  node_templates_index["Templates<br/>[index.js]"]
  node_help_menu["Help menu<br/>template builder<br/>[build_help_menu.js]"]
  node_file_bubble["File bubble<br/>template builder"]
  node_file_carousel["File carousel<br/>template builder"]
end

subgraph group_pipeline["File Pipeline"]
  node_pipeline_index["Pipeline<br/>staged workflow<br/>[index.js]"]
  node_pipeline_steps["Steps<br/>[index.js]"]
  node_get_message_buffer["Buffer<br/>extract step"]
  node_detect_type["Type<br/>classify step"]
  node_get_embedding["Embedding<br/>enrich step<br/>[get_embedding.js]"]
  node_upload_file["Upload<br/>storage step<br/>[upload_file.js]"]
  node_save_db["Save record<br/>db step<br/>[save_in_db.js]"]
end

subgraph group_storage["Persistence"]
  node_supabase_sql["Supabase SQL<br/>database schema<br/>[supabase_rpc.sql]"]
  node_line_file_sql["File SQL<br/>database schema<br/>[line_file.sql]"]
end

node_functions_index -->|"mounts"| node_routes_index
node_routes_index -->|"delegates"| node_line_controller
node_routes_index -->|"mounts"| node_line_file_assistant_route
node_line_controller -->|"dispatches"| node_command_dispatcher
node_line_controller -->|"orchestrates"| node_file_service
node_command_dispatcher -->|"fans out"| node_command_handlers
node_command_handlers -->|"includes"| node_help_handler
node_command_handlers -->|"includes"| node_find_handler
node_command_handlers -->|"includes"| node_match_handler
node_help_handler -->|"renders"| node_templates_index
node_find_handler -->|"queries"| node_client_lib
node_find_handler -->|"renders"| node_templates_index
node_match_handler -->|"queries"| node_client_lib
node_match_handler -->|"renders"| node_templates_index
node_file_service -->|"runs"| node_pipeline_index
node_pipeline_index -->|"uses"| node_pipeline_steps
node_pipeline_steps -->|"starts with"| node_get_message_buffer
node_pipeline_steps -->|"includes"| node_detect_type
node_pipeline_steps -->|"includes"| node_get_embedding
node_pipeline_steps -->|"includes"| node_upload_file
node_pipeline_steps -->|"ends with"| node_save_db
node_get_message_buffer -->|"reads"| node_client_lib
node_detect_type -->|"uses"| node_config_index
node_get_embedding -->|"calls"| node_client_lib
node_upload_file -->|"stores via"| node_client_lib
node_save_db -->|"persists via"| node_client_lib
node_client_lib -->|"configured by"| node_config_index
node_save_db -.->|"matches"| node_supabase_sql
node_save_db -.->|"matches"| node_line_file_sql
node_file_service -->|"responds with"| node_templates_index
node_templates_index -->|"exports"| node_help_menu
node_templates_index -->|"exports"| node_file_bubble
node_templates_index -->|"exports"| node_file_carousel
node_functions_index -.->|"deployed by"| node_firebase_json
node_functions_index -.->|"serves"| node_public_404

click node_firebase_json "https://github.com/muchen31415926/line-file-assistant/blob/main/firebase.json"
click node_firebaserc "https://github.com/muchen31415926/line-file-assistant/blob/main/.firebaserc"
click node_public_404 "https://github.com/muchen31415926/line-file-assistant/blob/main/public/404.html"
click node_functions_index "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/index.js"
click node_routes_index "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/routes/index.js"
click node_line_file_assistant_route "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/routes/line_file_assistant.js"
click node_line_controller "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/controllers/line_cotroller.js"
click node_command_dispatcher "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/commands/dispatcher.js"
click node_command_handlers "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/commands/handlers/index.js"
click node_help_handler "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/commands/handlers/help.js"
click node_find_handler "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/commands/handlers/find.js"
click node_match_handler "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/commands/handlers/match.js"
click node_reply_service "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_reply_service.js"
click node_file_service "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_file_service.js"
click node_pipeline_index "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_file_pipeline/index.js"
click node_pipeline_steps "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_file_pipeline/steps/index.js"
click node_get_message_buffer "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_file_pipeline/steps/get_line_message_buffer.js"
click node_detect_type "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_file_pipeline/steps/detect_file_type.js"
click node_get_embedding "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_file_pipeline/steps/get_embedding.js"
click node_upload_file "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_file_pipeline/steps/upload_file.js"
click node_save_db "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_file_pipeline/steps/save_in_db.js"
click node_client_lib "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/lib/client.js"
click node_config_index "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/config/index.js"
click node_supabase_sql "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/sql/supabase_rpc.sql"
click node_line_file_sql "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/sql/line_file.sql"
click node_templates_index "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/templates/index.js"
click node_help_menu "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/templates/build_help_menu.js"
click node_file_bubble "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/templates/build_file_bubble.js"
click node_file_carousel "https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/templates/build_file_carousel.js"

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_firebase_json,node_firebaserc,node_public_404 toneBlue
class node_functions_index,node_routes_index,node_line_file_assistant_route,node_line_controller,node_command_dispatcher,node_command_handlers,node_help_handler,node_find_handler,node_match_handler,node_reply_service,node_file_service,node_client_lib,node_config_index,node_templates_index,node_help_menu,node_file_bubble,node_file_carousel toneAmber
class node_pipeline_index,node_pipeline_steps,node_get_message_buffer,node_detect_type,node_get_embedding,node_upload_file,node_save_db toneMint
class node_supabase_sql,node_line_file_sql toneRose
```

## Components

### Firebase Deploy

Hosting and Cloud Functions deployment boundary

- [Firebase](https://github.com/muchen31415926/line-file-assistant/blob/main/firebase.json): deploy config · Firebase Hosting/Functions deployment settings · `firebase.json`
- [Project](https://github.com/muchen31415926/line-file-assistant/blob/main/.firebaserc): firebase config · Firebase project alias/configuration · `.firebaserc`
- [404 page](https://github.com/muchen31415926/line-file-assistant/blob/main/public/404.html): hosting asset · Fallback hosted page · `public/404.html`

### Functions App

Serverless LINE application runtime

- [Entry](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/index.js): functions bootstrap · Cloud Functions entrypoint · `functions/src/index.js`
- [Routes](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/routes/index.js): http routing · Wires request endpoints · `functions/src/routes/index.js`
- [File route](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/routes/line_file_assistant.js): assistant route · Dedicated file-assistant endpoint · `functions/src/routes/line_file_assistant.js`
- [LINE controller](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/controllers/line_cotroller.js): orchestrator · Translates LINE events into internal actions · `functions/src/controllers/line_cotroller.js`
- [Dispatcher](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/commands/dispatcher.js): command router · Fans out text commands to handlers · `functions/src/commands/dispatcher.js`
- [Command handlers](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/commands/handlers/index.js): intent handlers · Command entrypoint collection · `functions/src/commands/handlers/index.js`
- [Help](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/commands/handlers/help.js): command handler · Builds help response · `functions/src/commands/handlers/help.js`
- [Find](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/commands/handlers/find.js): command handler · Searches stored files · `functions/src/commands/handlers/find.js`
- [Match](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/commands/handlers/match.js): command handler · Matches file or content records · `functions/src/commands/handlers/match.js`
- [Reply service](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_reply_service.js): message reply · Sends LINE responses · `functions/src/services/line_reply_service.js`
- [File service](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_file_service.js): file orchestration · Coordinates file ingestion workflow · `functions/src/services/line_file_service.js`
- [Clients](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/lib/client.js): integration clients · Centralized external service clients · `functions/src/lib/client.js`
- [Config](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/config/index.js): runtime config · Application configuration and credentials · `functions/src/config/index.js`
- [Templates](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/templates/index.js): response templates · Central template exports · `functions/src/templates/index.js`
- [Help menu](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/templates/build_help_menu.js): template builder · Builds help bubble content · `functions/src/templates/build_help_menu.js`
- [File bubble](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/templates/build_file_bubble.js): template builder · Builds file result card · `functions/src/templates/build_file_bubble.js`
- [File carousel](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/templates/build_file_carousel.js): template builder · Builds multi-file result cards · `functions/src/templates/build_file_carousel.js`

### File Pipeline

Staged ingestion and enrichment flow

- [Pipeline](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_file_pipeline/index.js): staged workflow · Runs ordered file-processing steps · `functions/src/services/line_file_pipeline/index.js`
- [Steps](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_file_pipeline/steps/index.js): pipeline steps · Step registry for the ingestion pipeline · `functions/src/services/line_file_pipeline/steps/index.js`
- [Buffer](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_file_pipeline/steps/get_line_message_buffer.js): extract step · Reads the LINE message payload · `functions/src/services/line_file_pipeline/steps/get_line_message_buffer.js`
- [Type](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_file_pipeline/steps/detect_file_type.js): classify step · Determines file type · `functions/src/services/line_file_pipeline/steps/detect_file_type.js`
- [Embedding](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_file_pipeline/steps/get_embedding.js): enrich step · Creates vector representation · `functions/src/services/line_file_pipeline/steps/get_embedding.js`
- [Upload](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_file_pipeline/steps/upload_file.js): storage step · Stores the file in remote storage · `functions/src/services/line_file_pipeline/steps/upload_file.js`
- [Save record](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/src/services/line_file_pipeline/steps/save_in_db.js): db step · 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](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/sql/supabase_rpc.sql): database schema · RPC and file-table SQL · `functions/sql/supabase_rpc.sql`
- [File SQL](https://github.com/muchen31415926/line-file-assistant/blob/main/functions/sql/line_file.sql): database schema · File persistence/query definitions · `functions/sql/line_file.sql`

## Connections

- 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
