How cp-20/traqing works
<explanation>
Below is a step‑by‑step guide on how to draft a detailed, accurate system design diagram for the traQing project. This is a full‑stack, monorepo‑style web application that integrates with an external chat API (traQ), and uses a relational database with migration scripts. Follow these guidelines to capture all essential components, relationships, and technology choices.
1. Identify the main system components
- Frontend (apps/client)
- Reverse proxy / static asset server (Caddy)
- Backend API server (apps/server)
- Shared database library (packages/database)
- Database (PostgreSQL)
- External traQ API (OAuth & message feed)
- Migration subsystem (drizzle folder)
- Orchestration layer (docker-compose)
2. Determine relationships & data flows
- Browser → HTTP(S) → Caddy
• Serves index.html and static JS/CSS from apps/client build
• Proxies /api/* to Backend API server
- Backend API server ↔ Database
• Queries & writes via Drizzle ORM (packages/database)
- Backend API server ↔ External traQ API
• OAuth handshake (TRAQ_AUTH_CLIENT_ID)
• Bot token pulls historical messages & stamps (TRAQ_TOKEN)
• extractor.ts component runs background jobs to sync data
- Migration subsystem applies SQL migrations to PostgreSQL on startup
- docker‑compose wires up containers: caddy, client, server, postgres
3. Highlight architectural layers & patterns
- Monorepo with Yarn/Bun workspaces
- Client: React + Vite + TypeScript + Tailwind CSS
- API server: Node.js + TypeScript, tsup build, functional layering
• gateway.ts for HTTP routes
• auth.ts for OAuth
• extractor.ts for background sync jobs
• cache.ts for in‑memory caching
- Database access layer extracted into a separate package (packages/database)
- Migration driven by Drizzle (zero‑down‑time SQL migrations)
4. Technologies & frameworks
- Frontend: React, Vite, Tailwind, PostCSS
- Backend: Node.js, tsup, Express‑style gateway (or any HTTP framework you see in gateway.ts)
- DB client: Drizzle ORM, PostgreSQL
- Reverse proxy: Caddy
- Containerization: Docker, docker‑compose
- CI/CD: GitHub Actions (.github/workflows)
5. Diagramming guidelines
- Use clear, rectangular “containers” for each major component
- Group related files/modules inside each container (e.g. list “App.tsx, hooks/, components/” inside the Client box)
- Draw directional arrows:
• Browser → Caddy (GET /)
• Browser → Caddy (XHR /api/*) → Server
• Server → Database (SQL via Drizzle)
• Server → traQ API (OAuth & data fetch)
• extractor.ts → traQ API → writes to Database
• docker‑compose → spawns all containers
- Color‑code or shape‑code:
• Blue: Client/UI
• Green: Server/API
• Orange: Database & migrations
• Gray: Infrastructure (Caddy, Docker, CI)
• Purple dashed box: External services (traQ API)
6. Tailoring for a full‑stack application
- Emphasize separation of concerns: UI vs. API vs. Data
- Show static assets pipeline (Vite build → Docker image)
- Show background job runner (extractor) as part of the Server container or as a side‑car if you choose
- Include how environment variables (TRAQ_AUTH_CLIENT_ID, TRAQ_TOKEN, DATABASE_URL) flow into the Server container
7. Mandatory diagram elements
- Labels on every box (e.g. “React SPA”, “Caddy Reverse Proxy”, “Node API Server”, “PostgreSQL”, “traQ REST API”)
- Arrows with annotations (e.g. “OAuth2 token exchange”, “SQL queries”, “HTTP(S) /api/messages”)
- Legend for colors/shapes
- Optional: show GitHub Actions in the CI/CD layer triggering Docker builds and pushes
By following this outline, you’ll end up with a layered, color‑coded diagram that clearly shows how traQing’s frontend, backend, database, and external chat service interact, along with how the monorepo structure and CI/CD pipelines fit in. Focus on capturing each container, its responsibilities, and its integrations without over‑splitting—this strikes the right balance between clarity and completeness.
</explanation>