# tomasz-grobelny/aacs architecture

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

- Interactive diagram: https://gitdiagram.com/tomasz-grobelny/aacs
- Repository: https://github.com/tomasz-grobelny/aacs

## Overview

1. **What this repository is**  
   AACS is a multi-process Android Auto integration stack for Linux. It sits between an Android Auto head unit, an Android Auto-capable mobile side, and local desktop/media components. The codebase is split into separate binaries so the protocol bridge, USB gadget logic, and optional input injection can be deployed independently.

2. **Top-level runtime shape**  
   The main runtime boundaries are:
   - **USB/Android Auto side**: talks to the car headunit over USB OTG.
   - **Local IPC boundary**: a Unix socket used to bridge AAServer and AAClient.
   - **Desktop integration boundary**: optional tools such as GetEvents that inject input into X11 applications.

3. **AAServer: headunit-facing core**  
   `AAServer` is the most hardware-specific component. It owns the Android Auto session with the headunit, sets up USB gadget mode, and exposes a local socket for the companion client. Its source tree includes gadget management (`Udc`, `Gadget`, `Function`, `MassStorageFunction`, `FfsFunction`), Android Auto message handling, and socket transport.

4. **AAClient: companion proxy**  
   `AAClient` is the protocol peer on the other side of the bridge. Per the README, it connects to AAServer to obtain service descriptions and forwards Android Auto traffic. Architecturally, it is the abstraction layer that lets the Android Auto session be split from the USB-facing server and extended with other transports or clients later.

5. **Shared Android Auto protocol model**  
   The `proto/` directory contains the schema for the Android Auto messages and channels: discovery, ping, input, touch, video, media, navigation, Bluetooth, sensor, and vendor extension messages. These definitions are central to the architecture because both AAServer and AAClient build their channel negotiation and payload handling around them.

6. **Channel-based processing model**  
   Both server and client use a `ChannelHandler` hierarchy with specialized handlers such as `InputChannelHandler`, `VideoChannelHandler`, and `DefaultChannelHandler`. This indicates the protocol is treated as a set of independently routed logical channels rather than a single monolithic stream. That separation is important for the diagram: one transport, multiple typed channels.

7. **USB gadget and function stack in AAServer**  
   The server-side USB path is not a generic socket server; it actively configures Linux gadget mode through low-level components like `Udc`, `Gadget`, descriptors, and USB functions. This is where the project interfaces with kernel-level USB OTG support and libusbgx-style gadget configuration. This is the boundary where the software becomes the “device” the headunit sees.

8. **Video and input integration**  
   Video is treated as a distinct path from control input. The README says AACS can stream arbitrary video to the headunit and depends on Snowmix for video mixing. Input is handled separately through touch and event channel types, with server/client handlers designed to carry touch and button events alongside media/video traffic.

9. **GetEvents: desktop input bridge**  
   `GetEvents` is a small standalone utility that listens for touch events from AAServer and replays them into a selected application using XTest. This is a clean integration boundary with X11: Android Auto touch events become desktop mouse/touch-like events without being embedded into the main server/client binaries.

10. **Certificates and session identity**  
   The `ssl/` directories contain headunit and Android Auto certificate/key pairs. This is architecturally relevant because the Android Auto session is secured, and the repo treats certificates as part of the runtime identity of each side of the bridge.

11. **Build and packaging structure**  
   The repo is organized as multiple CMake targets: `AAServer`, `AAClient`, `GetEvents`, and shared protobuf generation under `proto/`. There is also a small root-level utility layer plus scripts and docs for boot/runtime setup. The build structure mirrors the runtime decomposition, which is useful for drawing component boundaries.

12. **Operational context**  
   The project is tuned for an Odroid N2 running Linux with USB OTG support and a modern kernel. The scripts and docs in `scripts/` and `doc/` support system startup, autologin, X session setup, and related environment preparation. These are deployment concerns rather than core logic, but they matter because the architecture depends on kernel gadget support and a graphics/input session for integration.

Main entry points: [`AAServer/main.cpp`](https://github.com/tomasz-grobelny/aacs/blob/master/AAServer/main.cpp) (AAServer), [`AAClient/main.cpp`](https://github.com/tomasz-grobelny/aacs/blob/master/AAClient/main.cpp) (AAClient), [`proto`](https://github.com/tomasz-grobelny/aacs/tree/master/proto) (proto), [`CMakeLists.txt`](https://github.com/tomasz-grobelny/aacs/blob/master/CMakeLists.txt) (Root build)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_runtime["Runtime components"]
  node_n_server["AAServer<br/>binary<br/>[main.cpp]"]
  node_n_server_usb["USB gadget<br/>usb-gadget<br/>[Gadget.h]"]
  node_n_server_socket["Socket bridge<br/>ipc"]
  node_n_server_channels["Channel handlers<br/>channel-routing<br/>[ChannelHandler.h]"]
  node_n_server_proto["AA message core<br/>protocol-model<br/>[Message.h]"]
  node_n_client["AAClient<br/>binary<br/>[main.cpp]"]
  node_n_client_comm["Client comm<br/>bridge-client<br/>[AaCommunicator.h]"]
  node_n_client_channels["Client handlers<br/>channel-routing<br/>[ChannelHandler.h]"]
  node_n_client_proto["Client messages<br/>protocol-model<br/>[Message.h]"]
  node_n_getevents["GetEvents<br/>desktop-tool<br/>[main.cpp]"]
end

subgraph group_grp_protocol["Shared protocol"]
  node_n_proto["proto"]
  node_n_common["utils<br/>[utils.cpp]"]
end

subgraph group_grp_deploy["Deployment support"]
  node_n_server_ssl["Server certs<br/>tls-identity<br/>[android_auto.crt]"]
  node_n_client_ssl["Headunit certs<br/>tls-identity<br/>[headunit.crt]"]
  node_n_scripts["Scripts"]
  node_n_docs["Docs"]
  node_n_root["Root build<br/>build-system<br/>[CMakeLists.txt]"]
end

node_n_server -->|"configures"| node_n_server_usb
node_n_server -->|"exports"| node_n_server_socket
node_n_server -->|"routes"| node_n_server_channels
node_n_server -->|"parses"| node_n_server_proto
node_n_client -->|"connects"| node_n_client_comm
node_n_client -->|"routes"| node_n_client_channels
node_n_client -->|"serializes"| node_n_client_proto
node_n_server -->|"shares"| node_n_proto
node_n_client -->|"shares"| node_n_proto
node_n_server_channels -->|"implements"| node_n_proto
node_n_client_channels -->|"implements"| node_n_proto
node_n_server -->|"uses"| node_n_server_ssl
node_n_client -->|"uses"| node_n_client_ssl
node_n_getevents -->|"receives input from"| node_n_server
node_n_getevents -.->|"fits into"| node_n_scripts
node_n_server -->|"uses"| node_n_common
node_n_client -->|"uses"| node_n_common
node_n_server -.->|"built by"| node_n_root
node_n_client -.->|"built by"| node_n_root
node_n_getevents -.->|"built by"| node_n_root
node_n_proto -.->|"generated by"| node_n_root
node_n_docs -.->|"documents"| node_n_scripts

click node_n_server "https://github.com/tomasz-grobelny/aacs/blob/master/AAServer/main.cpp"
click node_n_server_usb "https://github.com/tomasz-grobelny/aacs/blob/master/AAServer/include/Gadget.h"
click node_n_server_socket "https://github.com/tomasz-grobelny/aacs/blob/master/AAServer/include/SocketCommunicator.h"
click node_n_server_channels "https://github.com/tomasz-grobelny/aacs/blob/master/AAServer/include/ChannelHandler.h"
click node_n_server_proto "https://github.com/tomasz-grobelny/aacs/blob/master/AAServer/include/Message.h"
click node_n_client "https://github.com/tomasz-grobelny/aacs/blob/master/AAClient/main.cpp"
click node_n_client_comm "https://github.com/tomasz-grobelny/aacs/blob/master/AAClient/include/AaCommunicator.h"
click node_n_client_channels "https://github.com/tomasz-grobelny/aacs/blob/master/AAClient/include/ChannelHandler.h"
click node_n_client_proto "https://github.com/tomasz-grobelny/aacs/blob/master/AAClient/include/Message.h"
click node_n_getevents "https://github.com/tomasz-grobelny/aacs/blob/master/GetEvents/main.cpp"
click node_n_proto "https://github.com/tomasz-grobelny/aacs/tree/master/proto"
click node_n_common "https://github.com/tomasz-grobelny/aacs/blob/master/src/utils.cpp"
click node_n_server_ssl "https://github.com/tomasz-grobelny/aacs/blob/master/AAServer/ssl/android_auto.crt"
click node_n_client_ssl "https://github.com/tomasz-grobelny/aacs/blob/master/AAClient/ssl/headunit.crt"
click node_n_scripts "https://github.com/tomasz-grobelny/aacs/tree/master/scripts"
click node_n_docs "https://github.com/tomasz-grobelny/aacs/tree/master/doc"
click node_n_root "https://github.com/tomasz-grobelny/aacs/blob/master/CMakeLists.txt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_server,node_n_server_usb,node_n_server_socket,node_n_server_channels,node_n_server_proto,node_n_client,node_n_client_comm,node_n_client_channels,node_n_client_proto,node_n_getevents toneBlue
class node_n_proto,node_n_common toneAmber
class node_n_server_ssl,node_n_client_ssl,node_n_scripts,node_n_docs,node_n_root toneMint
```

## Components

### Runtime components

Main binaries and the live protocol bridge between headunit, client, and desktop input.

- [AAServer](https://github.com/tomasz-grobelny/aacs/blob/master/AAServer/main.cpp): binary · Headunit-facing server that owns the USB gadget side and local socket bridge. · `AAServer/main.cpp`
- [USB gadget](https://github.com/tomasz-grobelny/aacs/blob/master/AAServer/include/Gadget.h): usb-gadget · Configures Linux gadget mode and the functions exposed to the Android Auto headunit. · `AAServer/include/Gadget.h`
- [Socket bridge](https://github.com/tomasz-grobelny/aacs/blob/master/AAServer/include/SocketCommunicator.h): ipc · Local Unix-socket transport used to communicate with the companion client. · `AAServer/include/SocketCommunicator.h`
- [Channel handlers](https://github.com/tomasz-grobelny/aacs/blob/master/AAServer/include/ChannelHandler.h): channel-routing · Server-side routing for input, video, and default protocol channels. · `AAServer/include/ChannelHandler.h`
- [AA message core](https://github.com/tomasz-grobelny/aacs/blob/master/AAServer/include/Message.h): protocol-model · Server-side packet/message handling around Android Auto channel traffic. · `AAServer/include/Message.h`
- [AAClient](https://github.com/tomasz-grobelny/aacs/blob/master/AAClient/main.cpp): binary · Companion protocol peer that connects to AAServer and forwards Android Auto traffic. · `AAClient/main.cpp`
- [Client comm](https://github.com/tomasz-grobelny/aacs/blob/master/AAClient/include/AaCommunicator.h): bridge-client · Client-side communicator that connects to the server and exchanges service descriptions and traffic. · `AAClient/include/AaCommunicator.h`
- [Client handlers](https://github.com/tomasz-grobelny/aacs/blob/master/AAClient/include/ChannelHandler.h): channel-routing · Client-side handler hierarchy for input, video, and default channel behavior. · `AAClient/include/ChannelHandler.h`
- [Client messages](https://github.com/tomasz-grobelny/aacs/blob/master/AAClient/include/Message.h): protocol-model · Client-side message and device abstractions for the Android Auto session. · `AAClient/include/Message.h`
- [GetEvents](https://github.com/tomasz-grobelny/aacs/blob/master/GetEvents/main.cpp): desktop-tool · Standalone X11 input bridge that replays touch events into desktop applications. · `GetEvents/main.cpp`

### Shared protocol

Android Auto message model and common utility types used by both sides.

- [proto](https://github.com/tomasz-grobelny/aacs/tree/master/proto): protobuf-schemas · Android Auto channel and payload schemas shared by both runtime sides. · `proto`
- [utils](https://github.com/tomasz-grobelny/aacs/blob/master/src/utils.cpp): shared-utils · Small shared utility layer used by the top-level components. · `src/utils.cpp`

### Deployment support

Certificates, scripts, docs, and environment setup for running on target hardware.

- [Server certs](https://github.com/tomasz-grobelny/aacs/blob/master/AAServer/ssl/android_auto.crt): tls-identity · Android Auto-side certificate and key pair used by the server runtime. · `AAServer/ssl/android_auto.crt`
- [Headunit certs](https://github.com/tomasz-grobelny/aacs/blob/master/AAClient/ssl/headunit.crt): tls-identity · Headunit-side certificate and key pair used by the client runtime. · `AAClient/ssl/headunit.crt`
- [Scripts](https://github.com/tomasz-grobelny/aacs/tree/master/scripts): deployment-scripts · Startup, X session, video, and environment setup helpers for the target system. · `scripts`
- [Docs](https://github.com/tomasz-grobelny/aacs/tree/master/doc): deployment-docs · Build, kernel, and installation notes supporting target deployment. · `doc`
- [Root build](https://github.com/tomasz-grobelny/aacs/blob/master/CMakeLists.txt): build-system · Top-level CMake entry point that ties the binaries and shared schemas together. · `CMakeLists.txt`

## Connections

- AAServer → USB gadget: configures · AAServer sets up the Linux USB gadget and its functions.
- AAServer → Socket bridge: exports · AAServer exposes a local socket boundary for the companion client.
- AAServer → Channel handlers: routes · AAServer dispatches protocol traffic through specialized channel handlers.
- AAServer → AA message core: parses · AAServer builds and consumes Android Auto packets and messages.
- AAClient → Client comm: connects · AAClient uses its communicator to attach to AAServer.
- AAClient → Client handlers: routes · AAClient uses channel handlers for typed protocol processing.
- AAClient → Client messages: serializes · AAClient uses its local message model for protocol exchange.
- AAServer → proto: shares · Server-side handlers are defined by the shared protobuf schemas.
- AAClient → proto: shares · Client-side handlers are defined by the shared protobuf schemas.
- Channel handlers → proto: implements · Channel handlers specialize the schema-defined Android Auto channels.
- Client handlers → proto: implements · Client handlers specialize the schema-defined Android Auto channels.
- AAServer → Server certs: uses · AAServer carries its Android Auto certificate identity at runtime.
- AAClient → Headunit certs: uses · AAClient carries its headunit certificate identity at runtime.
- GetEvents → AAServer: receives input from · GetEvents consumes touch events emitted by the server-side bridge.
- GetEvents → Scripts: fits into · Desktop input bridging is supported by the runtime setup scripts.
- AAServer → utils: uses · Server code uses the shared utility layer.
- AAClient → utils: uses · Client code uses the shared utility layer.
- AAServer → Root build: built by · AAServer is one of the main top-level build targets.
- AAClient → Root build: built by · AAClient is one of the main top-level build targets.
- GetEvents → Root build: built by · GetEvents is one of the main top-level build targets.
- proto → Root build: generated by · Protobuf schemas are integrated into the overall build.
- Docs → Scripts: documents · Documentation explains the runtime and setup scripts.
