How yuhoulaiqiu/fe_proj works
1. This repo is a two-tier application: a React single-page frontend and a Go backend API. The frontend handles all user interaction and route navigation, while the backend owns authentication, business rules, persistence, and background jobs.
2. The frontend lives under src/ and is organized by screen and responsibility rather than by framework layers. src/pages contains the major user and admin pages, src/components contains shared layout and UI primitives, and src/services contains the HTTP client wrappers used by pages to talk to the backend.
3. Frontend navigation is split between public/user flows and admin flows. SiteLayout and AdminLayout provide the two main shells, while RequireAuth and RequireAdmin act as client-side route guards. This mirrors the product boundary between normal users and administrators.
4. The frontend service layer is deliberately separated into authApi.js, publicApi.js, and adminApi.js, with a shared http.js. This indicates three API surfaces: login/session management, public browsing and user actions, and privileged admin CRUD operations. Token-based session state is implied by the README and the login/current-user flow.
5. The backend entrypoint is server/cmd/community-help-hub-server/main.go. Configuration is centralized in server/internal/config, database bootstrap in server/internal/db, and the HTTP layer in server/internal/httpapi. This gives the backend a conventional Go service layout with clear package boundaries.
6. The core backend request handling is routed through server/internal/httpapi/router.go, which likely wires public routes, authenticated routes, and admin-only routes to handlers. The presence of router_test.go suggests the routing and access rules are important enough to be tested separately.
7. Business data and persistence are split into domain and store layers. server/internal/domain/entities.go defines the shared entity shapes, while server/internal/store/*.go groups persistence logic by feature: auth, activities, services, lost items, notifications, and related errors. This is the main separation between business concepts and MySQL access.
8. The database is MySQL, with schema defined in server/schema.mysql.sql and test data in server/seed_test_data.sql. That makes the system stateful and relational, with the backend responsible for reading/writing the operational entities and the seed file supporting local/test environments.
9. The main functional domains are:
- Activities: list/detail, publish/edit/delete, registration, attendance roster, CSV export, and status lifecycle.
- Services: browse for users, CRUD for admins.
- Lost-and-found: browse for users, full admin CRUD with soft delete.
- Notifications: reminders tied to activity registrations.
These map directly to the backend store modules and the corresponding frontend pages.
10. Background processing is handled in server/internal/jobs/jobs.go. The README indicates two important job responsibilities: maintaining activity state transitions over time and repairing/creating notification reminders such as 24-hour and 1-hour alerts. This means not all state changes are request-driven; some are time-driven.
11. Access control is role-based. The frontend blocks unauthenticated or non-admin users from protected views, but the backend must be the authoritative enforcement point because admin operations touch sensitive CRUD paths and user-specific actions like registration cancellation and roster access.
12. From an architecture-diagram perspective, the clearest main flows are:
- Browser → React pages/layouts → service modules → Go HTTP API → store layer → MySQL
- Browser → login/auth flow → token/session storage → authorized API calls
- Backend jobs → store layer → MySQL for reminder repair and lifecycle updates
- Admin browser paths → admin API subset → privileged CRUD on services and lost items
13. The repository also includes .trae/specs, which suggests feature planning/spec artifacts, but those are ancillary to runtime architecture. The production behavior is driven by the React client, the Go API server, MySQL storage, and the scheduled job subsystem.
Main entry points: App.jsx App shell · pages Public pages · router.go HTTP router · http.js HTTP client
Components 22
React frontend
Single-page app for public users and admins.
- Browser · User and admin entry point for the SPA.
- App shell · Top-level React app bootstrap and routing.
src/App.jsx - Site layout · Main shell for public and user-facing pages.
src/components/SiteLayout.jsx - Admin layout · Main shell for admin-facing pages.
src/components/AdminLayout.jsx - Auth guard · Blocks unauthenticated access to protected views.
src/components/RequireAuth.jsx - Admin guard · Blocks non-admin access to privileged views.
src/components/RequireAdmin.jsx - Public pages · Home, browse, details, login, and user center flows.
src/pages - Admin pages · Admin CRUD screens for services and lost items.
src/pages/admin - UI primitives · Reusable cards, alerts, pagination, and toast UI.
src/components/ui - Auth API · Login and current-user/session endpoints.
src/services/authApi.js - Public API · Public browsing and user-action API calls.
src/services/publicApi.js - Admin API · Admin CRUD and management API calls.
src/services/adminApi.js - HTTP client · Common request wrapper used by all service modules.
src/services/http.js
Go backend
HTTP API, domain, persistence, and jobs.
- Server main · Backend process startup and wiring.
server/cmd/community-help-hub-server/main.go - Config · Centralized backend configuration loading.
server/internal/config/config.go - DB bootstrap · Database connection and initialization.
server/internal/db/db.go - HTTP router · Routes public, authenticated, and admin handlers.
server/internal/httpapi/router.go - Domain entities · Shared entity definitions used across handlers and stores.
server/internal/domain/entities.go - Store layer · Feature-oriented persistence for auth, activities, services, lost items, and notifications.
server/internal/store - Background jobs · Time-driven activity state updates and reminder repair.
server/internal/jobs/jobs.go
Connections 24
- Browser → App shell: loads · The browser opens the SPA.
- App shell → Site layout: public shell · Public routes render inside the site layout.
- App shell → Admin layout: admin shell · Admin routes render inside the admin layout.
- App shell → Auth guard: protects · Protected user flows are wrapped by auth checks.
- App shell → Admin guard: protects · Admin flows are wrapped by admin checks.
- Site layout → Public pages: hosts · User-facing pages render within the site shell.
- Admin layout → Admin pages: hosts · Admin pages render within the admin shell.
- Public pages → UI primitives: uses · Pages reuse shared UI primitives.
- Admin pages → UI primitives: uses · Admin screens reuse shared UI primitives.
- Public pages → Public API: calls · Browse and user actions go through the public API client.
- Admin pages → Admin API: calls · Admin CRUD flows go through the admin API client.
- Public pages → Auth API: auth flow · Login and session checks use the auth client.
- Public API → HTTP client: shares transport · Public requests reuse the shared HTTP wrapper.
- Auth API → HTTP client: shares transport · Auth requests reuse the shared HTTP wrapper.
- Admin API → HTTP client: shares transport · Admin requests reuse the shared HTTP wrapper.
- Server main → Config: loads · Startup reads centralized configuration.
- Server main → DB bootstrap: initializes · Startup initializes the database layer.
- Server main → HTTP router: serves · The main process starts the HTTP router.
- HTTP router → Domain entities: uses · Handlers work with shared domain entities.
- HTTP router → Store layer: persists via · Request handlers delegate persistence to stores.
- Background jobs → Store layer: updates via · Background jobs repair and advance stored state.
- Schema → DB bootstrap: defines · Schema is the backing structure for the database.
- Seed data → Schema: populates · Seed data fills the relational schema.
- HTTP client → HTTP router: API calls · All frontend service requests reach the Go HTTP API.