How orange-cyberdefense/grepmarx works
Project Type & Purpose
• This is a full‐stack, Flask-based web application (“Grepmarx”) for security scanning (SAST & SCA).
• It provides a web UI (AdminLTE) to configure repositories, scan code, manage rules, view results and generate SBOMs.
High-Level Architecture Components
a. Client (Browser)
• HTML/CSS/JS (AdminLTE templates + custom assets under app/base/static)
• Interacts over HTTP(S).
b. Edge Layer
• Optional NGINX reverse proxy (docker nginx/grepmarx.conf)
• Routes requests to Gunicorn.
c. Web Server
• Gunicorn WSGI server (configured via gunicorn-cfg.py & supervisord.conf).
• Serves the Flask application (run.py).
d. Flask Application
• Blueprints under app/:
• base (login, nav, dashboard)
• administration (LDAP, user/repos management)
• analysis (scan submission, workbench, occurrence views)
• projects & rules (project dashboards, rule packs)
• ORM/models + forms + routes + templates/util.
• Configuration in app/config.py.
e. Database
• Relational DB (SQLite, MySQL or PostgreSQL via requirements-*.txt)
• Migrations via Alembic (migrations/).
f. Task Queue & Workers
• Redis (broker)
• Celery worker (app/celery_worker.py) scheduled by supervisor or Docker.
• Executes long‐running scan tasks asynchronously.
g. Third-Party Analysis Engines
• Semgrep (SAST)
• CycloneDX cdxgen & OWASP dep-scan (SCA/SBOM)
• scc (LOC counter)
• Application Inspector (feature discovery)
• Invoked by worker processes as CLI tools under app/third-party/.
h. Storage for Artifacts
• Scan outputs (reports, logs) written to DB or file‐system (e.g., media/).
Component Interactions & Data Flow
1. User submits scan request via Web UI →
HTTP POST → Gunicorn → Flask route (analysis blueprint)
2. Flask enqueues scan task → Celery (Redis broker)
3. Celery worker pulls task → invokes third‐party CLIs → processes results
4. Worker stores findings in Database + file storage
5. User refreshes/view results → Flask reads DB → renders templates
Architectural Patterns & Principles
• MVC-style separation: Blueprints for Controller (routes), Jinja templates for View, SQLAlchemy models as Model.
• Asynchronous Processing: Offload heavy scans to Celery workers.
• Modularization: Each feature in its own blueprint.
• Externalization of Config: .env, config.py, docker-compose.yml.
• Infrastructure as Code: Docker + Compose + supervisor configs.