This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
WeCoding IAM is an Identity and Access Management system written in Go (backend) with a React/TypeScript frontend. It provides RBAC access control (Casbin-based), multiple authentication methods (JWT, Basic, SecretKey), audit logging, and MFA support (TOTP).
make build # Build all binaries for host platform
make lint # Run golangci-lint
make test # Run unit tests with race detection and coverage
make cover # Run tests + generate HTML coverage report
make format # Run gofmt, goimports, golines, swag fmt
make tidy # go mod tidy
make gen # Run code generation (error codes, Swagger docs)
make swag # Generate Swagger docs
make serve-swagger # Serve Swagger UI
make all # Full pipeline: tidy gen add-copyright format lint build
make clean # Remove build output (_output/)cd web
pnpm install
pnpm start # Start dev server (UMI_ENV=dev)
pnpm build # Production build
pnpm lint # ESLint + Prettier + TypeScript check
pnpm test # Jest unit testsgo test ./internal/authz/... -v -run TestRoleCreateAll services are accessed through a central driver.Registry (internal/driver/registry_default.go), which uses sync.Once for lazy initialization. The registry wires up:
- L1 (Infrastructure): Logger (logrus), Config
- L1 (Low-level): Identity, Session, Self-service flows
- L2: Authorization (Casbin RBAC), Role, Policy
- L3: Token management, Lockout (brute-force protection), Audit, Courier (webhooks)
cmd/apiserver/main.go → apiserver.Run() → creates driver.Registry → initializes services → creates Gin router → starts HTTP server with graceful shutdown.
All REST API routes are in internal/api/router.go under /api/v1. Global middleware includes: RequestID, Logging, Recovery, CORS. Key route groups: /identities, /sessions, /login, /roles, /policies, /authz/check, /tokens, /audit/events.
GORM-based SQL implementations in internal/persistence/sql/ support MySQL and SQLite (switchable via config).
Casbin-based RBAC in internal/authz/. Roles are granted to users; policies combine resources, operations, and authorization effects.
- Registry: All services accessed via
driver.Registry— never instantiate services directly - Config: All config structs in
internal/config/— only Server (host, port) and Database (driver, dsn) - Error Codes: Generated in
pkg/code/— do not edit manually - Graceful Shutdown: Use
pkg/shutdown/manager for shutdown callbacks
Server config: conf/apiserver.yaml. Config fields:
server:
host: 127.0.0.1
port: 8080
database:
driver: sqlite # or mysql
dsn: /path/to/database- Go 1.24, Node >= 20.0.0, pnpm 8.5.1
- Backend entry:
cmd/apiserver/main.go - Frontend entry:
web/(Umi.js 4 + React 19 + Ant Design) - Build output:
_output/ - API docs:
api/swagger/(Swagger 2.0)