# synawkx/shazam architecture

> Architecture diagram of the GitHub repository synawkx/shazam, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/synawkx/shazam
- Repository: https://github.com/synawkx/shazam

## Overview

##### Project type and purpose
- This is a two-component remote agent system (“shazam v0.1”):
– A Windows-targeted C-based agent (src/) that performs tasks and communicates over HTTP.
– A Python-based command-and-control (C2) server (c2/app.py) that issues commands and collects data.

##### File structure
- Top level
– install.bat: Windows installer script for the agent
– shazam.log: sample or runtime log file
- c2/ directory (C2 server)
– app.py: Python HTTP server entry point
– requirements.txt: Python dependencies (e.g., Flask or requests server libraries)
- src/ directory (agent code)
– shazam.c / shazam.h: core agent logic
– winsys.h: Windows-specific system calls and APIs
– lib/: reusable C modules
- common.c/.h: utility functions
- connection.c/.h: socket-level connection management
- http.c/.h: HTTP client implementation

##### Main components
a. Agent (C executable)
– Core module (shazam.c) orchestrates tasks
– Windows system interface (winsys.h)
– HTTP client module (lib/http) on top of connection module (lib/connection)
– Common utilities (lib/common)
b. C2 server (Python app)
– HTTP server framework (e.g., Flask/Django)
– Command handler and data store or in-memory state
– External dependencies (requirements.txt)
c. Deployment artifacts
– install.bat installs the agent on Windows endpoints
– Logs (shazam.log) stored locally or forwarded

##### Relationships and data flows
- Agent startup → reads config (hard-coded or via registry/files)
- Agent → performs system calls via winsys → collects data
- Agent → uses lib/http → opens TCP connection → sends HTTP requests to C2
- C2 server → listens on HTTP endpoint → parses requests → issues commands or stores data
- Agent polls or keeps long-lived connections based on design in connection.c

##### Architectural patterns and design principles
- Modular C library layering (common → connection → http → core)
- Separation of concerns: system interface vs. networking vs. core logic
- Client-server over HTTP (REST-style or custom)
- Simple deployment script ensures repeatable installation

##### Technologies, frameworks, and libraries
- Native C (gcc/clang on Windows via MinGW/MSVC)
- Winsock or Windows API for networking (lib/connection + winsys)
- HTTP parsing and formatting in C (lib/http)
- Python HTTP framework (Flask or similar) for C2
- install.bat for Windows automation

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Agent and C2 swim lanes
    subgraph "Agent (On-Device)"
        direction TB
        Installer["install.bat"]:::deployment
        subgraph "Agent Components"
            direction TB
            Core["Core Module\n(shazam.c/.h)"]:::cmodule
            Winsys["Windows System Interface\n(winsys.h)"]:::osapi
            HTTPClient["HTTP Client Module\n(lib/http.c/.h)"]:::cmodule
            Connection["Connection Module\n(lib/connection.c/.h)"]:::cmodule
            Common["Common Utilities Module\n(lib/common.c/.h)"]:::cmodule
        end
        LogFile["shazam.log"]:::log
    end

    subgraph "C2 Server (Remote)"
        direction TB
        PythonApp["C2 Server Application\n(app.py)"]:::python
        Dependencies["C2 Dependencies\n(requirements.txt)"]:::python
        DataStore["In-Memory Data Store"]:::external
    end

    %% OS Network Stack pseudo-node
    OSStack["OS Network Stack\n(TCP/IP)"]:::osapi

    %% Flows and Relationships
    Installer -->|"Installs Agent"| Core
    Core -->|"uses"| Winsys
    Core -->|"calls"| Common
    Common -->|"builds on"| Connection
    Connection -->|"opens socket"| OSStack
    HTTPClient -->|"overlays"| Connection
    Core -->|"invokes HTTP client"| HTTPClient
    HTTPClient -->|"HTTP over TCP"| OSStack
    HTTPClient -->|"HTTP POST/GET"| PythonApp
    PythonApp -->|"Responses/Commands"| HTTPClient
    PythonApp -->|"logs/stores data"| DataStore
    Core -->|"writes logs"| LogFile

    %% Click Events
    click Core "https://github.com/synawkx/shazam/blob/master/src/shazam.c"
    click Winsys "https://github.com/synawkx/shazam/blob/master/src/winsys.h"
    click Common "https://github.com/synawkx/shazam/blob/master/src/lib/common.c"
    click Connection "https://github.com/synawkx/shazam/blob/master/src/lib/connection.c"
    click HTTPClient "https://github.com/synawkx/shazam/blob/master/src/lib/http.c"
    click PythonApp "https://github.com/synawkx/shazam/blob/master/c2/app.py"
    click Dependencies "https://github.com/synawkx/shazam/blob/master/c2/requirements.txt"
    click Installer "https://github.com/synawkx/shazam/blob/master/install.bat"
    click LogFile "https://github.com/synawkx/shazam/blob/master/shazam.log"

    %% Styles
    classDef cmodule fill:#ADD8E6,stroke:#0000FF,color:#000;
    classDef osapi fill:#90EE90,stroke:#008000,color:#000;
    classDef python fill:#FFA500,stroke:#FF8C00,color:#000;
    classDef deployment fill:#D3D3D3,stroke:#696969,color:#000,stroke-dasharray: 5 5;
    classDef log fill:#FFFACD,stroke:#FFD700,color:#000;
    classDef external fill:#F0F0F0,stroke:#A9A9A9,color:#000;
```
