# asynccnu/ccnubox-be architecture

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

- Interactive diagram: https://gitdiagram.com/asynccnu/ccnubox-be
- Repository: https://github.com/asynccnu/ccnubox-be

## Overview

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`](https://github.com/asynccnu/ccnubox-be/tree/main/bff) (BFF), [`be-user`](https://github.com/asynccnu/ccnubox-be/tree/main/be-user) (User), [`be-grade`](https://github.com/asynccnu/ccnubox-be/tree/main/be-grade) (Grade), [`be-classlist`](https://github.com/asynccnu/ccnubox-be/tree/main/be-classlist) (Classlist)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_services["Backend services"]
  node_bff["BFF<br/>public api gateway"]
  node_be_user["User<br/>identity service"]
  node_be_ccnu["CCNU<br/>sso crawler"]
  node_be_classlist["Classlist<br/>schedule hub"]
  node_be_class["Class"]
  node_be_grade["Grade"]
  node_be_feed["Feed<br/>notification bus"]
  node_be_content["Content<br/>reference data"]
  node_be_library["Library<br/>seat crawler"]
  node_be_elecprice["Elecprice<br/>polling service"]
  node_be_counter(("Counter<br/>user attribute"))
  node_be_proxy["Proxy"]
end

subgraph group_group_common["Shared code"]
  node_common_api["Contracts<br/>protobuf api layer"]
  node_common_bizpkg["Biz infra<br/>shared runtime libs"]
  node_common_pkg["Shared tools<br/>utility libraries"]
end

subgraph group_group_ops["Ops & delivery"]
  node_deployment["Deployment<br/>release manifests"]
  node_scripts["Scripts<br/>automation"]
end

subgraph group_group_migration["Migration path"]
  node_be_classlist_v2["Classlist v2<br/>refactored class domain"]
end

node_bff -->|"contracts"| node_common_api
node_bff -->|"auth"| node_be_user
node_bff -->|"class APIs"| node_be_class
node_bff -->|"schedule APIs"| node_be_classlist
node_bff -->|"grade APIs"| node_be_grade
node_bff -->|"feed APIs"| node_be_feed
node_bff -->|"content APIs"| node_be_content
node_bff -->|"library APIs"| node_be_library
node_bff -->|"electricity APIs"| node_be_elecprice
node_bff -->|"runtime"| node_common_bizpkg
node_be_user -->|"SSO"| node_be_ccnu
node_be_user -->|"core user"| node_be_counter
node_be_classlist -->|"identity"| node_be_user
node_be_classlist -->|"outbound access"| node_be_proxy
node_be_class -->|"schedule data"| node_be_classlist
node_be_class -->|"user context"| node_be_user
node_be_class -->|"crawl proxy"| node_be_proxy
node_be_grade -->|"events"| node_be_feed
node_be_grade -->|"user scope"| node_be_user
node_be_grade -->|"schedule link"| node_be_classlist
node_be_grade -->|"crawl proxy"| node_be_proxy
node_be_grade -->|"core user"| node_be_counter
node_be_feed -->|"events/contracts"| node_common_api
node_be_feed -->|"token/user"| node_be_user
node_be_content -->|"infra"| node_common_bizpkg
node_be_library -->|"identity"| node_be_user
node_be_library -->|"crawl proxy"| node_be_proxy
node_be_elecprice -->|"notifications"| node_be_feed
node_be_elecprice -->|"crawl proxy"| node_be_proxy
node_be_proxy -->|"shared infra"| node_common_bizpkg
node_be_classlist_v2 -.->|"evolution"| node_be_classlist
node_deployment -->|"deploys"| node_bff
node_deployment -->|"deploys"| node_be_user
node_deployment -->|"deploys"| node_be_classlist
node_deployment -->|"deploys"| node_be_grade
node_scripts -->|"automation"| node_deployment

click node_bff "https://github.com/asynccnu/ccnubox-be/tree/main/bff"
click node_be_user "https://github.com/asynccnu/ccnubox-be/tree/main/be-user"
click node_be_ccnu "https://github.com/asynccnu/ccnubox-be/tree/main/be-ccnu"
click node_be_classlist "https://github.com/asynccnu/ccnubox-be/tree/main/be-classlist"
click node_be_class "https://github.com/asynccnu/ccnubox-be/tree/main/be-class"
click node_be_grade "https://github.com/asynccnu/ccnubox-be/tree/main/be-grade"
click node_be_feed "https://github.com/asynccnu/ccnubox-be/tree/main/be-feed"
click node_be_content "https://github.com/asynccnu/ccnubox-be/tree/main/be-content"
click node_be_library "https://github.com/asynccnu/ccnubox-be/tree/main/be-library"
click node_be_elecprice "https://github.com/asynccnu/ccnubox-be/tree/main/be-elecprice"
click node_be_counter "https://github.com/asynccnu/ccnubox-be/tree/main/be-counter"
click node_be_proxy "https://github.com/asynccnu/ccnubox-be/tree/main/be-proxy"
click node_common_api "https://github.com/asynccnu/ccnubox-be/tree/main/common/api"
click node_common_bizpkg "https://github.com/asynccnu/ccnubox-be/tree/main/common/bizpkg"
click node_common_pkg "https://github.com/asynccnu/ccnubox-be/tree/main/common/pkg"
click node_deployment "https://github.com/asynccnu/ccnubox-be/tree/main/deployment"
click node_scripts "https://github.com/asynccnu/ccnubox-be/tree/main/scripts"
click node_be_classlist_v2 "https://github.com/asynccnu/ccnubox-be/tree/main/be-classlist_v2"

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_bff,node_be_user,node_be_ccnu,node_be_classlist,node_be_class,node_be_grade,node_be_feed,node_be_content,node_be_library,node_be_elecprice,node_be_counter,node_be_proxy toneBlue
class node_common_api,node_common_bizpkg,node_common_pkg toneAmber
class node_deployment,node_scripts toneMint
class node_be_classlist_v2 toneRose
```

## Components

### Backend services

Domain services and the public BFF

- [BFF](https://github.com/asynccnu/ccnubox-be/tree/main/bff): public api gateway · HTTP entrypoint that authenticates, shapes responses, and fans out to backend gRPC services · `bff`
- [User](https://github.com/asynccnu/ccnubox-be/tree/main/be-user): identity service · User accounts, login/session state, and core-user resolution · `be-user`
- [CCNU](https://github.com/asynccnu/ccnubox-be/tree/main/be-ccnu): sso crawler · University SSO and cookie acquisition boundary for external campus systems · `be-ccnu`
- [Classlist](https://github.com/asynccnu/ccnubox-be/tree/main/be-classlist): schedule hub · Class schedule and student-course domain with DB, cache, and event handling · `be-classlist`
- [Class](https://github.com/asynccnu/ccnubox-be/tree/main/be-class): class utility · Free classroom and course-selection upload workflows built on schedule data · `be-class`
- [Grade](https://github.com/asynccnu/ccnubox-be/tree/main/be-grade): grades service · Grade and rank crawling, storage, and update propagation · `be-grade`
- [Feed](https://github.com/asynccnu/ccnubox-be/tree/main/be-feed): notification bus · Event distribution and push delivery layer with Kafka and JPush · `be-feed`
- [Content](https://github.com/asynccnu/ccnubox-be/tree/main/be-content): reference data · Calendar, department, banner, version, and website content APIs · `be-content`
- [Library](https://github.com/asynccnu/ccnubox-be/tree/main/be-library): seat crawler · Library seat and discussion-room domain with outbound proxy support · `be-library`
- [Elecprice](https://github.com/asynccnu/ccnubox-be/tree/main/be-elecprice): polling service · Scheduled electricity-price polling and state storage with feed integration · `be-elecprice`
- [Counter](https://github.com/asynccnu/ccnubox-be/tree/main/be-counter): user attribute · Redis-backed core-user tracking used by other services · `be-counter`
- [Proxy](https://github.com/asynccnu/ccnubox-be/tree/main/be-proxy): outbound proxy · Shared proxying service for outbound crawling and external-system access · `be-proxy`

### Shared code

Protobuf contracts and reusable infrastructure libraries

- [Contracts](https://github.com/asynccnu/ccnubox-be/tree/main/common/api): protobuf api layer · Shared service interfaces and generated gRPC code for all boundaries · `common/api`
- [Biz infra](https://github.com/asynccnu/ccnubox-be/tree/main/common/bizpkg): shared runtime libs · Common gRPC, infra, logging, OTel, proxy, and config helpers · `common/bizpkg`
- [Shared tools](https://github.com/asynccnu/ccnubox-be/tree/main/common/pkg): utility libraries · Cross-cutting helpers such as cron, logger, limiter, identity, and nacos support · `common/pkg`

### Ops & delivery

Deployment, CI, and build automation

- [Deployment](https://github.com/asynccnu/ccnubox-be/tree/main/deployment): release manifests · Docker, Kubernetes, environment configs, and CI/CD wiring · `deployment`
- [Scripts](https://github.com/asynccnu/ccnubox-be/tree/main/scripts): automation · Build, infra setup, config sync, and dependency update scripts · `scripts`

### Migration path

A newer classlist implementation with clearer internal boundaries

- [Classlist v2](https://github.com/asynccnu/ccnubox-be/tree/main/be-classlist_v2): refactored class domain · Newer classlist layout with explicit biz/usecase/repository/events boundaries · `be-classlist_v2`

## Connections

- 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
