Gateway module pattern
Each domain under apps/gateway/src/modules generally owns routes, validation schema, controller, service, and types. Shared middleware, infrastructure clients, models, queues, and core response/logging utilities live under src/shared; Socket.IO has its own handler/consumer tree.
Console domain pattern
apps/console/src/domains/<feature> groups API clients, components, hooks, pages, and types. Cross-domain UI, layouts, storage, query client, theme, and helpers live under src/shared. Central routing is in src/router/index.tsx.
Agent pattern
Behavior is grouped into chat, assist, agents/tools, and ingestion modules. BullMQ consumers live in workers; Redis, providers, internal API, MinIO, Qdrant, and queue clients live in infrastructure.
Placement rule
Put feature-specific behavior close to its domain. Promote code to shared only after it has a real cross-domain consumer and stable abstraction. Avoid imports that make the worker or agent depend on the gateway’s runtime module graph.
Code under ee/ has a different license. Do not move enterprise implementation into open-source paths merely to simplify imports.