# yuhoulaiqiu/fe_proj architecture

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

- Interactive diagram: https://gitdiagram.com/yuhoulaiqiu/fe_proj
- Repository: https://github.com/yuhoulaiqiu/fe_proj

## Overview

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: [`src/App.jsx`](https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/App.jsx) (App shell), [`src/pages`](https://github.com/yuhoulaiqiu/fe_proj/tree/main/src/pages) (Public pages), [`server/internal/httpapi/router.go`](https://github.com/yuhoulaiqiu/fe_proj/blob/main/server/internal/httpapi/router.go) (HTTP router), [`src/services/http.js`](https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/services/http.js) (HTTP client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React frontend"]
  node_browser(("Browser<br/>client"))
  node_app_shell["App shell<br/>react spa<br/>[App.jsx]"]
  node_site_layout["Site layout<br/>public shell<br/>[SiteLayout.jsx]"]
  node_admin_layout["Admin layout<br/>admin shell<br/>[AdminLayout.jsx]"]
  node_auth_guard["Auth guard<br/>route guard<br/>[RequireAuth.jsx]"]
  node_admin_guard["Admin guard<br/>route guard<br/>[RequireAdmin.jsx]"]
  node_public_pages["Public pages<br/>user screens"]
  node_admin_pages["Admin pages<br/>admin screens"]
  node_ui_components["UI primitives<br/>shared ui"]
  node_auth_api["Auth API<br/>session client<br/>[authApi.js]"]
  node_public_api["Public API<br/>browse client<br/>[publicApi.js]"]
  node_admin_api["Admin API<br/>privileged client<br/>[adminApi.js]"]
  node_http_client["HTTP client<br/>shared transport<br/>[http.js]"]
end

subgraph group_backend["Go backend"]
  node_server_main["Server main<br/>go entrypoint<br/>[main.go]"]
  node_config["Config<br/>settings<br/>[config.go]"]
  node_db_bootstrap["DB bootstrap<br/>mysql setup<br/>[db.go]"]
  node_router["HTTP router<br/>request routing<br/>[router.go]"]
  node_domain["Domain entities<br/>models<br/>[entities.go]"]
  node_stores["Store layer<br/>mysql repositories"]
  node_jobs["Background jobs<br/>scheduler<br/>[jobs.go]"]
end

subgraph group_data["Data layer"]
  node_schema[("Schema<br/>[schema.mysql.sql]")]
  node_seed_data[("Seed data<br/>mysql seed<br/>[seed_test_data.sql]")]
end

node_browser -->|"loads"| node_app_shell
node_app_shell -->|"public shell"| node_site_layout
node_app_shell -->|"admin shell"| node_admin_layout
node_app_shell -->|"protects"| node_auth_guard
node_app_shell -->|"protects"| node_admin_guard
node_site_layout -->|"hosts"| node_public_pages
node_admin_layout -->|"hosts"| node_admin_pages
node_public_pages -->|"uses"| node_ui_components
node_admin_pages -->|"uses"| node_ui_components
node_public_pages -->|"calls"| node_public_api
node_admin_pages -->|"calls"| node_admin_api
node_public_pages -->|"auth flow"| node_auth_api
node_public_api -->|"shares transport"| node_http_client
node_auth_api -->|"shares transport"| node_http_client
node_admin_api -->|"shares transport"| node_http_client
node_server_main -->|"loads"| node_config
node_server_main -->|"initializes"| node_db_bootstrap
node_server_main -->|"serves"| node_router
node_router -->|"uses"| node_domain
node_router -->|"persists via"| node_stores
node_jobs -->|"updates via"| node_stores
node_schema -->|"defines"| node_db_bootstrap
node_seed_data -->|"populates"| node_schema
node_http_client -->|"API calls"| node_router

click node_app_shell "https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/App.jsx"
click node_site_layout "https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/components/SiteLayout.jsx"
click node_admin_layout "https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/components/AdminLayout.jsx"
click node_auth_guard "https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/components/RequireAuth.jsx"
click node_admin_guard "https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/components/RequireAdmin.jsx"
click node_public_pages "https://github.com/yuhoulaiqiu/fe_proj/tree/main/src/pages"
click node_admin_pages "https://github.com/yuhoulaiqiu/fe_proj/tree/main/src/pages/admin"
click node_ui_components "https://github.com/yuhoulaiqiu/fe_proj/tree/main/src/components/ui"
click node_auth_api "https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/services/authApi.js"
click node_public_api "https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/services/publicApi.js"
click node_admin_api "https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/services/adminApi.js"
click node_http_client "https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/services/http.js"
click node_server_main "https://github.com/yuhoulaiqiu/fe_proj/blob/main/server/cmd/community-help-hub-server/main.go"
click node_config "https://github.com/yuhoulaiqiu/fe_proj/blob/main/server/internal/config/config.go"
click node_db_bootstrap "https://github.com/yuhoulaiqiu/fe_proj/blob/main/server/internal/db/db.go"
click node_router "https://github.com/yuhoulaiqiu/fe_proj/blob/main/server/internal/httpapi/router.go"
click node_domain "https://github.com/yuhoulaiqiu/fe_proj/blob/main/server/internal/domain/entities.go"
click node_stores "https://github.com/yuhoulaiqiu/fe_proj/tree/main/server/internal/store"
click node_jobs "https://github.com/yuhoulaiqiu/fe_proj/blob/main/server/internal/jobs/jobs.go"
click node_schema "https://github.com/yuhoulaiqiu/fe_proj/blob/main/server/schema.mysql.sql"
click node_seed_data "https://github.com/yuhoulaiqiu/fe_proj/blob/main/server/seed_test_data.sql"

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_browser,node_app_shell,node_site_layout,node_admin_layout,node_auth_guard,node_admin_guard,node_public_pages,node_admin_pages,node_ui_components,node_auth_api,node_public_api,node_admin_api,node_http_client toneBlue
class node_server_main,node_config,node_db_bootstrap,node_router,node_domain,node_stores,node_jobs toneAmber
class node_schema,node_seed_data toneMint
```

## Components

### React frontend

Single-page app for public users and admins.

- **Browser**: client · User and admin entry point for the SPA.
- [App shell](https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/App.jsx): react spa · Top-level React app bootstrap and routing. · `src/App.jsx`
- [Site layout](https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/components/SiteLayout.jsx): public shell · Main shell for public and user-facing pages. · `src/components/SiteLayout.jsx`
- [Admin layout](https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/components/AdminLayout.jsx): admin shell · Main shell for admin-facing pages. · `src/components/AdminLayout.jsx`
- [Auth guard](https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/components/RequireAuth.jsx): route guard · Blocks unauthenticated access to protected views. · `src/components/RequireAuth.jsx`
- [Admin guard](https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/components/RequireAdmin.jsx): route guard · Blocks non-admin access to privileged views. · `src/components/RequireAdmin.jsx`
- [Public pages](https://github.com/yuhoulaiqiu/fe_proj/tree/main/src/pages): user screens · Home, browse, details, login, and user center flows. · `src/pages`
- [Admin pages](https://github.com/yuhoulaiqiu/fe_proj/tree/main/src/pages/admin): admin screens · Admin CRUD screens for services and lost items. · `src/pages/admin`
- [UI primitives](https://github.com/yuhoulaiqiu/fe_proj/tree/main/src/components/ui): shared ui · Reusable cards, alerts, pagination, and toast UI. · `src/components/ui`
- [Auth API](https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/services/authApi.js): session client · Login and current-user/session endpoints. · `src/services/authApi.js`
- [Public API](https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/services/publicApi.js): browse client · Public browsing and user-action API calls. · `src/services/publicApi.js`
- [Admin API](https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/services/adminApi.js): privileged client · Admin CRUD and management API calls. · `src/services/adminApi.js`
- [HTTP client](https://github.com/yuhoulaiqiu/fe_proj/blob/main/src/services/http.js): shared transport · Common request wrapper used by all service modules. · `src/services/http.js`

### Go backend

HTTP API, domain, persistence, and jobs.

- [Server main](https://github.com/yuhoulaiqiu/fe_proj/blob/main/server/cmd/community-help-hub-server/main.go): go entrypoint · Backend process startup and wiring. · `server/cmd/community-help-hub-server/main.go`
- [Config](https://github.com/yuhoulaiqiu/fe_proj/blob/main/server/internal/config/config.go): settings · Centralized backend configuration loading. · `server/internal/config/config.go`
- [DB bootstrap](https://github.com/yuhoulaiqiu/fe_proj/blob/main/server/internal/db/db.go): mysql setup · Database connection and initialization. · `server/internal/db/db.go`
- [HTTP router](https://github.com/yuhoulaiqiu/fe_proj/blob/main/server/internal/httpapi/router.go): request routing · Routes public, authenticated, and admin handlers. · `server/internal/httpapi/router.go`
- [Domain entities](https://github.com/yuhoulaiqiu/fe_proj/blob/main/server/internal/domain/entities.go): models · Shared entity definitions used across handlers and stores. · `server/internal/domain/entities.go`
- [Store layer](https://github.com/yuhoulaiqiu/fe_proj/tree/main/server/internal/store): mysql repositories · Feature-oriented persistence for auth, activities, services, lost items, and notifications. · `server/internal/store`
- [Background jobs](https://github.com/yuhoulaiqiu/fe_proj/blob/main/server/internal/jobs/jobs.go): scheduler · Time-driven activity state updates and reminder repair. · `server/internal/jobs/jobs.go`

### Data layer

Database schema and seeded test data.

- [Schema](https://github.com/yuhoulaiqiu/fe_proj/blob/main/server/schema.mysql.sql): mysql schema · Operational database schema definition. · `server/schema.mysql.sql`
- [Seed data](https://github.com/yuhoulaiqiu/fe_proj/blob/main/server/seed_test_data.sql): mysql seed · Local and test dataset for the database. · `server/seed_test_data.sql`

## Connections

- 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.
