Backend Development 20 min read

How Componentized Architecture Transforms Activity Systems: From OOP to Rule Engines

This article explores how DeWu's community activity platform evolved from ad‑hoc implementations to a componentized, event‑driven backend using OOP principles, modular design, rule engines, and observer‑hook mechanisms, while also outlining future AI‑driven optimizations and system‑wide standardization.

DeWu Technology
DeWu Technology
DeWu Technology
How Componentized Architecture Transforms Activity Systems: From OOP to Rule Engines

Introduction

DeWu’s platform blends cultural products with e‑commerce, relying heavily on community‑driven activities to boost user engagement and brand perception. Activity business drives significant UGC volume and reading time, making it a critical growth engine.

Business Catalysts

The platform faces a tension between effect (creative, varied activity designs) and efficiency (standardized, fast‑to‑market implementations). New activity types demand extensive development, testing, and risk management, leading to high iteration costs and inconsistent implementations across teams.

Componentization

To address these challenges, the system adopts componentization: breaking complex features into reusable, low‑coupling modules. Core concepts include OOP benefits (encapsulation, abstraction, inheritance, polymorphism), separation of system and business layers, and an event‑driven architecture that decouples business logic from system processes.

Rule Engine & Task Model

<code>// TaskMode 任务模型
type TaskMode interface {
    // TaskType 任务类型
    TaskType() consts.ActTaskType
    // TaskUniqueFlag 事件唯一标识
    TaskUniqueFlag() string
    // ExpressFunctions 自定义函数集
    ExpressFunctions(ctx context.Context) map[string]govaluate.ExpressionFunction
    // ExpressArguments 任务条件参数搜集器
    ExpressArguments(ctx context.Context, pending []db.PendingTasks) (dto.ExpressArguments, error)
}

// Example: TaskPublishTimes implementation
type TaskPublishTimes struct { event *dto.TaskPublishEvent }
func NewTaskPublishTimes(event *dto.TaskPublishEvent) (TaskMode, error) {
    if event.ContentId == 0 { return nil, errors.New("missing necessary parameters") }
    return &TaskPublishTimes{event: event}, nil
}
func (t *TaskPublishTimes) TaskType() consts.ActTaskType { return consts.ActTaskTypePublishTimes }
func (t *TaskPublishTimes) TaskUniqueFlag() string { return fmt.Sprintf("CNT_ID_%d", t.event.ContentId) }
func (t *TaskPublishTimes) ExpressFunctions(ctx context.Context) map[string]govaluate.ExpressionFunction {
    return map[string]govaluate.ExpressionFunction{"WITH_ANY_TOPIC": func(args ...interface{}) (interface{}, error) { /* ... */ }}
}
func (t *TaskPublishTimes) ExpressArguments(ctx context.Context, pending []db.PendingTasks) (dto.ExpressArguments, error) {
    // gather base, interaction, audit info concurrently
    return args, err
}
</code>

Observer & Hook Mechanism

<code>// ActSysObserver4TaskDetail 任务明细进展转发
type ActSysObserver4TaskDetail interface {
    Unique() string
    Forward(ctx context.Context, detail *db.ActUserTaskDetail) error
}

type ActSysSubject4TaskDetail struct { mutex sync.Mutex; observers []ActSysObserver4TaskDetail }
func (s *ActSysSubject4TaskDetail) Attach(o ActSysObserver4TaskDetail) {
    if uk := o.Unique(); len(uk) > 0 { s.mutex.Lock(); s.observers = append(s.observers, o); s.mutex.Unlock() }
}
func (s *ActSysSubject4TaskDetail) Notify(ctx context.Context, detail *db.ActUserTaskDetail) error {
    for _, o := range s.observers { if err := o.Forward(ctx, detail); err != nil { return err } }
    return nil
}

// Example Hook: Check‑in reminder
type ActTaskDetailObserver2CheckinReach struct{}
func (o *ActTaskDetailObserver2CheckinReach) Forward(ctx context.Context, d *db.ActUserTaskDetail) error {
    if d.Status != consts.ActTaskDetailStatusDone { return nil }
    return NewReachClient().Send(ctx, "act_checkin_task_detail_done", d.UserId)
}
</code>

Systemization and Future Outlook

Beyond componentization, the platform pursues full systemization: standardized activity element libraries, low‑code assembly, intelligent decision centers, and cross‑team collaboration pipelines. Upcoming enhancements include AI‑driven activity optimization, edge‑computing for low latency, and deeper integration of cultural content with e‑commerce.

Componentization diagram
Componentization diagram
Event‑driven architecture
Event‑driven architecture
rule enginebackend architecturegolangcomponentizationEvent-Driventask modeling
DeWu Technology
Written by

DeWu Technology

A platform for sharing and discussing tech knowledge, guiding you toward the cloud of technology.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.