How apache/answer works
Purpose and Runtime
Apache Answer is a self-hosted Q&A, help-center, and knowledge-management platform. It ships as a Go backend plus React frontend, typically packaged in a Docker image and deployed with persistent /data storage. Primary runtime/build entry points are cmd/main.go, cmd/command.go, and cmd/wire_gen.go; container startup is defined by Dockerfile and script/entrypoint.sh.
Application Composition and Startup
The Go executable uses Cobra commands and Google Wire-generated dependency injection. Startup assembles configuration, repositories, services, HTTP server, scheduled work, and routes through provider modules rather than a single monolith initializer. Installation is a first-class server mode that can bootstrap configuration from environment values.
• cmd/main.go
• cmd/wire.go
• internal/install/install_server.go
HTTP, UI, and API Boundary
The backend hosts API, static/UI, Swagger, template-rendered, plugin, and MCP endpoints. Requests pass through shared middleware for recovery, authentication, API keys, language, rate limiting, and specialized plugin/MCP access controls before controllers invoke services. The React SPA is the principal interactive client; server HTML templates support rendered/public pages and SEO-oriented views.
• internal/base/server/http.go
• internal/router/config.go
• internal/router/mcp_router.go
• ui/src/router/routes.ts
• ui/static.go
Core Domain and Layering
Domain operations follow a controller → service → repository → entity pattern. Controllers expose public/admin workflows; services enforce content, permissions, revisions, reviews, voting, tags, collections, badges, notifications, and user/account policies; repositories persist and query entities. API schemas form the request/response boundary, distinct from persistence entities.
• internal/controller/question_controller.go
• internal/service/content/question_service.go
• internal/repo/question/question_repo.go
• internal/entity/question_entity.go
• internal/schema/question_schema.go
Persistence, Installation, and Configuration
Persistent state includes users/authentication, questions/answers/comments, tags, revisions, reviews, notifications, plugin configuration/KV data, API keys, and site configuration. Versioned migrations initialize and evolve the schema; installation can be driven interactively or from environment settings. Configuration defaults and runtime loading are centralized outside individual features.
• configs/config.yaml
• configs/config.go
• internal/migrations/migrations.go
• internal/migrations/init_data.go
• internal/base/conf/conf.go
Asynchronous and Derived Work
In-process queue abstractions and cron support decouple side effects from request handling: activity tracking, event processing, notification/email delivery, search indexing, and vector/embedding synchronization. This is a material boundary for changes that create content or user events: synchronous domain writes can trigger downstream queue/event work.
• internal/base/queue/queue.go
• internal/base/cron/cron.go
• internal/service/eventqueue/event_queue.go
• internal/service/notification/notification_service.go
• internal/service/vector_sync/vector_sync.go
Extensibility and External Integrations
A typed plugin contract exposes replaceable or additive capabilities including authentication/user center, CAPTCHA, CDN/storage/upload, search/vector search, parsers/rendering, connectors/importers, review, filtering, notifications, and plugin KV storage. AI conversations, embeddings, and MCP routes provide AI-agent-facing integration points. Implementations can therefore cross external boundaries without embedding provider-specific logic into core content services.
• plugin/plugin.go
• plugin/search.go
• plugin/vector_search.go
• internal/service/ai_conversation/ai_conversation_service.go
• internal/controller/mcp_controller.go
Deployment and Frontend Delivery
The frontend is a React/TypeScript application with route-level public, user, review, install, and administration surfaces; its service clients call backend APIs. Docker Compose and Helm provide local and Kubernetes deployment paths, with deployment, service, ingress, PVC, and autoscaling manifests.
• ui/src/index.tsx
• ui/src/services/index.ts
• docker-compose.yaml
• charts/templates/deployment.yaml
• charts/templates/pvc.yaml
Main entry points: main.go Go application · config.go API, UI & MCP routes · question_service.go Domain services · event_queue.go Event queue
Components 22
Startup & Configuration
- Go application · Builds server modes and dependency graph.
cmd/main.go - Install server · Initializes configuration from interactive or environment input.
internal/install/install_server.go - Runtime configuration
internal/base/conf/conf.go - Migrations & seed data
internal/migrations/migrations.go
HTTP & Frontend
- HTTP server & middleware · Applies authentication, rate limits, language, recovery, and access controls.
internal/base/server/http.go - API, UI & MCP routes
internal/router/config.go - Controllers · Public and administration endpoints invoke domain operations.
internal/controller/question_controller.go - React SPA
ui/src/index.tsx - Frontend service clients
ui/src/services/index.ts - Static UI & templates · Hosts SPA assets and rendered public pages.
ui/static.go
Core Domain
- Domain services · Content, permissions, revisions, reviews, voting, tags, and account policies.
internal/service/content/question_service.go - API schemas
internal/schema/question_schema.go - Repositories
internal/repo/question/question_repo.go - Persistence entities
internal/entity/question_entity.go
Async Work
- Event queue · Decouples side effects from synchronous domain writes.
internal/service/eventqueue/event_queue.go - Cron scheduler
internal/base/cron/cron.go - Notification delivery
internal/service/notification/notification_service.go - Vector synchronization
internal/service/vector_sync/vector_sync.go
Extensions & AI
- Plugin contracts · Allows provider-specific auth, storage, search, rendering, and integrations.
plugin/plugin.go - AI conversations & MCP
internal/service/ai_conversation/ai_conversation_service.go
Deployment
- Container runtime · Starts the application with persistent data storage.
Dockerfile - Kubernetes deployment · Deployment is paired with persistent-volume manifests.
charts/templates/deployment.yaml
Connections 23
- Container runtime → Go application: starts
- Kubernetes deployment → Container runtime: runs image
- Go application → Runtime configuration: loads
- Go application → Install server: serves install mode
- Install server → Migrations & seed data: initializes
- Go application → Migrations & seed data: applies
- Go application → HTTP server & middleware: assembles
- HTTP server & middleware → API, UI & MCP routes: dispatches
- API, UI & MCP routes → Controllers: maps requests
- API, UI & MCP routes → Static UI & templates: serves
- React SPA → Frontend service clients: uses
- Frontend service clients → HTTP server & middleware: calls APIs
- Controllers → API schemas: binds
- Controllers → Domain services: invokes
- Domain services → Repositories: persists through
- Repositories → Persistence entities: maps
- Domain services → Event queue: publishes side effects
- Event queue → Notification delivery: delivers
- Event queue → Vector synchronization: indexes
- Cron scheduler → Event queue: triggers jobs
- Domain services → Plugin contracts: uses capabilities
- API, UI & MCP routes → AI conversations & MCP: exposes AI/MCP
- AI conversations & MCP → Plugin contracts: uses providers