CyberCortex is built as a Discord-native cybersecurity learning assistant that balances three goals:
- Practical value for learners preparing in authorized environments
- Consistent structure across outputs (roadmaps, study plans, quizzes, red-team guidance)
- Safety controls for dual-use cybersecurity topics
Discord User
-> Slash Command
-> Command Handler
-> Input Guard + Scope Validation + Rate Limiter
-> Gemini Service (prompt orchestration, retries, quality checks)
-> Formatter + Smart Splitter
-> Discord Reply / Follow-up
- Safety-first request handling before model invocation
- Structured AI outputs instead of free-form responses
- Search-grounded links for labs, resources, and news
- Graceful degradation under provider/API failures
- Discord-friendly formatting and chunk delivery
- User triggers a slash command.
- Command module validates required options and normalizes input.
inputGuardsanitizes text and blocks unsafe prompt patterns.rateLimiterenforces per-user request quotas.- Command routes to either:
runAICommand+geminiServicefor generated content, or- Search services (
labsSearchService,resourceSearchService,newsService) for grounded content.
- Output is formatted and split using
smartSplitMessage. - Response is sent through Discord interaction reply/edit/follow-up APIs.
| Layer | Responsibility | Key Files |
|---|---|---|
| Bot Entry | Startup, Discord client events, service wiring | src/index.js |
| Command Surface | Slash command definitions and per-command execution | src/commands/* |
| Command Dispatch | Dynamic command loading and routing | src/handlers/commandHandler.js |
| Input and Abuse Controls | Sanitization, prompt-injection checks, rate limiting | src/utils/inputGuard.js, src/utils/rateLimiter.js |
| AI Orchestration | Prompt construction, model fallback, retries, quality validation | src/services/geminiService.js, src/services/prompts/* |
| Grounded Search | Candidate retrieval for labs/resources/news | src/services/labsSearchService.js, src/services/resourceSearchService.js, src/services/newsService.js |
| Output Delivery | Markdown normalization, chunk-safe Discord delivery | src/utils/formatResponse.js, src/utils/smartSplitMessage.js, src/utils/discordResponse.js |
| Error Handling | User-safe failure responses and logging | src/handlers/errorHandler.js, src/utils/logger.js |
| Configuration | Environment loading and validation | src/config/env.js |
- Input sanitation and prompt-injection pattern blocking
- Authorized-scope checks for sensitive red-team style requests
- Guardrails in prompt templates to avoid weaponized output
- Grounding constraints so generated links must match fetched candidates
- Defensive framing for dual-use topics
- Multi-key API support and model fallback candidates
- Exponential backoff retries for transient provider errors
- Quality validation + refinement pass for structured commands
- Response length/chunk management for Discord limits
CyberCortex is modular by command and service. New features typically require:
- Add a command file under
src/commands. - Add a prompt builder under
src/services/prompts(if AI-generated). - Extend
geminiServicequality/validation rules (if structured output). - Register command and update docs.
- Rate limiting is in-memory (single-process scope)
- Prompt-injection detection is rule-based
- External dependency risk from model/search/feed providers
- No persistent memory by design (privacy-first)
- Redis-backed distributed rate limiting
- Deeper policy-driven prompt risk scoring
- Optional analytics for command usage and quality outcomes
- Expanded integration tests for command output contracts