This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
MX Space is a personal blog server application built with NestJS, MongoDB, and Redis. This is a monorepo containing the core server application and related packages. The main application is located in apps/core/.
- Dashboard (admin-vue3):
../admin-vue3— 后台管理面板,Vue 3 项目 - Frontend (Shiroi):
../Shiroi— 主站前端 (Next.js) - haklex:
../haklex(standalone) /../Shiroi/haklex(original host) — Rich editor packages (@haklex/*)
mx-core uses @haklex/rich-headless (zero-React, server-side only) for Lexical JSON processing:
helper.lexical.service.ts—createHeadlessEditor()+allHeadlessNodes+$toMarkdown()for JSON → Markdown conversionai-translation/lexical-translation-parser.ts— AI translation content parsing- After haklex releases, update the pinned version in
apps/core/package.json
- Node.js: >= 22 (see
.nvmrcin root) - pnpm: Use Corepack (
corepack enable)
All commands should be run from the repository root unless specified otherwise.
pnpm dev- Start development serverpnpm build- Build the projectpnpm bundle- Create production bundlepnpm test- Run all testspnpm lint- Run ESLintpnpm format- Format code with Prettier
# Run a single test file
pnpm test -- test/src/modules/user/user.service.spec.ts
# Run tests matching a pattern
pnpm test -- --testNamePattern="should create user"
# Run tests in watch mode
pnpm -C apps/core run test:watchnpm run start:debug- Start with debug modenpm run start:cluster- Start in cluster modenpm run repl- Start REPL mode
apps/core/src/modules/- Business logic modules (auth, posts, comments, etc.)apps/core/src/processors/- Infrastructure services (database, redis, gateway, helpers)apps/core/src/common/- Shared utilities (guards, interceptors, decorators)apps/core/src/migration/- Database migration scriptsapps/core/test/- Test files and mockspackages/- Shared packages (api-client, webhook)
API Route Prefix: The @ApiController() decorator adds /api/v{version} prefix in production but no prefix in development. This allows direct access during development.
Processors: Infrastructure services organized in processors/:
database/- MongoDB connection and model registrationredis/- Redis caching and pub/subgateway/- WebSocket gateways for real-time featureshelper/- Utility services (email, image, JWT, etc.)
Database Models: Uses Mongoose with TypeGoose. All models extend a base with _id, created, updated fields.
Authentication: JWT-based with decorators @Auth() for route protection and @CurrentUser() for accessing the authenticated user.
ResponseInterceptor auto-wraps responses:
- Array →
{ data: [...] }(always wrapped) - Object → returned directly (no wrapper)
- @Paginator →
{ data: [...], pagination: {...} }(requiresmodel.paginate()result) - @Bypass → skips all transformation
JSONTransformInterceptor converts all keys to snake_case (e.g., createdAt → created_at)
Uses Vitest with in-memory MongoDB and Redis.
Use createE2EApp helper from test/helper/create-e2e-app.ts:
const proxy = createE2EApp({
imports: [...],
controllers: [MyController],
providers: [...],
models: [MyModel],
pourData: async (modelMap) => {
// Insert test data
const model = modelMap.get(MyModel)!.model
await model.create({ ... })
}
})
it('should work', async () => {
const res = await proxy.app.inject({ method: 'GET', url: '/...' })
expect(res.statusCode).toBe(200)
})test/mock/modules/- Module-level mocks (auth, redis, gateway)test/mock/processors/- Processor mocks (email, event)test/helper/- Test utilities (db-mock, redis-mock)
Migration scripts in src/migration/version/ are version-based and run automatically on startup when needed.
Configuration via src/app.config.ts supports:
- Environment variables
- Command line arguments
- YAML configuration files