Appearance
MongoDB Domain Models & Database Schema
1. Database Document Architecture
Intelektika Portal v2.0 uses the official MongoDB Go driver (go.mongodb.org/mongo-driver/v2). Each domain entity is defined as a Go struct with BSON tags.
mermaid
erDiagram
School ||--o{ License : receives
School ||--o{ ServerMonitor : operates
School ||--o{ Student : enrolls
School ||--o{ SyncLog : records
TKAExam ||--o{ SyncLog : synced_in2. Core Document Collections
2.1 School Document (schools)
go
type School struct {
ID bson.ObjectID `bson:"_id,omitempty" json:"id"`
NPSN string `bson:"npsn" json:"npsn"`
Name string `bson:"name" json:"name"`
Stage string `bson:"stage" json:"stage"` // SD, SMP, SMA, SMK, MI, MTs, MA
DistrictCode string `bson:"district_code" json:"district_code"`
ServerCode string `bson:"server_code" json:"server_code"` // SRV-[NPSN]-01
ProctorName string `bson:"proctor_name" json:"proctor_name"`
ProctorPhone string `bson:"proctor_phone" json:"proctor_phone"`
CreatedAt time.Time `bson:"created_at" json:"created_at"`
UpdatedAt time.Time `bson:"updated_at" json:"updated_at"`
}2.2 License Document (licenses)
go
type License struct {
ID bson.ObjectID `bson:"_id,omitempty" json:"id"`
LicenseID string `bson:"license_id" json:"license_id"`
NPSN string `bson:"npsn" json:"npsn"`
SchoolName string `bson:"school_name" json:"school_name"`
HardwareID string `bson:"hardware_id" json:"hardware_id"`
MaxStudents int `bson:"max_students" json:"max_students"`
Status string `bson:"status" json:"status"` // ACTIVE, EXPIRED, REVOKED
Signature string `bson:"signature" json:"signature"`
RawToken string `bson:"raw_token" json:"raw_token"`
IssuedAt time.Time `bson:"issued_at" json:"issued_at"`
ExpiresAt time.Time `bson:"expires_at" json:"expires_at"`
}3. Database Indexing Strategy
To guarantee high throughput during simultaneous school server heartbeats:
schoolsCollection: Unique indexes onnpsnandserver_code.licensesCollection: Unique index onlicense_idand composite index on[npsn, status].server_monitorsCollection: Unique index onserver_codeand TTL index onlast_ping_at.sync_logsCollection: Composite index on[npsn, created_at].