A TCP server built in Rust to facilitate communication between the UI-Layer, Pi_Transmit, and the integrated database.
Its designed to be multithreaded and hosted through AWS to enable future scalability and expansion through region deployment.
To see detailed information on all the avaliable request and endpoint information, visit the API Specification Document.
- Thread safe server with RESTful design principles that is ready for multithreading
- SQLite3 integrated database
- Responses can be generated from files
- Polymorphic and type-agnostic design utilizing dependency injecting
- Database integrations can be expanded by implementing the
Databasetrait and abstract functions - Chosen database format is injected and initialized on program start
- All model functionality is implemented through the
BaseModeltrait and abstract functions - Models are directly parsed into
HttpResponseby callingBaseModel::public_json()
- Database integrations can be expanded by implementing the
- Raw requests deserialized to strongly typed
HttpRequeststruct - Request headers pre-parsed to read exact body from stream
- Compiler enforced route handling with respect to method, headers, path, and body
- Routing returns initialized
HttpResponsestruct HttpHeaderutilizes a factory builder pattern to supportHttpResponsefunctionality
- Url used for parsing requests url
- Serde and serde_json used for serialization and deserialization
- Chrono used for UTC timestamps
- Rusqlite used for database integration
- Toml used for config file parsing
- tcp-server/
- Cargo.toml
- src/
- config.toml - The programs configuration file
- main.rs - Holds the entrypoint as well as the client handling and request routing logic
- data/
- mod.rs
- database.rs - Holds the
Databasetrait implementation - mock_database.rs - Holds a mock
Databaseimplementation for testing - sqlite_database.rs - Holds the SQLite
Databaseimplementation for production - test_sqlite_db.rs - Holds testing functionality for
sqlite_database.rs
- http/
- mod.rs
- http_header.rs - Holds the
HttpStatus,HttpHeaderType, andHttpHeaderstruct implementations - http_method.rs - Holds the
HttpMethodstruct implementation - http_path.rs - Holds the
HttpPathstruct implementation - http_request.rs - Holds the
HttpRequeststruct implementation with byte buffer parsing logic - http_response.rs - Holds the
HttpResponsestruct implementation with stream sending logic
- models/
- mod.rs
- base_model.rs - Holds the
BaseModeltrait implementation - user_model.rs - Holds the
Userimplementation of theBaseModeltrait - sensor_model.rs - Holds the
Sensorimplementation of theBaseModeltrait - session_model.rs - Holds the
Sessionimplementation of theBaseModeltrait - session_sensor_model.rs - Holds the
SessionSensorimplementation of theBaseModeltrait - session_sensor_data_model.rs - Holds the
SessionSensorDataimplementation of theBaseModeltrait
- views/
- 404.html - A fallback to provide a 404 response when HTML is expected
- index.html - A placeholder webpage to be replaced with files generated by the UI-Layer repository
-
Open a terminal where the repository will be cloned
-
Install the Rust toolchain if not already installed
- run the command
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Hit enter again for the default installation
- Check it was installed correctly by running the following commands
rustc --version cargo --version
- run the command
-
Clone the repository by running the following command
git clone https://github.com/CS-Personal-Data-Acquisition-Prototype/Rust-Tcp.git -
Edit the configuration file
config.tomlin thesrcdirectory- Follow the Configuration section for format guidelines
-
Run the program by following the Usage section
The configuration file doesn't have any headers.
The default values look like the following:
database_file = "data_acquisition.db" # name of local database file
local_addr = "0.0.0.0:7878" # local address to listen for TCP requests onThis crates defaults to a mock database connection when using cargo build or cargo run.
To utilize an SQLite database the crate must be built and ran with --features sql.
-
Open a terminal in the directory 'tcp-server'.
-
To run the project in debug use the command:
cargo run [--features sql] -
To run the project in release mode use the command:
cargo run --release [--features sql]
- User authentication, utilizing existing session cookie infastructure
- Multithread with pooling as demand increases, existing code is already thread-safe
- Parsing request url query string to support API query parameters
To apply the Apache License to your work, attach the following boilerplate notice. The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
Copyright 2025 CS 46X Personal Data Acquisition Prototype Group
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.