mirror of
https://github.com/d0zingcat/alert-message-center.git
synced 2026-05-13 23:16:48 +00:00
4.9 KiB
4.9 KiB
Project Context for GitHub Copilot
This document provides technical context, architectural decisions, and code conventions for the Alert Message Center project. It is intended to help AI assistants understand the codebase.
1. Project Overview
Alert Message Center (formerly Alert Manager) is a centralized alert dispatching system.
- Goal: Decouple alert sources from alert recipients.
- Mechanism: Alerts are sent to a Topic. Users subscribe to Topics. The system dispatches alerts to subscribers via Feishu (Lark) Private Messages.
- Runtime: Bun (JavaScript/TypeScript runtime).
2. Tech Stack
- Monorepo: Simple directory structure (
apps/server,apps/web). - Backend:
- Runtime: Bun.
- Framework: Hono (Web Standard based).
- Database: SQLite (via
better-sqlite3). - ORM: Drizzle ORM.
- Authentication: Feishu OAuth2 (Session-based with cookies).
- External API: Feishu Open Platform (Server-side API).
- Frontend:
- Build Tool: Vite.
- Framework: React.
- Styling: Tailwind CSS.
- Icons: Lucide React.
- Client:
hono/client(RPC-style type-safe client).
3. Data Model (Schema)
The database schema is defined in apps/server/src/db/schema.ts.
Entities
-
Topic (
topics)id: UUID (Primary Key)name: Display name (e.g., "Payment Service Errors").slug: URL-safe identifier (e.g.,payment-errors). Used in webhook URLs.description: Optional text.
-
User (
users)id: UUID (Primary Key).name: Display name.feishuUserId: The Feishuopen_id. Critical for sending messages.email: Contact info.isAdmin: Boolean flag for administrative privileges (create topics, view all users).
-
Subscription (
subscriptions)topicId: Foreign Key ->topics.id.userId: Foreign Key ->users.id.- Relationship: Many-to-Many between Topics and Users.
4. Key Workflows
Authentication
- Strategy: Feishu OAuth2.
- Flow:
- Frontend calls
/api/auth/login-urlto get Feishu auth URL. - User redirects to Feishu, approves, redirects back to
/api/auth/callback. - Server exchanges code for token, gets user info, creates/updates user in DB.
- Server sets
sessioncookie (httpOnly).
- Frontend calls
- Context:
AuthContext.tsxmanages user state on frontend.
Alert Ingestion & Dispatch
File: apps/server/src/webhook.ts
- Ingest:
POST /api/webhook/:slugreceives a JSON payload. - Lookup:
- Find
Topicbyslug. - Fetch all
subscriptionsfor this topic, including the associateduser.
- Find
- Dispatch:
- Iterate through subscribers.
- For each user, call
FeishuClient.sendMessage. - Payload: The
contentandmsg_typefrom the request body are passed directly to Feishu.
Subscription Management
- Users can subscribe/unsubscribe themselves to any topic.
- Admins can manage subscriptions for other users globally in
AdminView. - Topic Deletion: Centralized in the Admin Dashboard (All Topics Tab) to avoid accidental deletion from the main topic list.
- Button logic on frontend toggles between "Subscribe" and "Unsubscribe".
5. API Endpoints
Auth
GET /api/auth/login-urlGET /api/auth/callbackGET /api/auth/mePOST /api/auth/logout
Management
GET /api/topics: List all approved topics.GET /api/topics/my-requests: List user's own topic requests.GET /api/topics/requests: List pending topic requests (Admin only).GET /api/topics/all: List all topics regardless of status (Admin only).POST /api/topics: Create a topic (Admin creates approved, User creates pending).POST /api/topics/:id/approve: Approve a topic request (Admin only).POST /api/topics/:id/reject: Reject a topic request (Admin only).DELETE /api/topics/:id: Delete a topic (Admin only).POST /api/topics/:id/subscribe/:userId: Subscribe.DELETE /api/topics/:id/subscribe/:userId: Unsubscribe.GET /api/users: List users (Admin only).
Webhook
POST /api/webhook/:slug: Trigger an alert for a topic.
6. Future Roadmap (Planned)
- Message Preview: Preview Feishu card JSON in the UI.
- History/Logs: Keep a log of sent alerts for auditing.
- Retry Mechanism: Handle Feishu API failures.
- Deployment: Dockerfile and deployment scripts.
7. Development Conventions
- Imports: Use relative imports.
- Styling: Use Tailwind utility classes directly in JSX.
- Async/Await: Prefer
async/awaitover.then(). - Type Safety: strict TypeScript usage. Backend and Frontend share types via Hono RPC or shared interfaces.
- Environment Variables:
FEISHU_APP_ID,FEISHU_APP_SECRET,REDIRECT_URI,ADMIN_EMAILS.
- Administrators:
- Configured via the
ADMIN_EMAILSenvironment variable (comma-separated list of emails).
- Configured via the