CSEMA Go Rewrite Plan
The plan rewrites the CSEMA cybersecurity learning platform from Django + Next.js as one small Go binary (Echo, GORM, MariaDB 11.8) with an embedded Nuxt UI, plus a small agent on each lab host. It starts from what people actually use, and it keeps only what that use needs. This is the last big refactor, so every choice favours less code.
Status: implementation in progress. See the progress table. The work branch is refactor/go-rewrite (local). Measured on 31 Oct 2026 against a local copy of the production database.
1. Summary
The platform grew one feature at a time. It now has 45 Django apps, 308 tables and 669 API routes. Most of them are hidden, empty or unused. One production container runs 7 processes. A small change often touches 3 or 4 parts.
The rewrite keeps the features people use and makes each one as simple as possible. "Simple" is the main rule. When two designs work, we choose the one with fewer parts.
| Topic | Today | New |
|---|---|---|
| Programs | nginx, uvicorn ×4, 2 Celery workers, beat, Redis, Next.js server | csema (one Go binary) + csema-lab-agent on each lab host |
| Database | Postgres, 308 tables, 2,036 MB | MariaDB 11.8 with GORM, 23 tables |
| API | 669 routes | About 70 routes, one style |
| Backend code | 172k lines of Python | As little as possible. Target under 20k lines of Go. |
| UI | Next.js, 117 pages, 74 dependencies | Nuxt 4 + Nuxt UI 4, static, embedded in the binary |
| Events | A separate Next.js app (a fork of the main UI: 31 pages, 26k lines) with its own login hand-off | Part of the one app and the one binary. 3 tables. |
| Lab machines | Cloud VM pool, golden snapshots, orchestrator, Python agent | Hosts that you add by hand, a Go agent with a built-in SSH gateway |
| Size | — | Binary under 50 MB. Memory under 50 MB at idle. |
| Analytics and tracking | Tracking SDK, PostHog key, Sentry, email open and click tracking | None. Errors go to the server log. |
| Newsletter | Growth engine (10 apps) | Built in: write, test, send, one-click unsubscribe |
CLAUDE.md at the root: module shape, Go and GORM rules, API and UI conventions, no tests, no backward-compatibility code, no hard-coded values, max 500 lines per Go file, a README.md in every package (plus docs/ only when needed), and the handover checklist.2. How we measured usage
Hidden pages and dead routes look the same as live ones in code, so we used 5 sources:
- Browser crawl. We signed in with 2 local test accounts (a learner on the highest plan and a staff user) and opened 61 pages with Claude in Chrome. A marker request before each page let us assign each backend call to its page.
- Static scan of the frontend. 388 API calls with their HTTP methods, including actions that a page load does not run.
- Route table. All Django URL patterns, matched against the frontend calls.
- Database. Row count and newest write time for each of the 265 models.
- Django admin log. Which models staff change by hand.
3. The system today
- The real product data is small. Without the marketing log table, the database is about 90 MB.
- Large files live in git: lesson presentations (323 MB), challenge artwork (51 MB), marketing images (47 MB) and frontend images (94 MB). User uploads are 1.6 GB.
- The code uses no Postgres-only features. MariaDB is a safe target.
- A standalone events app (another repository, a fork of the main UI) signs users in with an SSO token and calls
/api/events/. The rewrite merges it into the one app (section 11). - A lab orchestrator (another repository) runs the lab VM pool. Section 15 replaces it.
4. Features in use
The learner sidebar has 6 items: Home, Learn, Practice, Compete, Teams and Events (the events app). The account menu adds Profile, Achievements, Plans, Bills and Ambassador. Staff have an admin panel.
| Area | What the user does | Main data today (rows, last write) |
|---|---|---|
| Sign in | Email + password, Google, GitHub, email verification, password reset, one session per user. 1,781 users (25%) have no password and use only Google or GitHub. | users (6,996, today) |
| Onboarding | 4-step survey, then a recommended path. | onboarding responses (994, today) |
| Learn | 27 paths in 5 tracks. Slide lessons, quizzes, code exercises, shell tasks, certificates. | modules (752), quiz attempts (12,817), certificates (910), code submissions (today) |
| Practice | 207 CTF challenges with hints, files and writeups. 35 machines and 23 red-team labs on hosted VMs. | solves (4,714), lab sessions (218, today) |
| Compete | Global leaderboard. | users.points |
| Teams | Team leaderboard, create, invite, join requests. | teams (161), requests (211) |
| Events | CTF events with teams, waves, live scoreboard, certificates (in the events app). 6 events so far, all free, 5 created by staff. The largest had 830 registrations and 14,322 solves in 2 days. | registrations (1,591), event solves (16,209). Last write Sep 2026. |
| Billing | Plans, Razorpay checkout, coupons, bills, lab hour packs. | plans (8), payments (today) |
| Small forms | Contact, ambassador application, CJWAPT waitlist. | 24 / 23 / 10 rows |
| Admin | Staff edit challenges, challenge files, plans, events, learning paths and users (Django admin), plus an admin panel. | admin log (1,871) |
Hidden, broken or redirect-only pages still ship: Battleground, Exams, Interviews, Jobs, Series, study materials, a path "practical" page that calls a missing route (404) and a tampered-evidence page (404). About 10 frontend calls point at routes that do not exist.
5. Scope: keep, park, drop
- core Rewritten in Go as part of the single release.
- park Does not fit the core. Its data is archived and its code is frozen. It comes back later as a separate service (section 6).
- drop No data or no users. Deleted. It stays only in git history.
| Django app | Decision | Go package / service | Routes | Used by UI | Models | With data | Rows | Last write |
|---|---|---|---|---|---|---|---|---|
| admin_panel | core | (feature admin.go) | 23 | 15 | 1 | 0 | 0 | — |
| allauth | core | auth | 19 | 1 | 0 | 0 | 0 | — |
| rest_framework_simplejwt | core | auth | 1 | 1 | 0 | 0 | 0 | — |
| users | core | auth | 70 | 47 | 23 | 16 | 30,899 | 2026-10-31 |
| offers | core | billing | 7 | 4 | 2 | 1 | 1 | 2026-01-07 |
| payments | core | billing | 10 | 0 | 1 | 1 | 8 | 2026-10-31 |
| teams | core | compete | 30 | 14 | 5 | 5 | 435 | 2026-09-08 |
| events | core | events | 99 | 53 | 27 | 21 | 45,950 | 2026-09-25 |
| redteam_labs | core | labs | 35 | 18 | 16 | 14 | 848 | 2026-10-31 |
| coding | core | learn | 8 | 1 | 5 | 5 | 846 | 2026-10-31 |
| learning | core | learn | 52 | 19 | 23 | 16 | 70,254 | 2026-10-28 |
| shell_labs | core | learn | 4 | 4 | 5 | 5 | 374 | 2026-10-31 |
| challenges | core | practice | 38 | 17 | 20 | 19 | 7,814 | 2026-10-31 |
| ambassador | core | community | 8 | 5 | 2 | 1 | 23 | — |
| exam_waitlist | core | community | 2 | 2 | 1 | 1 | 10 | 2026-10-31 |
| onboarding | core | auth | 9 | 8 | 6 | 4 | 5,204 | 2026-10-31 |
| ai_simulation | park | ai-sim | 6 | 0 | 5 | 3 | 8 | 2026-10-30 |
| battleground | park | battleground | 32 | 31 | 14 | 9 | 5,677 | 2026-09-14 |
| exam | park | exams | 25 | 9 | 13 | 10 | 29,005 | 2026-09-01 |
| forensics_labs | park | forensics | 3 | 0 | 6 | 5 | 67 | 2026-09-16 |
| tampered_evidence | park | forensics | 1 | 1 | 4 | 0 | 0 | — |
| ai_engine | park | growth | 0 | 0 | 1 | 0 | 0 | — |
| automation | park | growth | 9 | 0 | 2 | 1 | 11 | 2026-08-29 |
| campaigns | park | growth | 4 | 0 | 4 | 4 | 32,684 | 2026-10-30 |
| conversions | park | growth | 1 | 0 | 1 | 0 | 0 | — |
| decision_engine | park | growth | 0 | 0 | 1 | 1 | 7,206,921 | 2026-10-31 |
| experiments | park | growth | 3 | 0 | 2 | 2 | 15 | 2026-08-20 |
| products | park | growth | 2 | 0 | 1 | 1 | 2 | 2026-08-16 |
| providers | park | growth | 3 | 0 | 0 | 0 | 0 | — |
| scoring | park | growth | 0 | 0 | 2 | 2 | 2,525 | 2026-08-16 |
| sending_limits | park | growth | 6 | 0 | 2 | 2 | 15 | 2026-08-29 |
| ai_interactions | park | interviews | 5 | 0 | 1 | 1 | 218 | 2026-09-02 |
| interviews | park | interviews | 14 | 12 | 7 | 5 | 1,245 | 2026-05-07 |
| network_labs | park | network-labs | 4 | 0 | 2 | 2 | 118 | 2026-10-31 |
| soc_arena | park | soc-arena | 40 | 5 | 9 | 6 | 66 | 2026-10-24 |
| zero_hour | park | zero-hour | 5 | 4 | 2 | 2 | 95 | — |
| academic | drop | - | 15 | 7 | 6 | 0 | 0 | — |
| behavior_tracking | drop | - | 3 | 1 | 1 | 1 | 5,724 | 2026-10-31 |
| blog | drop | - | 4 | 3 | 2 | 2 | 6 | 2026-05-11 |
| branding | drop | - | 2 | 2 | 2 | 0 | 0 | — |
| bug_bounty | drop | - | 18 | 15 | 5 | 0 | 0 | — |
| corporate | drop | - | 11 | 7 | 3 | 0 | 0 | — |
| merch | drop | - | 13 | 0 | 6 | 0 | 0 | — |
| organizations | drop | - | 7 | 0 | 3 | 2 | 2 | 2026-08-25 |
Features we drop inside core apps
- OTP login. It went from 4,748 codes in March to 9 in August.
- Blog / news (1 post), series (0 badges earned), study materials (5 rows), jobs (0 rows), partner page.
- Faculty, academy and corporate dashboards (0 rows in their tables).
- Team announcements and team chat (2 and 30 rows, last chat in 2025).
- Ambassador hub and referrals (0 referrals). The application form stays.
- All analytics and tracking: the tracking SDK (
/api/track/, called on every page), PostHog, Sentry, and email open and click tracking. - Lab pause and resume, lab certificates (0 and 1 rows), lab hour packs (never bought) and the lab credit ledger.
- In-app notifications and the bell. 90-day volume is mostly automatic noise ("challenge unlocked": 1,507, "you solved": 771). Results show where they happen instead: a toast, the team page, the event page.
- Answer and attempt history (every quiz answer, code submission and wrong flag). Only the result is kept, in
progress. - Exam results in the core. The 149 results go to the archive with the rest of the exam data.
- Event extras that were never or almost never used: organizations (1 row, never used for an event), paid events and ticket tiers (0 sold), the paid challenge library (0 purchases), co-organizers, student event credits, white-label settings, event moderation, event bug bounty, warnings (0), integrity flags (0), challenge view tracking. Event team chat (273 messages in 1 event) is dropped too: teams use their own chat apps. Support messages become a contact form entry.
6. Notes on parked modules
These modules each have their own runtime, UI or data model. They leave the core now and come back later. By Conway's law, a module comes back as a new package in the same repository and binary, unless a separate team owns it or its runtime must be isolated. Only then is it a separate service. SOC and network labs, for example, need their own runtime images on the lab hosts, but their APIs and UI still fit in the core.
| Module | What exists today | Data to keep | Notes for the rebuild |
|---|---|---|---|
| Zero Hour (season) | zero_hour app, zero_hour_pack (412 files), story UI, audio | challenge links (24), progress (71 users) | A season links existing challenges into chapters. It needs only challenges and XP. |
| SOC Arena | soc_arena (40 routes), SOC runtime image | scenario (1), runs (6) | Runs on lab sessions. Rebuild with its own scenario engine. |
| Network labs (GNS3) | network_labs, services/netsim, Next.js GNS3 proxy | labs (73), sessions (45) | Lessons that link to these labs show "coming back soon" until the rebuild. |
| AI simulation | ai_simulation + its own Vite UI | sessions (4) | Nearly unused. Rebuild only if there is demand. |
| Forensics labs | forensics_labs, tampered_evidence, own Vite UI | sessions (4) | One "forensics simulations" service. |
| Battleground | 1v1 live CTF, hidden by a flag | sessions (134). Last activity May 2026. | Archive. Rebuild only if wanted. |
| AI interviews | interviews, ai_interactions, unlinked | attempts (15) | Archive. |
| Exams | MCQ exams, practical exams through the orchestrator | Archive (registrations, results, MCQs) | Rebuild later on the shared lab hosts. |
| Growth engine (removed) | 10 apps (decisions, campaigns, experiments …), no learner UI | Not migrated. It is removed, not rebuilt. | Transactional mail and a simple newsletter are in the core (section 11). Old tracking and unsubscribe links are not kept. |
7. What we do not build
Each item below has a simpler choice that is good enough for today's load (21 lab users a month, a peak of 2 concurrent labs, about 7k accounts). We add the bigger version only when a real need shows up.
| We do not build | We do this instead |
|---|---|
| JWT access and refresh tokens, JWKS | One opaque session token in a cookie (same origin). The same token works as a Bearer header for other clients. |
| Redis, Celery, a job queue | Goroutine tickers for periodic work. One mail_outbox table for mail. |
| A WebSocket hub, notifications | Server-sent events only for the live event scoreboard. WebSocket only for the lab terminal. No notifications. |
| A lab credit ledger and hour packs | Hours left = the monthly allowance for the user's tier (a setting) minus this month's lab_sessions.seconds_used. |
| Constants in code | A settings table, edited in admin. Infrastructure values in env config. |
| A WireGuard VPN gateway | An SSH gateway in the agent (section 15). Players need only ssh. |
| sqlc, SQL files and generated code | GORM models. Raw SQL only for a few heavy reads (leaderboard, stats). |
| Analytics, tracking, Sentry | Nothing. Server logs only. |
| A marketing engine | A newsletter: subscribers, issues in Markdown, send through the outbox. |
| OpenAPI files and code generators | Go response structs → TypeScript types with tygo. One small api.ts fetch wrapper. |
| S3 or object storage | Files on the local disk (/var/lib/csema/files), served with cache headers. |
| Separate tables for quizzes, questions, choices, tests, hints, files | JSON columns on the parent row (section 11 explains the rule). |
| A table for each kind of "done" (solves, completions, attempts, badges, certificates) | One progress table. |
| Content-as-code (55k lines of seed scripts), content files in git | Content lives in the database. Content files (lesson presentations, challenge files, images) are imported into the files directory, never committed. Staff edit both in the admin area. S3 support comes later. |
| Automated tests (for now) | Manual checklists until you approve the system (strict rule). |
| An admin audit log, analytics tables | Structured logs. |
| Cloud VM automation, autoscaling, HA | Lab hosts that you add by hand. |
| Multiple instances of the core | One instance with an in-place, zero-downtime upgrade. |
8. Target architecture
- HTTP. Echo serves
/api/*, the embedded UI and/files/*. The binary gets its own TLS certificate (ACME, HTTP-01). No nginx. - Embedded UI. The
nuxi generateoutput is embedded withgo:embed. Unknown paths return200.html. - Background work. Goroutine tickers handle event wave releases, monthly lab hours, session clean-up and newsletter batches. The mail outbox sends all mail.
- No third-party calls from the browser. No analytics, no tracking pixels, no external fonts or icons.
- Labs. The core talks to each lab host over SSH (section 15).
- Other parts outside the binary: the code runner (Python sandbox, used by code exercises), SMTP and Razorpay.
9. Repository layout
All current code from the 4 repositories moves into legacy/, unchanged. The new code is built next to it, in isolation. Nothing in the new code imports from legacy/. Docs and project files stay at the top level.
/ branch refactor/go-rewrite ├── legacy/ today's code, read-only, deleted after cutover │ ├── backend/ the Django project (all apps, services, lab packs, static) │ ├── frontend/ the Next.js app (csem_front) │ ├── events-frontend/ the separate events app │ └── orchestrator/ the lab orchestrator and Python lab agent ├── cmd/ │ ├── csema/ main.go of the core │ └── csema-lab-agent/ main.go of the agent ├── internal/ │ ├── auth/ users, sessions, tokens, onboarding │ ├── learn/ paths, modules, activities │ ├── practice/ challenges │ ├── progress/ progress, XP, leaderboard, stats, home │ ├── teams/ teams, team_members │ ├── events/ events, event_challenges, event_entries │ ├── labs/ lab_hosts, lab_sessions │ ├── billing/ plans, payments, coupons │ ├── community/ forms, subscribers, newsletters │ ├── server/ Echo setup, config, settings, middleware, errors, UI embed, graceful restart │ ├── db/ GORM setup, pool, transaction helper │ ├── mail/ outbox and SMTP │ └── agent/ agent code: reconcile, Docker, nftables, SSH gateway, HTTPS proxy, exec ├── web/ Nuxt app ├── docs/ ├── CLAUDE.md go.mod Makefile
Development uses the machine's own MariaDB 11.8 (database csema) and the existing Mailpit container. No extra database is started.
Lab sources and runtime images (machine-labs-pack, the code runner, the shell-lab image) stay in legacy/backend. They move out only when we need to change them.
10. Module design
The core has 9 feature packages and 3 platform packages. A new developer reads one package to understand one feature.
Boundaries follow the team (Conway's law)
A system copies the communication structure of the people who build it. In the last 6 months, one engineer made every commit in all 4 repositories. Today's split (separate backend, frontend, events app and orchestrator repositories, 7+ processes) makes that one person coordinate with themselves across 4 codebases for each feature. The new structure matches the real team:
- One repository, one core binary. A second binary only where the runtime is on another machine:
csema-lab-agenton lab hosts. The code runner sandbox stays separate for isolation. - Modules follow the people who ask for changes, not technical layers. Each area is a vertical slice: Go packages, their tables, a UI folder and an admin section. One person can own a whole area when the team grows. A
CODEOWNERSfile maps folders to owners at that point.
| Area | Who asks for changes | Go packages | UI folders | Admin section |
|---|---|---|---|---|
| Account | Learners (product) | auth, progress | account/, home/, profile/ | Users |
| Learning content | Course and challenge authors | learn, practice | learn/, practice/ | Content, Challenges |
| Events and community | Event and community staff | events, teams, community | events/, teams/, community/ | Events, Newsletter, Forms |
| Labs | Lab operator | labs, agent | labs/ | Labs |
| Billing | Business | billing | billing/ | Billing |
The rule for later: a new service only when a new team owns it or its runtime must be isolated. Otherwise it is a new package.
One package, one shape
internal/practice/
├── README.md what it does, tables it owns, routes, main flows (short)
├── docs/ only when one README page is not enough
├── model.go GORM structs for this package's tables (columns only)
├── practice.go type Service struct{ db *gorm.DB } and the rules (plain methods)
├── http.go Routes(g *echo.Group) and handlers: read input → call Service → write JSON
└── admin.go admin handlers for this package's tables
Rules
- Each table has one owner package. Only the owner writes to it. Any package can read with SQL joins.
- XP has one write path:
progress.Record(tx, …). It adds theprogressrow and updatesusers.xpin the same transaction.users.xpis the one column that a non-owner writes. Event solves never change it. - Handlers are thin. No SQL and no rules in a handler.
- No interfaces unless there are 2 real implementations. No repository layer: the Service uses GORM directly.
- GORM, plainly. Models have columns only, with no relation fields, so GORM never saves related rows by surprise. Joins are written where they are needed. No hooks.
- Admin endpoints live in the owner package (
admin.go), so the rules for a table stay in one place. - One error type:
server.Err(status, code, message). Clients get{"error":{"code","message","fields"}}. - Max 500 lines per Go file. Split by meaning, not by size alone.
- No backward-compatibility code. The UI and API ship in one binary, and the agent ships with the core. A change updates every caller at once: no old routes, aliases, deprecated fields, fallbacks or API versions.
- No hard-coded values. Infrastructure (domains, keys, SMTP, paths) comes from one
Configstruct, loaded from env and checked at start. Business values (lab hours per tier, ranks, onboarding roles, rate limits, feature switches) come from thesettingstable throughserver.Setting(key), cached and edited in admin. Content (paths, challenges, plans, coupons) is data. The UI has no URLs, prices, lists or constants: it reads them from the API.
Database connection
- One
*gorm.DB(gorm.io/driver/mysql) shared by all packages. Pool: at most 10 open connections, 5 idle, 5-minute lifetime. DSN:parseTime=true,loc=UTC,charset=utf8mb4. - GORM settings:
SkipDefaultTransactionandPrepareStmton, the slog logger, UTCNowFunc. - Transactions:
db.Transaction(func(tx *gorm.DB) error { … }). Each request uses at most one. - Schema: for now,
AutoMigratefrom the models during development. Proper migration tooling comes later, before the first deploy. The deploy rule stays the same: a release only adds columns, tables or indexes (expand), and a later release removes old ones (contract).
11. Data model and ERD
The model has 23 tables. Four ideas make it small:
- One table for "done".
progressstores every completion: a solved challenge, a machine flag, an unlocked hint, a finished activity, module or path, and an event solve. XP, leaderboards, streaks, the activity heatmap, badges and certificates all come from this one table. - JSON for parts that belong to a parent. A quiz's questions, a code exercise's tests, a challenge's hints, files and lab spec are always read and saved together with their parent and are never queried on their own. The rule: if we never query it alone, it is a JSON column. The API never sends answers, flag hashes or tests to the browser.
- Status columns, not more tables. Team invites and join requests are rows in
team_memberswithstatus=invitedorrequested. Event allow-lists are rows inevent_entrieswithstatus=allowed. Contact, ambassador, waitlist, event-support and challenge-report forms are rows inform_entries. Newsletter opt-in is one row insubscribersfor each email. - Reuse. Event challenges are normal challenges linked to an event. They stay unpublished in Practice until staff publish them after the event. Event teams are normal teams with
event_idset and a join code. Event solves and hints areprogressrows withevent_idset.
user_id column points to users.id (lines to users are left out for clarity). Dashed lines are references by kind + ref_id.Key tables in detail
progress one row = one thing a user finished
user_id BIGINT → users.id
event_id BIGINT 0 = not in an event, else → events.id
kind ENUM challenge | flag | hint | activity | module | path
ref_id BIGINT id of the challenge / activity / module / path
part VARCHAR(32) '' | 'user' | 'root' (machine flags) | hint number
xp INT can be negative (a hint costs XP)
score SMALLINT quiz score in %, else NULL
data JSON e.g. {"certificate":"CSEMA-7F3K-…"} for a path
created_at DATETIME(6)
PRIMARY KEY (user_id, event_id, kind, ref_id, part)
INDEX (event_id, created_at), INDEX (kind, ref_id)
challenges
id, slug UNIQUE, title, category, difficulty, kind ENUM(flag, machine), tier ENUM(free, prime, elite),
xp, body JSON {description, hints:[{text,xp}], files:[{name,path}], writeup, tags:[…]}
flags JSON [{part:"", hash}] or [{part:"user",hash,xp},{part:"root",hash,xp}] (HMAC, never sent out)
lab JSON {image, port, memory_mb, services:[…]} (machine only)
published, created_at, updated_at
activities one interactive part of a module
id, module_id → modules.id, position, kind ENUM(quiz, code, shell, challenge), title, xp
challenge_id → challenges.id, only when kind = challenge (a real foreign key)
content JSON quiz: {questions:[{text, choices:[…], answer}]}
code: {starter, tests:[…]} shell: {setup, checks:[…]}
lab_sessions
status ENUM(starting, running, ended, failed), error TEXT
active_user_id generated: user_id while starting or running, else NULL
UNIQUE (active_user_id) one active lab per user, race-free
teams / team_members
teams.owner_id the one owner; a transfer is one update
team_members PRIMARY KEY (team_id, user_id), status ENUM(member, invited, requested)
event_entries
UNIQUE (event_id, user_id) no double registration, one team per event
UNIQUE (event_id, email) one allow-list row per email
payments
amount_paise INT, UNIQUE (provider_order_id), UNIQUE (provider_payment_id)
XP rules
| Column | Meaning |
|---|---|
challenges.xp, activities.xp | Default reward for a solve or a finished activity. |
modules.xp | One-time bonus when the module is complete. Finishing a path gives a certificate, not XP. |
event_challenges.xp | The reward inside that event. It replaces challenges.xp there. |
progress.xp | The XP actually given. The primary key makes a second award impossible. |
users.xp | Lifetime XP. A cache of progress.xp where event_id = 0, updated in the same transaction by progress.Record. |
Event XP and lifetime XP are separate. An event solve (event_id ≠ 0) counts only on that event's scoreboard and never changes users.xp. A user can solve the same challenge once in Practice and once in each event.
Flags
- Static flags: HMAC-SHA256 hashes in
challenges.flags. - Per-player flags (machine labs): generated when a session starts and stored as hashes in
lab_sessions.flags. - The HMAC key (
FLAG_PEPPER) lives in env config, never in the database. A database dump alone cannot be used to guess flags offline.
Old tables to new tables
| New | Replaces (today) |
|---|---|
progress | ChallengeSolve, MachineFlagSolve, UnlockedHint, ModuleCompletion, ModuleProgress, PathProgress, QuizAttempt, CodingExerciseSolve, ShellTaskPass, EarnedBadge, Certificate, EventChallengeSolve, UnlockedEventChallengeHint, UserStreak, UserScoreHistory |
activities | Quiz, QuizQuestion, QuizChoice, CodingExercise, CodingTestCase, ShellPractical, ShellTask, ChallengePlacement |
modules, paths | Module, Phase (→ section text), Objective, Resource, LearningPath, Topic |
challenges | Challenge, Category, Tag, Hint, ChallengeFile, OfficialWriteup, TutorialPoint, MachineFlag, RedTeamLabSpec, RedTeamLabContent, RedTeamFlagSecret |
teams, team_members | Team, TeamInvite, TeamRequest, TeamAnnouncement, TeamChat, EventTeam, EventTeamMember, EventTeamRequest |
events, event_challenges, event_entries | Event, EventWave (→ release_at), EventChallenge, EventChallengeHint, EventRegistration, EventAllowedEmail, CertificateTemplate, UserPrize, EventGallery, EventAnnouncement (→ settings JSON, shown on the event page), EventReport and TrivarnaWriteup (→ data), EventSupportMessage (→ form_entries) |
lab_hosts, lab_sessions | RedTeamPoolVM, RedTeamTenantSlot, LabSession, RedTeamLabState |
plans, payments, coupons | SubscriptionPlan, RazorpaySubscription, UserSubscriptionVerification, RedTeamSubscription, Offer, CouponCode |
users, sessions, tokens | User, UserProfile (core fields), EmailVerification, PasswordReset, OnboardingResponse (→ users.onboarding JSON) |
form_entries | Contact, Ambassador, ExamWaitlistEntry, EventSupportMessage, Feedback and ChallengeReport |
settings | JobRole, ranks, tier lab hours and other values that are hard-coded today |
| Not kept (archived) | QuizAnswer, CodeSubmission, ChallengeAttempt, ShellAttempt, Notification, UserNotification, LabAccount, LabCreditEntry, LabPlanPurchase, all exam tables |
subscribers, newsletters | Marketing consent, MailingGroup, campaigns (new, simple version) |
mail_outbox | Celery mail tasks, EmailLog |
Schema rules: MariaDB 11.8 LTS, InnoDB, utf8mb4_uca1400_ai_ci, strict mode. DATETIME(6) in UTC. JSON columns with JSON_VALID checks. An index on every foreign key. Integer ids stay the same as today where a table maps one-to-one. Money is integer paise. Emails are stored lowercase. Every *_id column has an index. Foreign key constraints come with the migration tooling, because GORM creates them only from relation fields and our models have none.
12. API
Conventions
- Prefix
/api. Plural nouns. Content uses slugs in URLs (/api/challenges/sql-101). Things that users create use ids. - Auth: the
csema_sessioncookie (HttpOnly, Secure, SameSite=Lax), orAuthorization: Bearer <token>. - Lists:
?cursor=&limit=(default 50, maximum 200). The response is{"items":[…],"next":"…"}. - Writes return the changed object. Errors use the one error shape.
- One call for each screen.
GET /api/megives the user, plan, offer banner and the settings the UI needs.GET /api/homegives the whole Home page.
Endpoints
auth
POST /api/auth/signup email, username, password
POST /api/auth/login email or username + password → sets cookie
POST /api/auth/logout
GET /api/auth/google /api/auth/github redirect to the provider
GET /api/auth/google/callback /api/auth/github/callback
POST /api/auth/verify-email token
POST /api/auth/forgot-password email
POST /api/auth/reset-password token, password
GET /api/me user, plan, banner, UI settings
PATCH /api/me name, bio, country, avatar, newsletter on/off
PUT /api/me/password
PUT /api/me/onboarding survey answers → recommended path
community
POST /api/forms/{contact|ambassador|waitlist|event-support|challenge-report}
POST /api/newsletter subscribe an email (double opt-in mail)
POST /api/newsletter/unsubscribe token from the mail link (one click, no login)
learn
GET /api/paths all paths by track, with my progress
GET /api/paths/{slug} path, sections, modules, my progress
GET /api/modules/{id} lesson content + activities (no answers)
POST /api/modules/{id}/complete
POST /api/activities/{id}/submit quiz answers | code | shell check → result, xp
GET /api/certificates/{code} public certificate check
practice
GET /api/challenges ?category&difficulty&kind&q&solved&cursor
GET /api/challenges/{slug} details, hints (locked/unlocked), files, my flags
POST /api/challenges/{slug}/flag flag, part → correct?, xp
POST /api/challenges/{slug}/hints/{n} unlock a hint (costs xp)
progress
GET /api/home next lesson, today, weekly goal, streak, picks
GET /api/leaderboard ?limit
GET /api/users/{username} public profile: xp, rank, badges, heatmap, radar
teams
GET /api/teams leaderboard + search
POST /api/teams create (I become owner)
GET /api/teams/{slug}
PATCH /api/teams/{slug} name, open (owner)
POST /api/teams/{slug}/join request to join, accept my invite, or join with a code
POST /api/teams/{slug}/members invite a user (owner)
PATCH /api/teams/{slug}/members/{uid} accept a request (owner)
DELETE /api/teams/{slug}/members/{uid} leave, kick, decline
labs
GET /api/labs hours left this month, my running session, its SSH command and password
POST /api/challenges/{slug}/lab start a lab session
DELETE /api/labs/sessions/{id} stop it
GET /api/labs/sessions/{id}/terminal WebSocket: terminal in the attack box
events
GET /api/events upcoming, live, past
GET /api/events/{slug} details, my entry, my team
POST /api/events/{slug}/register join (checks the allow-list)
DELETE /api/events/{slug}/register leave before the start
GET /api/events/{slug}/challenges released challenges (waves by release_at)
POST /api/events/{slug}/challenges/{cslug}/flag
POST /api/events/{slug}/challenges/{cslug}/hints/{n}
GET /api/events/{slug}/scoreboard public when the event allows it (spectate)
GET /api/events/{slug}/stream server-sent events: scoreboard, releases, announcements
POST /api/events/{slug}/writeup upload a writeup file after the event
(event teams use /api/teams with "event": slug, and join with the team's join code)
billing
GET /api/plans active plans
GET /api/coupons/{code} check a coupon
POST /api/checkout plan + coupon → Razorpay order
POST /api/checkout/verify Razorpay signature → payment done
POST /api/webhooks/razorpay
GET /api/payments my bills
Admin API
Every admin resource has the same 5 routes. Only staff can call them. Each resource lives in the package that owns its table (admin.go).
GET /api/admin/{resource} list ?q= & filters & cursor
POST /api/admin/{resource} create
GET /api/admin/{resource}/{id} read
PATCH /api/admin/{resource}/{id} update (only the fields sent)
DELETE /api/admin/{resource}/{id} delete
| Resource | Package | Filters | Extra actions (only these) |
|---|---|---|---|
users | auth | q, role, tier | No create. PATCH sets role, tier, tier_until, disabled. DELETE anonymizes. |
paths, modules, activities | learn | path, module, published | — |
challenges | practice | q, category, kind, published | POST /challenges/{id}/files upload a file |
events | events | status (upcoming, live, past) | PUT /events/{id}/challenges the full list with xp and release_atGET|PATCH /events/{id}/entries, POST /events/{id}/entries/import (CSV allow-list)POST /events/{id}/announcements post on the event page (live through the stream) |
teams | teams | event, q | — |
plans, coupons | billing | active | — |
payments | billing | from, to, status, kind | Read only. The list also returns totals for the range. Manual upgrades are a PATCH on the user's tier. |
lab-hosts | labs | status | POST /lab-hosts/{id}/setup install over SSH. |
lab-sessions | labs | status, host, user | No create. DELETE stops a session. |
forms | community | form (contact, ambassador, waitlist, event-support, challenge-report), status (new, done) | — |
subscribers | community | status, q | — |
newsletters | community | status | POST /newsletters/{id}/test send to mePOST /newsletters/{id}/send send to all subscribers |
settings | server | — | List and PATCH /settings/{key}. No create or delete: keys are defined in code with defaults. |
system | server | — | Read only: GET /api/admin/system gives version, uptime, database, mail queue and lab hosts. |
Today's admin routes, and where they go
| Today | New |
|---|---|
/api/admin-panel/contact-messages/ | /api/admin/forms?form=contact |
/api/admin-panel/exam-waitlist/ | /api/admin/forms?form=waitlist |
/api/admin-panel/system-health/ | /api/admin/system |
/api/admin-panel/revenue-summary/ | /api/admin/payments?from=&to= (totals in the response) |
/api/admin-panel/live-events/ | /api/admin/events?status=live |
/api/admin-panel/integrity-flags/ | Dropped (0 rows) |
/api/challenges-admin/ | /api/admin/challenges |
/api/redteam/admin/labs/, …/labs/meta/, …/labs/{id}/test-launch/ | /api/admin/challenges (the lab spec is a field of the challenge). Test launch is a normal lab start by a staff user. |
/api/redteam/admin/labs/snapshot/rebuild/ | Dropped (no snapshots) |
/api/learning-admin/, /api/learning-paths/bulk-upload/ | /api/admin/paths, /modules, /activities |
/api/accounts/admin/lifecycle-emails/, /api/accounts/mailing/… | /api/admin/newsletters |
/api/bug-bounty/admin/…, /api/battleground/sessions/, /api/jobs/, /api/study-materials/ | Dropped or parked |
Django admin (/admin/, 1,285 routes) | The resources above |
That is about 70 routes plus the admin resources, against 669 routes today. The appendix lists the 208 core routes that the current UI calls, grouped by new package. Every feature in them maps to a route above or is in the drop list.
13. Sessions and compatibility
- Sessions. A random 32-byte token. Only its SHA-256 hash is stored in
sessions. Login deletes the user's other sessions (the current one-session rule). Sessions last 30 days and slide on use. - Passwords. Django hashes (
pbkdf2_sha256$…) are checked withx/crypto/pbkdf2. On the next login they are rehashed with argon2id. - Google and GitHub. A user is matched by verified email, as today. No extra table.
- Flags. Stored hashes are HMAC-SHA256 with the old secret key as pepper. The same value becomes the
FLAG_PEPPERsetting. - At cutover everyone logs in once more. Passwords keep working. We do not bridge the old JWTs.
- No compatibility layer. Old routes, links and file URLs are not kept. Files are served at
/files/….
14. UI plan
Problems in today's UI
- Every page makes 7 "shell" calls, and Home makes about 15 more.
- Dead, hidden and redirect-only pages still ship, and one route folder is a duplicate.
- The admin "Tools" page mixes 9 unrelated tabs.
- The API layer is split over
client.ts…client-part4.tsplus 30 files. - Next.js server routes act as proxies, and heavy duplicate libraries ship (2 chart libraries, jQuery, 2 globe libraries, Genkit).
New UI
- Stack. Nuxt 4 + Nuxt UI 4 + TypeScript,
ssr: false, built withnuxi generateand embedded in the binary. No Node server in production. Landing, pricing and legal pages are pre-rendered for SEO. - Few overrides. We use Nuxt UI components as they are. The theme changes only through one global override, so that the shades stay the same as today.
- Everything is a component. A page only composes components and has no CSS of its own. Shared parts live in
components/app/. Each feature has a folder that matches its Go package, for examplecomponents/practice/ChallengeCard.vue. - Data. One
api.tsfetch wrapper with relative URLs. Types come from Go withtygo. - No hard-coded content. No lists of paths, plans, ranks, roles or prices in the UI code. Today's UI has many (curriculum, plan highlights, ranks, lab templates, scenario JSON). The new UI reads all of them from the API.
- No tracking. No analytics, no third-party scripts. Inter and the icons are bundled locally.
- Navigation. Home · Learn · Practice · Compete (leaderboard, teams) · Events · Profile. Events screens: list, event page (register, team), play (challenges, team, scoreboard), live scoreboard for spectators, results and certificate. Admin has its own sidebar: Users, Content, Challenges, Events, Billing, Labs, Forms, Newsletter, Settings, System.
- One page pattern. A header (title and one main action), a filter bar, the content, and empty, loading and error states.
- Certificates (paths and events) are HTML pages built from a template image and the user's name, printed to PDF by the browser. No PDF code on the server.
- Budget. Initial JavaScript under 250 KB gzip, one chunk for each route.
// app.config.ts
export default defineAppConfig({ ui: { colors: { primary: 'blue', neutral: 'neutral' } } })
/* assets/css/main.css */
@import "tailwindcss";
@import "@nuxt/ui";
@theme { --font-sans: 'Inter', system-ui, sans-serif; }
:root { --ui-bg: #ffffff; --ui-bg-muted: #fbfcfd; --ui-primary: var(--color-blue-600); }
.dark { --ui-bg: #0f0f0f; --ui-bg-elevated: #161616; --ui-bg-muted: #0b0b0b;
--ui-border: #262626; --ui-primary: var(--color-blue-500); }
15. Machine lab hosting
Machine labs, red-team labs, shell labs and (later) SOC and exam labs run as containers on shared lab hosts. A small Go agent, csema-lab-agent, runs on each host. The core's labs package places sessions and controls the agents.
Why we change it
| Measured (Sep to Oct 2026) | Value |
|---|---|
| Lab sessions | 218 sessions, 21 accounts |
| Peak concurrent sessions | 2 |
| Real play time | about 17 h |
| Cloud VMs created since 3 Aug | 61, about 2,263 VM-hours |
| Failed starts | 15% (32 of 218), all from network hops between services |
| Typical lab memory | 128–256 MB |
The VM-hours are about 100 times the play time. The cost comes from warm and short-lived VMs, not from players.
Design
- Hosts. In development the lab host is the same machine as the core. In production we connect any machine by its IP address: the same machine or another one.
- Code runner. The agent runs the code runner (Python sandbox for code activities) as a container on the lab host. Learner code never runs next to the core.
- Add a host by hand. You create a Debian 12 machine and add the core's SSH key. In admin you click Add host. The core connects once as root (the host's SSH server and port stay as they are), installs Docker and nftables, creates a restricted user (socket forwarding only), uploads the agent and starts it with systemd.
- Control link. The agent serves HTTP only on a Unix socket. The core reaches the socket through one SSH connection for each host. There is no public control port and no API key.
- Desired state. The core sends the full list of sessions for the host. The agent compares it with the running containers, fixes any difference and reports back. The agent also stops sessions at their deadline by itself.
- Placement. The host with the most free memory, checked under
SELECT … FOR UPDATEon thelab_hostsrow. A unique generated column allows one active session per user. Labs share hosts. - Lab hours. Each tier's monthly allowance is a setting. Hours left = allowance minus this month's
seconds_used. No credit table. - Isolation now. Standard containers with memory, CPU and PID limits. nftables rules stop labs from reaching the internet, the host or other sessions.
- One release. Core and agent have one version. A core upgrade pushes the agent to every host.
Network
Each session gets its own Docker network, a /27 from 198.18.0.0/17, which is the pool that CLAUDE.md already pins. There is no VPN.
How a player reaches a lab
- SSH gateway (main path). The agent has a built-in SSH server on port 2222. The host's own SSH server is never changed. The UI shows one command and a password for each session:
ssh -p 2222 s-1234@ssh.lab.csema.tanmoysrt.xyz shell in the attack box ssh -p 2222 -L 8080:198.18.3.5:80 s-1234@ssh.lab.csema.tanmoysrt.xyz reach a target port from your laptop ssh -p 2222 -D 1080 s-1234@ssh.lab.csema.tanmoysrt.xyz SOCKS proxy for a browser or proxychains ssh -p 2222 -R 4444:localhost:4444 s-1234@ssh.lab.csema.tanmoysrt.xyz catch a reverse shell on your laptop ssh -J s-1234@ssh.lab.csema.tanmoysrt.xyz:2222 root@198.18.3.5 jump to a target's own SSH
The gateway allows forwards only into the user's own session network. A reverse forward (-R) listens on the session network's gateway address, so a target can connect back. Players need nothing butssh, and it works where UDP is blocked. The limit: no raw UDP or ICMP from the player's own machine. Those tools run in the attack box. - Web challenges:
https://<token>.lab.csema.tanmoysrt.xyz. Wildcard DNS points at the host. The agent gets the wildcard certificate (ACME DNS-01) itself. - Terminal in the UI: browser → core (checks the user) → SSH tunnel → agent →
docker execwith a PTY in the attack box. No ttyd container.
Agent API (Unix socket)
GET /health version, Docker status
PUT /state desired sessions and images (full list, with SSH passwords)
GET /state actual sessions, IPs, ports, errors, memory and network use
GET /exec/{session} WebSocket: interactive PTY
16. Deploy and size budget
- Copy the new binary and run
systemctl reload csema. - The running process starts the new binary and passes it the listening socket (
tableflip). - The new process applies schema changes (expand only) and reports ready.
- The old process stops accepting, finishes requests (30-second limit), closes UI terminals with code 1012 and exits. Clients reconnect. Lab SSH sessions are not affected: they end at the agent, not the core.
- If the new process fails its health check, it exits and the old one keeps serving.
| Budget | Limit | How |
|---|---|---|
| Binary | < 50 MB (target 30) | CGO_ENABLED=0 -trimpath -ldflags "-s -w". CI fails above the limit. |
| Memory at idle | < 50 MB (target 30) | GOMEMLIMIT=48MiB, 10 DB connections, no big caches. |
| Not in the binary | — | Lesson presentations, uploads and large images, in /var/lib/csema/files. |
17. Phases and steps
Implementation progress
Current order: the backend is implemented. Next is the UI from section 14: minimal, with the legacy design as the visual baseline, Nuxt UI blocks as they are and the theme in one place.
| Phase | Status | Implemented and checked | Remaining |
|---|---|---|---|
| P0 Set up | Implemented | Go layout, local MariaDB database, Nuxt scaffold, Makefile and CI checks. Local format, vet, build and size checks pass. | Remote CI run when publication of the branch is authorized. |
| P1 Skeleton, auth, progress | Implemented; checks open | Core server, database, mail outbox, auth, onboarding, progress and all 23 models. Password and mail flows checked locally. | Google and GitHub sign-in with configured credentials. Complete the remaining exit checks. |
| P2 Learner backend | Implemented (Few checks pending) | Learner routes, content import, staff CRUD and uploads are implemented. Shell state and editor checkpoints pass manual checks. Teams, plans, coupons, payment reports, forms, subscribers and newsletters pass API checks. Mailpit confirms preview, bulk send and one-click unsubscribe. Checkout uses Razorpay Orders and signed capture verification. Missing-key and unsigned-webhook checks pass. Added GET /api/home (next lesson, week goal, streak, rank step, picks), GET /api/admin/system and avatar upload; each checked through the API. | Real Razorpay checkout, captured payment, signed webhook and repeat-delivery checks need staging keys. |
| P3 Labs | Implemented (Few checks pending) | Host setup, placement, full desired state, Docker networks, SSH gateway and browser terminal. Manual checks cover private image pulls, isolation, stop, deadline cleanup and container survival across an agent restart. The agent manages the code runner. A reverse forward works from its own lab and is blocked from a separate network. Active labs block runtime edits. A fresh agent deployment passes the SSH shell check. Wildcard HTTPS with Certbot DNS-01 returns a lab page with a trusted certificate; web access is explicit per service (131 of 133 machines). Idle stop, agent upgrade with 40 containers kept, 20 concurrent sessions on distinct /27 networks, and cached starts of 1.35 to 1.39 s are checked. Shutdown ends terminals with code 1012 and streams at once; normal requests still drain. | Start every machine of the catalogue once. Finish the -J check. 28 compose labs and the ttyd shell labs are not imported. The owner deferred the 40-session, 24-hour soak until the end of the whole rewrite. |
| P4 UI | In progress | The learner and staff screens are implemented. Learning now uses a compact library, a curriculum without numbered rails and a focused HTML lesson reader. Shared presentation players and simulators are copied with the learning files. Mobile headers and cards are smaller. Eyebrow labels and nested card states are removed. Buttons and form controls use a central md size. Landing and pricing actions also use md. Shared actions are neutral, and a screen has at most one explicit primary action. Manual review covered 38 mobile and desktop screen states without duplicate primary buttons. Practice now shows separate Challenges and Machine labs tabs. Search, topic filters, catalogue tabs, pagination and presentation full screen passed manual browser checks at mobile and desktop widths in light and dark themes. The landing page is at / and the signed-in home is at /dashboard. Auth screens, Ctrl+K search, flag and lesson celebrations, admin lists and filters use soft neutral surfaces. The sidebar has its own surface and a raised active row, and its collapse button is at the bottom. All 765 challenge titles, stories and machine questions are rewritten, and categories drop from 38 to 15. Machine labs can use a per-player flag. Admin, auth and sidebar screens pass a browser check in light, dark, collapsed and narrow states. | Finish the remaining form, certificate, editor and event browser checks. Check the initial JavaScript budget. A content inventory found 29 referenced video files missing locally; the lesson HTML and interactive content remain available. Soak checks remain deferred until the end. |
| P5 Events | Implemented; UI checks in progress | The event backend and manual solo/team flows are implemented. The UI now has event lists, registration, event teams, challenges, live scoreboard, writeup upload and certificates. Staff screens cover event editing, challenge waves, entries, allow-list import and announcements. | Finish the browser dry run and the TRIVARNA-size load check. Soak checks remain deferred until the end. |
| P6 Verify and harden | Pending | Manual checks and build checks run during implementation. No automated tests were added. | Complete section 18, load checks, upgrade checks and owner approval. |
| P7 Migration and cutover | Plan later | No production cutover work. | Write the migration plan after system verification, as specified below. |
P0. Set up
- Done: move all current code to
legacy/(gitignored):backend(csemv2),frontend(csem_front),events-frontendandorchestrator. The 4 repositories become 1. - Write
CLAUDE.md(done, on the branch). Create the Go module, thecsemadatabase on the local MariaDB 11.8, the Makefile and CI (vet, build, size check). No test jobs (strict rule). - Create the Nuxt app in
web/with the theme override.
P1. Skeleton, auth, progress
server,db,mail: Echo, errors, cookie sessions, rate limits, the GORM setup, the outbox, the UI embed, graceful restart.- GORM models for all 23 tables.
authandprogress(Record, leaderboard, stats).
P2. Learner features
- A one-time content import from Postgres: paths, modules, activities, challenges, plans. The UI then works with real content.
learn(with the code runner for code activities),practice,teams,billing,community(forms, newsletter), each with itsadmin.go.
P3. Labs (parallel from P1)
- Agent: socket API, Docker, reconcile loop. Check: start and stop 20 sessions on a local VM.
- Hosts: Add host over SSH, restricted user, agent upload. Check: an empty Debian 12 VM becomes ready with one click.
- Network:
/27networks, multi-service labs, nftables. Check: user A cannot reach user B's lab, and labs cannot reach the internet. - Access: the SSH gateway (shell,
-L,-D,-R,-J), wildcard HTTPS and the UI terminal. Check: each command in section 15 works, and a reverse shell reaches a laptop. - Credits, deadlines, idle stop. Soak run: 40 sessions for 24 hours, with a core deploy during the run.
P4. UI (parallel from P1)
- App shell, then Home, Learn, Practice (with the lab panel and terminal), Compete, Profile, Billing.
- Admin screens for each package.
- Pre-render public pages. Embed the build.
P5. Events (merged into the one app)
eventspackage: events, waves byrelease_at, allow-list import, registration, event teams with join codes, flags and hints throughprogress, scoreboard, the server-sent event stream, writeups.- Admin screens: create and edit, attach challenges and waves, entries, teams, announcements.
- Player screens and the public live scoreboard.
- Load: one live event of TRIVARNA size (830 players, about 14k solves) on one binary. Rate limits on flag submits. The scoreboard is cached for 2 seconds.
P6. Verify and harden
- Walk through every flow by hand with the checklist.
- Run a load tool against the busiest routes, and deploy while it runs.
- After your approval, and only then, we decide which automated tests to add.
P7. Data migration and cutover (planned later)
Outline: an import tool transforms the Postgres data into the 23 tables and checks the counts. We rehearse it, then switch traffic in a short read-only window. Django stays available for a rollback period, and then legacy/ is deleted.
18. How we check success
All checks are manual until you approve the system (strict rule: no automated tests).
| Check | Pass condition |
|---|---|
| User flows | A walkthrough of every flow works: sign up, onboard, lesson, quiz, code, flag, hint, start lab, SSH, terminal, team, checkout (Razorpay test mode), newsletter, admin edit. |
| Old passwords and flags | A sample of real password hashes and flag hashes verify in Go. |
| Lab starts | Time to running is under 5 s with cached images. No failed starts in 50 tries. |
| Zero downtime | A deploy during a load-tool run gives 0 failed requests. Open lab SSH sessions stay up. |
| Speed | p95 under 50 ms for the 20 busiest routes on the real data. |
| Size | Binary under 50 MB. Idle memory under 50 MB. |
| Privacy | The browser makes no request to any third-party host. |
| Simplicity | 23 tables, about 70 routes, under 20k lines of Go. |
| No hard-coded values | A search of the Go and Vue code finds no URLs, prices, limits, lists or copy text outside config, settings and UI labels. |
19. Risks
| Risk | Mitigation |
|---|---|
| A dropped feature is still used by someone. | The drop list is checked with you before P2. Data is archived, not deleted. |
| The new data model loses detail (for example every quiz answer). | Only the score and the last submission are kept. This is a choice. The archive keeps the old rows. |
| A large live event overloads the one binary. | Cached scoreboard, flag rate limits, server-sent events from one in-process hub. A staff dry run before the first real event. No cutover during an event. |
| One lab host (no HA). | Accepted for now. Sessions are short and restart cleanly. |
| One big release is late. | Freeze new features in Django. Labs and UI run in parallel. |
20. Decisions
| Question | Decision |
|---|---|
| Drop list (section 5) | Accepted. |
| Exams | Set aside for now. Data is archived. |
| Growth engine | Removed. |
| Hosting | Development: core, MariaDB and lab host on one machine. Production: we connect a lab host by IP, the same machine or another one. |
| Lab host SSH | The host's SSH server and port are never changed. The player gateway uses port 2222. |
| Base domain | csema.tanmoysrt.xyz. Labs at *.lab.csema.tanmoysrt.xyz. |
| Code runner | A container on the lab host, run by the agent. |
| Content files | Out of the repository. Imported into the files directory. S3 later. |
| Legacy code | All 4 repositories moved to legacy/ (gitignored, read-only reference). Done. |
21. Appendix: raw maps
Page to API (crawl, 61 pages)
The 7 shell calls on every page are /api/branding/, /api/accounts/notifications/, /api/accounts/api_profile/, /api/track/, /api/offers/current/, /api/events/my-collaborations/ and /api/ambassador/me/. Red codes are errors.
Show the page map
| Page | API calls on load (beyond the 7 shell calls) |
|---|---|
/dashboard/challenges/1133 | GET /api/coding/exercises/GET /api/challenges/{id}/GET /api/redteam/session/GET /api/redteam/credits/GET /api/redteam/machines/{id}/GET /api/redteam/machines/ |
/dashboard/learning/57 | GET /api/accounts/onboarding/status/GET /api/learning-paths/{id}/ |
/dashboard/learning/57/practical | GET /learning/api/learning/paths/{id}/practical/ 404 |
/dashboard/study-materials | GET /api/learning-paths/ |
/dashboard/study-materials/2 | GET /api/learning-paths/ |
/dashboard/exams | GET /api/exam/api/exams/GET /api/exam/api/my-history/ |
/dashboard/exams/history | GET /api/exam/api/my-history/ |
/dashboard/exams/:id | GET /api/exam/api/exams/{id}/GET /api/exam/api/check-access/ |
/dashboard/interviews | GET /api/interview-credits/GET /api/interviews/ |
/dashboard/interviews/history | GET /api/interview-attempts/ |
/dashboard/interviews/:id | GET /api/interview-credits/GET /api/interviews/{id}/ |
/dashboard/jobs | GET /api/accounts/api_weekly_progress/GET /api/accounts/onboarding/status/GET /api/onboarding/survey/journey/GET /api/zero-hour/progress/GET /api/zero-hour/campaign/GET /api/learning-paths/GET /api/challenges/GET /api/events/ |
/dashboard/leaderboard | GET /api/accounts/api_leaderboard/ |
/dashboard/news | GET /api/blog-posts/ |
/dashboard/series | GET /api/zero-hour/progress/GET /api/redteam/credits/GET /api/zero-hour/campaign/GET /api/soc/GET /api/redteam/machines/GET /api/challenges/ |
/dashboard/teams/:id | GET /api/teams/{id}/GET /api/teams/ |
/dashboard/profile | GET /api/accounts/api_skill_radar/GET /api/accounts/api_daily_activity/ |
/dashboard/achievements | GET /api/accounts/available-challenge-badges/ |
/dashboard/pricing | GET /api/accounts/api/pricing/ |
/dashboard/bills | GET /api/payments/history/ |
/dashboard/ambassador | none |
/dashboard/cjwapt | GET /api/waitlist/CJWAPT/ |
/dashboard/bug-bounty | GET /api/bug-bounty/programs/GET /api/bug-bounty/my-stats/ |
/dashboard/bug-bounty/timeline | GET /api/bug-bounty/timeline/ |
/dashboard/bug-bounty/submissions | GET /api/bug-bounty/submissions/ |
/dashboard/bug-bounty/leaderboard | GET /api/bug-bounty/leaderboard/ |
/dashboard/bug-bounty/prizes | GET /api/bug-bounty/vulnerability-badges/GET /api/bug-bounty/vulnerability-badges/sqli/image/GET /api/bug-bounty/vulnerability-badges/idor/image/GET /api/bug-bounty/vulnerability-badges/rce/image/GET /api/bug-bounty/vulnerability-badges/xss/image/GET /api/bug-bounty/vulnerability-badges/auth_bypass/image/GET /api/bug-bounty/vulnerability-badges/ssrf/image/GET /api/bug-bounty/vulnerability-badges/info_disclosure/image/GET /api/bug-bounty/vulnerability-badges/csrf/image/ |
/dashboard/battleground | GET /api/accounts/api_leaderboard/ |
/dashboard/practice/new | GET /api/challenges/ |
/dashboard/machines/plans | GET /api/accounts/api/pricing/ |
/dashboard/learning/challenges/tampered-evidence | GET /api/tampered-evidence/DF101-CTF-TAMPERED-EVIDENCE/session/ 404POST /api/tampered-evidence/DF101-CTF-TAMPERED-EVIDENCE/session/ 404 |
/dashboard/profile/achievements | GET /api/accounts/available-challenge-badges/ |
/dashboard/academic | GET /api/academic/assignments/ |
/dashboard/corporate | none |
/dashboard/challenges/create | GET /api/categories/GET /api/redteam/credits/GET /api/challenges/GET /api/redteam/machines/ |
/ | GET /api/stats/GET /api/accounts/api_weekly_progress/GET /api/accounts/onboarding/status/GET /api/onboarding/survey/journey/GET /api/learning-paths/GET /api/zero-hour/progress/GET /api/zero-hour/campaign/GET /api/challenges/GET /api/events/ |
/pricing | GET /api/stats/GET /api/accounts/api/pricing/ |
/leaderboard | GET /api/accounts/api_leaderboard/ |
/learning | GET /api/learning-paths/ |
/challenges | GET /api/zero-hour/campaign/GET /api/challenges/ |
/teams | GET /api/teams/ |
/news | GET /api/blog-posts/ |
/news/:slug | GET /api/blog-posts/{slug}/GET /api/blog-feedbacks/ |
/csema-labs | none |
/contact | none |
/seasons | GET /api/zero-hour/campaign/ |
/welcome | GET /api/events/live-online/GET /api/events/my-live-registration/GET /api/accounts/onboarding/status/GET /api/accounts/api_weekly_progress/GET /api/onboarding/survey/journey/GET /api/zero-hour/campaign/GET /api/zero-hour/progress/GET /api/learning-paths/GET /api/challenges/GET /api/events/ |
/dashboard/admin-panel/system-health | GET /api/admin-panel/system-health/ |
/dashboard/admin-panel/moderation | GET /api/admin-panel/integrity-flags/ |
/dashboard/admin-panel/contact-messages | GET /api/admin-panel/contact-messages/ |
/dashboard/admin-panel/waitlist | GET /api/admin-panel/exam-waitlist/ |
/dashboard/admin-panel/live-ops | GET /api/admin-panel/live-events/ |
/dashboard/admin-panel/revenue | GET /api/admin-panel/revenue-summary/ |
/dashboard/admin-panel/challenges | GET /api/categories/GET /api/challenges-admin/ |
/dashboard/admin-panel/machine-labs | GET /api/redteam/admin/labs/meta/GET /api/redteam/admin/labs/ |
/dashboard/admin-panel/bug-bounty | GET /api/bug-bounty/admin/submissions/ |
/dashboard/admin-panel/tools | GET /api/jobs/GET /api/study-materials/GET /api/blog-posts/GET /api/interviews/GET /api/battleground/sessions/GET /api/challenges/ |
/dashboard/learning/create | GET /api/onboarding/survey/job_roles/GET /api/exam/api/exams/GET /api/categories/GET /api/challenges/GET /api/learning-paths/ |
Current core routes in use (208), by new package
A ✓ means that a page load in the crawl called the route.
(feature admin.go) · 15 routes
| Method | Current route | Django app | Seen |
|---|---|---|---|
| GET | /api/admin-panel/contact-messages/ | admin_panel | ✓ |
| DELETE | /api/admin-panel/contact-messages/{contact_id}/ | admin_panel | |
| GET | /api/admin-panel/exam-waitlist/ | admin_panel | ✓ |
| GET | /api/admin-panel/integrity-flags/ | admin_panel | ✓ |
| POST | /api/admin-panel/integrity-flags/{flag_id}/resolve/ | admin_panel | |
| GET | /api/admin-panel/live-events/ | admin_panel | ✓ |
| GET | /api/admin-panel/redteam/subscriptions/ | admin_panel | |
| POST | /api/admin-panel/redteam/subscriptions/{subscription_id}/force-expire/ | admin_panel | |
| POST | /api/admin-panel/redteam/subscriptions/{subscription_id}/suspend/ | admin_panel | |
| POST | /api/admin-panel/redteam/subscriptions/{subscription_id}/unsuspend/ | admin_panel | |
| GET | /api/admin-panel/revenue-summary/ | admin_panel | ✓ |
| GET | /api/admin-panel/support-messages/ | admin_panel | |
| GET | /api/admin-panel/system-health/ | admin_panel | ✓ |
| GET | /api/admin-panel/users/ | admin_panel | |
| GET POST | /api/admin-panel/users/{user_id}/moderation/ | admin_panel |
auth · 49 routes
| Method | Current route | Django app | Seen |
|---|---|---|---|
| GET | /accounts/login/ | allauth | ✓ |
| POST | /api/accounts/api/contact/ | users | |
| GET | /api/accounts/api/pricing/ | users | ✓ |
| GET | /api/accounts/api_category_progress/ | users | |
| GET | /api/accounts/api_daily_activity/ | users | ✓ |
| POST | /api/accounts/api_delete_account/ | users | |
| POST | /api/accounts/api_github_auth/ | users | |
| POST | /api/accounts/api_google_auth/ | users | |
| GET | /api/accounts/api_leaderboard/ | users | ✓ |
| POST | /api/accounts/api_logout/ | users | |
| GET | /api/accounts/api_partner_students/ | users | |
| GET PUT | /api/accounts/api_profile/ | users | ✓ |
| GET | /api/accounts/api_skill_radar/ | users | ✓ |
| GET | /api/accounts/api_solved_by_category/ | users | |
| POST | /api/accounts/api_sso_exchange/ | users | |
| POST | /api/accounts/api_sso_token/ | users | |
| GET | /api/accounts/api_weekly_progress/ | users | ✓ |
| POST | /api/accounts/auth/login/ | users | ✓ |
| POST | /api/accounts/auth/password-reset/confirm/ | users | |
| POST | /api/accounts/auth/password-reset/request/ | users | |
| POST | /api/accounts/auth/password/ | users | |
| POST | /api/accounts/auth/register/ | users | |
| POST | /api/accounts/auth/resend-verification/ | users | |
| POST | /api/accounts/auth/verify-email/ | users | |
| GET | /api/accounts/available-challenge-badges/ | users | ✓ |
| GET | /api/accounts/dream_job_pathway/ | users | |
| POST | /api/accounts/initiate_subscription_payment/ | users | |
| GET | /api/accounts/mailing/available_users/ | users | |
| POST | /api/accounts/mailing/groups/ | users | |
| DELETE POST PUT | /api/accounts/mailing/groups/{pk}/ | users | |
| POST | /api/accounts/mailing/groups/{pk}/add_users/ | users | |
| POST | /api/accounts/mailing/groups/{pk}/remove_users/ | users | |
| POST | /api/accounts/mailing/send_group/ | users | |
| POST | /api/accounts/mailing/send_manual/ | users | |
| POST | /api/accounts/mailing/templates/ | users | |
| DELETE POST PUT | /api/accounts/mailing/templates/{pk}/ | users | |
| POST | /api/accounts/notifications/ | users | ✓ |
| DELETE | /api/accounts/notifications/delete-all/ | users | |
| DELETE | /api/accounts/notifications/delete/{notification_id}/ | users | |
| POST | /api/accounts/notifications/mark-all-read/ | users | |
| POST | /api/accounts/notifications/mark-read/{notification_id}/ | users | |
| POST | /api/accounts/onboarding/complete/ | users | |
| GET | /api/accounts/onboarding/path/ | users | ✓ |
| POST | /api/accounts/onboarding/status/ | users | ✓ |
| GET | /api/accounts/player_detailed_stats/{user_id}/ | users | |
| GET | /api/accounts/public_profile/{user_id}/ | users | |
| GET | /api/accounts/session-info/ | users | |
| POST | /api/accounts/verify_subscription_payment/ | users | |
| POST | /api/token/refresh/ | rest_framework_simplejwt | ✓ |
billing · 3 routes
| Method | Current route | Django app | Seen |
|---|---|---|---|
| GET | /api/offers/current/ | offers | ✓ |
| GET | /api/offers/validate-coupon/ | offers | |
| GET | /api/offers/{pk}/ | offers | ✓ |
compete · 14 routes
| Method | Current route | Django app | Seen |
|---|---|---|---|
| GET | /api/team-invites/ | teams | |
| POST | /api/team-invites/{pk}/accept/ | teams | |
| POST | /api/team-invites/{pk}/reject/ | teams | |
| POST | /api/teams/ | teams | ✓ |
| GET | /api/teams/{pk}/ | teams | ✓ |
| POST | /api/teams/{pk}/announcement/create/ | teams | |
| POST | /api/teams/{pk}/invite/ | teams | |
| POST | /api/teams/{pk}/join/ | teams | |
| POST | /api/teams/{pk}/leave/ | teams | |
| POST | /api/teams/{pk}/manage/ | teams | |
| GET | /api/teams/{pk}/members/ | teams | |
| POST | /api/teams/{pk}/regenerate-invite-code/ | teams | |
| POST | /api/teams/{pk}/request/ | teams | |
| GET | /api/teams/{pk}/requests/ | teams |
events · 53 routes
| Method | Current route | Django app | Seen |
|---|---|---|---|
| GET POST | /api/events/ | events | ✓ |
| GET | /api/events/capacity-options/ | events | |
| GET | /api/events/library-challenges/ | events | |
| GET | /api/events/live-online/ | events | ✓ |
| GET | /api/events/my-collaborations/ | events | ✓ |
| GET | /api/events/my-live-registration/ | events | ✓ |
| POST | /api/events/request-event-credit/ | events | |
| GET POST | /api/events/{pk}/ | events | ✓ |
| POST | /api/events/{pk}/admin/challenges/{challenge_id}/force-unlock/ | events | |
| GET | /api/events/{pk}/all-teams/ | events | |
| DELETE | /api/events/{pk}/all-teams/{team_id}/ | events | |
| POST | /api/events/{pk}/allowed-emails/ | events | |
| GET POST | /api/events/{pk}/announcements/ | events | |
| DELETE PATCH | /api/events/{pk}/announcements/{announcement_id}/ | events | |
| GET POST | /api/events/{pk}/certificate-template/ | events | |
| GET | /api/events/{pk}/challenge-analysis/ | events | |
| GET | /api/events/{pk}/challenges/ | events | |
| GET | /api/events/{pk}/challenges/{challenge_id}/ | events | |
| POST | /api/events/{pk}/challenges/{challenge_id}/hints/{hint_id}/unlock/ | events | |
| POST | /api/events/{pk}/challenges/{challenge_id}/submit_flag/ | events | |
| POST | /api/events/{pk}/create_category/ | events | |
| GET POST | /api/events/{pk}/event-teams/ | events | |
| GET | /api/events/{pk}/event-teams/{team_id}/ | events | |
| POST | /api/events/{pk}/event-teams/{team_id}/join/ | events | |
| GET POST | /api/events/{pk}/event-teams/{team_id}/requests/ | events | |
| GET | /api/events/{pk}/flag-submission-stats/ | events | |
| GET | /api/events/{pk}/gallery/ | events | |
| POST | /api/events/{pk}/hints/create/ | events | |
| GET | /api/events/{pk}/leaderboard/ | events | |
| GET | /api/events/{pk}/my-certificate/ | events | |
| GET | /api/events/{pk}/my-stats/ | events | |
| GET | /api/events/{pk}/my-team/ | events | |
| GET POST | /api/events/{pk}/my-team/chat/ | events | |
| POST | /api/events/{pk}/my-team/kick/ | events | |
| POST | /api/events/{pk}/my-team/leave/ | events | |
| POST | /api/events/{pk}/my-team/settings/ | events | |
| POST | /api/events/{pk}/my-team/transfer-captain/ | events | |
| POST | /api/events/{pk}/purchase-challenges/ | events | |
| POST | /api/events/{pk}/register/ | events | |
| GET | /api/events/{pk}/registrations/ | events | |
| POST | /api/events/{pk}/send_reminder_emails/ | events | |
| GET | /api/events/{pk}/solves/ | events | |
| POST | /api/events/{pk}/support_messages/ | events | |
| POST | /api/events/{pk}/support_messages/{message_id}/resolve/ | events | |
| GET | /api/events/{pk}/unlocked-hints/ | events | |
| POST | /api/events/{pk}/upload-certificate-image/ | events | |
| POST | /api/events/{pk}/verify-challenges-purchase/ | events | |
| POST | /api/events/{pk}/verify-payment/ | events | |
| GET POST | /api/events/{pk}/warnings/ | events | |
| DELETE PATCH | /api/events/{pk}/warnings/{warning_id}/ | events | |
| GET POST | /api/events/{pk}/waves/ | events | |
| DELETE PATCH | /api/events/{pk}/waves/{wave_id}/ | events | |
| POST | /events/{event_id}/unregister/ | events |
labs · 18 routes
| Method | Current route | Django app | Seen |
|---|---|---|---|
| GET | /api/redteam/admin/labs/ | redteam_labs | ✓ |
| GET | /api/redteam/admin/labs/meta/ | redteam_labs | ✓ |
| GET | /api/redteam/admin/labs/preview/ | redteam_labs | |
| GET | /api/redteam/admin/labs/snapshot/rebuild/ | redteam_labs | |
| GET | /api/redteam/admin/labs/{challenge_id}/ | redteam_labs | ✓ |
| GET | /api/redteam/admin/labs/{challenge_id}/test-launch/ | redteam_labs | |
| GET | /api/redteam/certificate/ | redteam_labs | |
| GET | /api/redteam/credits/ | redteam_labs | ✓ |
| GET | /api/redteam/labs/ | redteam_labs | |
| GET | /api/redteam/labs/{challenge_id}/ | redteam_labs | |
| GET | /api/redteam/labs/{challenge_id}/certificate/ | redteam_labs | |
| GET POST | /api/redteam/labs/{challenge_id}/start/ | redteam_labs | |
| GET POST | /api/redteam/labs/{challenge_id}/stop/ | redteam_labs | |
| GET | /api/redteam/machines/ | redteam_labs | ✓ |
| GET | /api/redteam/machines/{challenge_id}/ | redteam_labs | ✓ |
| GET | /api/redteam/session/ | redteam_labs | ✓ |
| GET | /api/redteam/session/heartbeat/ | redteam_labs | |
| GET | /api/redteam/subscription/status/ | redteam_labs |
learn · 24 routes
| Method | Current route | Django app | Seen |
|---|---|---|---|
| GET | /api/coding/exercises/ | coding | ✓ |
| GET | /api/jobs/ | learning | ✓ |
| DELETE GET | /api/jobs/{pk}/ | learning | |
| GET | /api/learning-paths/ | learning | ✓ |
| GET | /api/learning-paths/next_drop/ | learning | |
| POST | /api/learning-paths/scbtp-pathway/ | learning | |
| GET POST | /api/learning-paths/{pk}/ | learning | ✓ |
| GET | /api/quizzes/{pk}/ | learning | |
| POST | /api/quizzes/{pk}/check_mcq/ | learning | |
| POST | /api/quizzes/{pk}/check_saq/ | learning | |
| POST | /api/quizzes/{pk}/submit/ | learning | |
| GET POST | /api/shell-labs/modules/{module_id}/ | shell_labs | |
| PUT | /api/shell-labs/modules/{module_id}/file/ | shell_labs | |
| POST | /api/shell-labs/tasks/{task_id}/check/ | shell_labs | |
| POST | /api/shell-labs/tasks/{task_id}/solution/ | shell_labs | |
| GET | /api/study-materials/ | learning | ✓ |
| DELETE GET | /api/study-materials/{pk}/ | learning | |
| POST | /learning/api/learning/gns3/session/ | learning | |
| POST | /learning/api/learning/modules/{module_id}/complete_progress/ | learning | |
| POST | /learning/api/learning/modules/{module_id}/gns3-flag/ | learning | |
| GET | /learning/api/learning/paths/{path_id}/practical/ | learning | ✓ |
| POST | /learning/api/learning/paths/{path_id}/practical/{challenge_id}/ | learning | |
| POST | /learning/api/learning/paths/{path_id}/practical/{challenge_id}/submit/ | learning | |
| POST | /learning/modules/{module_id}/verify-lab-completion/ | learning |
practice · 17 routes
| Method | Current route | Django app | Seen |
|---|---|---|---|
| GET | /api/categories/ | challenges | ✓ |
| GET POST | /api/challenges-admin/ | challenges | ✓ |
| DELETE PATCH | /api/challenges-admin/{pk}/ | challenges | |
| GET | /api/challenges/ | challenges | ✓ |
| GET | /api/challenges/next_drop/ | challenges | |
| GET | /api/challenges/trivarna/ | challenges | |
| POST | /api/challenges/trivarna/redeem/ | challenges | |
| GET | /api/challenges/trivarna/writeup/ | challenges | |
| GET | /api/challenges/{pk}/ | challenges | ✓ |
| POST | /api/challenges/{pk}/hints/{hint_id}/unlock/ | challenges | |
| GET | /api/challenges/{pk}/rewards/ | challenges | |
| GET POST | /api/challenges/{pk}/submit_flag/ | challenges | |
| GET POST | /api/challenges/{pk}/submit_machine_flag/ | challenges | |
| GET | /api/series/ | challenges | |
| GET | /api/series/{pk}/ | challenges | |
| GET | /api/stats/ | challenges | ✓ |
| GET | /api/tags/ | challenges |
community + onboarding (auth) · 15 routes
| Method | Current route | Django app | Seen |
|---|---|---|---|
| GET | /api/ambassador/ | ambassador | |
| POST | /api/ambassador/claim_referral/ | ambassador | |
| GET POST | /api/ambassador/me/ | ambassador | ✓ |
| GET | /api/ambassador/referrals/ | ambassador | |
| GET POST | /api/ambassador/{id}/ | ambassador | ✓ |
| GET | /api/onboarding/survey/admin_skill_analytics/ | onboarding | |
| GET | /api/onboarding/survey/job_roles/ | onboarding | ✓ |
| GET | /api/onboarding/survey/journey/ | onboarding | ✓ |
| GET | /api/onboarding/survey/pathway/ | onboarding | |
| GET | /api/onboarding/survey/report/ | onboarding | |
| POST | /api/onboarding/survey/skip/ | onboarding | |
| POST | /api/onboarding/survey/submit/ | onboarding | |
| GET POST | /api/onboarding/survey/{pk}/ | onboarding | ✓ |
| DELETE POST | /api/waitlist/{code}/ | exam_waitlist | ✓ |
| POST | /api/waitlist/{code}/public/ | exam_waitlist |