Overview
Concrete tool for constructing and running the CyberStrikeAI server provided by the internal/app package.
Description
app.New is the composition root: it takes a parsed config, a logger, and a config file path, and returns a fully-wired *App holding the Gin router, SQLite database, RBAC-attached auth manager, MCP server, external MCP manager, agent, C2 manager, robot handlers, audit service, and storage handler. RunWithContext starts the MCP and main HTTP servers (with optional TLS/HTTP2 and HTTP→HTTPS redirect), blocks until the context is cancelled (SIGINT/SIGTERM), and performs a 10-second graceful shutdown of both servers.
Usage
- Deployment: call
New from cmd/server/main.go after loading config, then RunWithContext(ctx) to serve.
- Self-update restart: after an in-place update, call
New again to re-wire subsystems against the new code, then RunWithContext.
- First boot:
New creates the database directory, reconciles the schema, and bootstraps the admin password / MCP auth token.
Code Reference
Source Location
- Repository: CyberStrikeAI
- File: internal/app/app.go
- Lines: New L81-697, RunWithContext L698-790
Signature
type App struct {
config *config.Config
logger *logger.Logger
router *gin.Engine
mcpServer *mcp.Server
externalMCPMgr *mcp.ExternalMCPManager
agent *agent.Agent
executor *security.Executor
db *database.DB
auth *security.AuthManager
auditSvc *audit.Service
c2Manager *c2.Manager
// ... robot handlers, storage handler, knowledge manager ...
}
func New(cfg *config.Config, log *logger.Logger, configPath string) (*App, error)
func (a *App) RunWithContext(ctx context.Context) error
func (a *App) Shutdown() error
Import
import "cyberstrike-ai/internal/app"
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| cfg |
*config.Config |
Yes |
Parsed config (Server/Database/MCP/Auth/AI/Robots/Project)
|
| log |
*logger.Logger |
Yes |
Structured zap logger
|
| configPath |
string |
Yes |
Path to config.yaml for live edits
|
| ctx |
context.Context |
Yes (RunWithContext) |
Cancellable context for graceful shutdown
|
Outputs
| Name |
Type |
Description
|
| New returns |
*App, error |
Fully-wired application, or error
|
| RunWithContext returns |
error |
Non-nil only on server startup/TLS failure
|
| Side effects |
Running servers |
MCP HTTP server + main HTTP/HTTPS server
|
Usage Examples
Standard Deployment
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer cancel()
cfg, err := config.Load("config.yaml")
if err != nil {
log.Fatal(err)
}
a, err := app.New(cfg, logger, "config.yaml")
if err != nil {
log.Fatal(err)
}
if err := a.RunWithContext(ctx); err != nil {
log.Fatal(err)
}
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.