# Architecture

## Directory Structure

#### High-Level Directory Structure

```arduino
arduinoCopy code<root dir>/
├── ats/
│   ├── apis/
│   ├── database/
│   ├── exceptions/
│   ├── exchanges/
│   ├── indicators/
│   ├── logs/
│   ├── saved_states/
│   ├── state/
│   ├── static/
│   ├── strategies/
│   ├── templates/
│   ├── tests/
│   ├── trading_job/
│   ├── utils/
│   ├── __init__.py
│   ├── main.py
│   ├── test.py
├── custom_modules/
│   ├── exchanges/
│   ├── fees/
│   ├── indicators/
│   ├── strategies/
├── .env
├── environment.yml
├── requirements.txt
├── setup.sh
├── start.sh
└── README.md
```

***

### Core Application: `ats/`

The `ats` folder contains the core application code, organized into multiple subdirectories for modularity and maintainability.

#### Key Folders

* **`apis/`**\
  Handles API endpoints, requests to external APIs, and response processing logic.
* **`database/`**\
  Manages database interactions, including models, schemas, connections, and CRUD operations.
* **`exceptions/`**\
  Custom exception classes for handling specific errors throughout the application.
* **`exchanges/`**\
  Connectors and integrations for interacting with various financial or crypto exchanges.\
  Each built-in exchange resides in `exchanges/exchanges/<exchange_name>` and implements an `Exchange` class extending the `BaseExchange` class.
* **`indicators/`**\
  Implementations of technical indicators used in trading strategies, such as Moving Averages, RSI, or MACD.\
  Each indicator must extend the `BaseIndicator` class.
* **`logs/`**\
  Contains application logs for debugging and monitoring performance.
* **`saved_states/`**\
  Stores serialized states or checkpoint data to maintain consistency across runs or allow resuming processes.
* **`state/`**\
  Serializable classes extending the `SimpleState` class for managing and persisting application states.
* **`static/`**\
  Static assets like CSS, JavaScript, and images for the trading UI.
* **`strategies/`**\
  Built-in trading strategies, each implemented as a class that extends the `BaseStrategy` class.\
  Strategies should reside in `strategies/<strategy_name>` and must define a `Strategy` class in a `strategy.py` file.
* **`templates/`**\
  Template files (e.g., HTML files) for rendering dynamic content in the trading UI.
* **`tests/`**\
  Unit tests, integration tests, and other test-related files to verify application correctness.
* **`trading_job/`**\
  Core logic and classes for managing and executing trading jobs.
* **`utils/`**\
  Utility functions and helper modules for reusable functionalities like file operations, data transformations, and logging.

***

## Custom Modules: `custom_modules/`

The `custom_modules` directory is dedicated to user-defined customizations. It allows users to add their own exchange connectors, strategies, indicators, and fee models. These modules override the core ones in the `ats` folder if there is a naming conflict.

#### Key Folders

* **`exchanges/`**\
  Custom exchange implementations. Each exchange must:
  * Be placed in `custom_modules/exchanges/<exchange_name>.py`.
  * Implement an `Exchange` class extending the `BaseExchange` class.
* **`fees/`**\
  Custom fee models for defining unique fee structures. Each fee model must:
  * Be placed in `custom_modules/fees/<fee_model_name>.py`.
  * Implement a class extending the `BaseFees` class.
* **`indicators/`**\
  Custom technical indicators. Each indicator must:
  * Be placed in `custom_modules/indicators/<indicator_name>.py`.
  * Implement a class extending the `BaseIndicator` class.
* **`strategies/`**\
  Custom trading strategies. Each strategy must:
  * Be placed in `custom_modules/strategies/<strategy_name>/strategy.py`.
  * Implement a `Strategy` class extending the `BaseStrategy` class.

***

## Root-Level Files

* **`.env`**\
  Contains environment-specific variables, such as API keys and configurations.
* **`environment.yml`**\
  Specifies dependencies for setting up the project environment with Conda.
* **`requirements.txt`**\
  Python dependencies for the application, used with `pip`.
* **`setup.sh`**\
  A shell script for initializing and configuring the application environment.
* **`start.sh`**\
  A shell script for starting the application.
