How asynccnu/ccnubox-be works
1. This repository is a Go-based microservice backend for “华师匣子”. The production system is centered on a BFF plus a set of domain services, with shared protobuf contracts and common infra libraries under common/.
2. The main request entrypoint is bff/. It exposes the public HTTP API, applies auth and cross-cutting middleware, and fans out to backend services over gRPC. It also owns API shaping/aggregation for front-end needs, plus observability pieces like logging, tracing, metrics, and JWT/session handling.
3. The service-to-service contract layer is common/api/, which contains protobuf definitions and generated code for all service APIs (content, classService, classlist, grade, feed, library, user, proxy, ccnu, counter, etc.). This is the boundary that keeps service interfaces explicit and stable.
4. Most backend services follow the same layered pattern: conf/ioc for wiring and infrastructure clients, grpc/ for transport, service/ or biz/ for business logic, and repository/ or data/ for persistence. Dependency injection is generated with Wire in many services, and shared infra is consistently brought in through etcd, Redis, MySQL, Kafka, and OpenTelemetry hooks.
5. be-user is the identity/account boundary. It persists user data, caches login/session-related state in Redis, and depends on be-ccnu and be-counter to obtain CCNU login cookies and determine “core user” status.
6. be-ccnu encapsulates the university single-sign-on / cookie acquisition logic. Its crawler modules and proxy integration indicate it acts as the gateway to CCNU’s external authentication and campus systems, rather than serving front-end traffic directly.
7. be-classlist is the class-schedule domain hub. It manages class info and student-course data, with separate DB and cache repositories, transaction support, and Kafka-backed event handling. It also talks to be-user and be-proxy, which implies it needs authenticated user context and resilient access to external university endpoints.
8. be-class handles class-related utility features such as free classroom queries and course-selection upload/crawling workflows. It depends on be-classlist, be-user, and be-proxy, so it sits on top of scheduling data, identity, and outbound proxying.
9. be-grade is the grades/ranking service. It crawls undergrad/postgraduate grade sources, stores grade and rank data, and publishes updates into the wider ecosystem. It depends on be-feed, be-user, be-proxy, be-classlist, be-counter, and Redis/lock infrastructure, showing that grade retrieval is both user-scoped and event-driven.
10. be-feed is the notification/event distribution layer. It consumes and produces Kafka events, stores feed configuration and tokens, and integrates with JPush for mobile push delivery. It also has cron jobs, so it bridges scheduled tasks and asynchronous domain events into user-facing notifications.
11. be-content is the content/reference-data service. It provides calendar, department, banner, website, version, and info-summary data, backed by database/cache and Qiniu integration for file/media handling. It also has cron jobs for periodically maintained content.
12. be-library and be-elecprice are both crawler-heavy domain services. be-library manages seat/discussion-related data and uses user/proxy support; be-elecprice polls electricity pricing/state on a schedule, stores it in cache/DB, and can feed updates into the notification flow.
13. be-counter is a small supporting service that tracks whether a user is a core user. Its implementation is Redis-centric, which makes it a lightweight feature-flag/attribute service used by other domains rather than a primary business store.
14. be-proxy is shared infrastructure for outbound IP proxying. Several crawler-oriented services depend on it to avoid being blocked by external systems, so it is an enabling service for the data-ingestion side of the platform.
15. The repo also contains operational scaffolding: deployment/ for Docker/Kubernetes manifests and environment configs, .github/workflows/ for per-service CI/CD, and scripts/ for build, infra setup, and config synchronization. There is a newer-looking be-classlist_v2/ tree that reorganizes the classlist domain into clearer biz/usecase/repository/events boundaries, but the deployed system in deployment/ still targets the original service set.
Main entry points: bff BFF · be-user User · be-grade Grade · be-classlist Classlist
Components 18
Backend services
Domain services and the public BFF
- BFF · HTTP entrypoint that authenticates, shapes responses, and fans out to backend gRPC services
bff - User · User accounts, login/session state, and core-user resolution
be-user - CCNU · University SSO and cookie acquisition boundary for external campus systems
be-ccnu - Classlist · Class schedule and student-course domain with DB, cache, and event handling
be-classlist - Class · Free classroom and course-selection upload workflows built on schedule data
be-class - Grade · Grade and rank crawling, storage, and update propagation
be-grade - Feed · Event distribution and push delivery layer with Kafka and JPush
be-feed - Content · Calendar, department, banner, version, and website content APIs
be-content - Library · Library seat and discussion-room domain with outbound proxy support
be-library - Elecprice · Scheduled electricity-price polling and state storage with feed integration
be-elecprice - Counter · Redis-backed core-user tracking used by other services
be-counter - Proxy · Shared proxying service for outbound crawling and external-system access
be-proxy
Shared code
Protobuf contracts and reusable infrastructure libraries
- Contracts · Shared service interfaces and generated gRPC code for all boundaries
common/api - Biz infra · Common gRPC, infra, logging, OTel, proxy, and config helpers
common/bizpkg - Shared tools · Cross-cutting helpers such as cron, logger, limiter, identity, and nacos support
common/pkg
Ops & delivery
Deployment, CI, and build automation
- Deployment · Docker, Kubernetes, environment configs, and CI/CD wiring
deployment - Scripts · Build, infra setup, config sync, and dependency update scripts
scripts
Migration path
A newer classlist implementation with clearer internal boundaries
- Classlist v2 · Newer classlist layout with explicit biz/usecase/repository/events boundaries
be-classlist_v2
Connections 36
- BFF → Contracts: contracts · Uses shared protobuf/gRPC definitions for service calls
- BFF → User: auth · Validates sessions and user identity
- BFF → Class: class APIs · Serves classroom and course-selection features
- BFF → Classlist: schedule APIs · Reads class schedule and student-course data
- BFF → Grade: grade APIs · Exposes grade and rank views
- BFF → Feed: feed APIs · Surfaces notification and feed endpoints
- BFF → Content: content APIs · Serves calendar, department, and reference data
- BFF → Library: library APIs · Surfaces library seat and discussion features
- BFF → Elecprice: electricity APIs · Exposes electricity price/state queries
- BFF → Biz infra: runtime · Reuses shared middleware, client, and infra helpers
- User → CCNU: SSO · Relies on CCNU cookie acquisition for login flows
- User → Counter: core user · Checks whether a user is marked as core
- Classlist → User: identity · Needs authenticated user context
- Classlist → Proxy: outbound access · Uses proxying for external university systems
- Class → Classlist: schedule data · Builds classroom utilities on classlist information
- Class → User: user context · Needs user-scoped access and identity
- Class → Proxy: crawl proxy · Uses proxying for outbound crawling
- Grade → Feed: events · Publishes grade updates into the feed system
- Grade → User: user scope · Retrieves grade data in the context of a user
- Grade → Classlist: schedule link · Correlates grade flow with classlist data
- Grade → Proxy: crawl proxy · Uses proxying to reach external grade sources
- Grade → Counter: core user · Checks user attributes during grade workflows
- Feed → Contracts: events/contracts · Shares event and service contracts across the ecosystem
- Feed → User: token/user · Maintains per-user feed config and delivery tokens
- Content → Biz infra: infra · Uses shared DB/cache/OTel/config helpers
- Library → User: identity · Needs authenticated user context
- Library → Proxy: crawl proxy · Uses outbound proxying for external systems
- Elecprice → Feed: notifications · Can feed polling updates into the notification flow
- Elecprice → Proxy: crawl proxy · Uses proxying for scheduled polling
- Proxy → Biz infra: shared infra · Implements the outbound proxy foundation used by other services
- Classlist v2 → Classlist: evolution · Represents a refactored successor layout for the classlist domain
- Deployment → BFF: deploys · Contains runtime manifests and configs for the BFF
- Deployment → User: deploys · Contains runtime manifests and configs for the user service
- Deployment → Classlist: deploys · Contains runtime manifests and configs for the classlist service
- Deployment → Grade: deploys · Contains runtime manifests and configs for the grade service
- Scripts → Deployment: automation · Builds images, sets up infra, and syncs configs