Skip to content

Commit f4d386b

Browse files
committed
docs: update documentation
1 parent 5293303 commit f4d386b

15 files changed

Lines changed: 564 additions & 262 deletions

File tree

README.md

Lines changed: 129 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,50 @@ specific functionality. The main components include:
1111
- **Data Ingestion Service**: Responsible for collecting data from various sensor endpoints.
1212
- **Data Processing Service**: Processes the ingested data, applying any necessary transformations
1313
or aggregations.
14-
- **API Gateway**: Exposes a REST API for clients to access the processed data.
14+
- **REST API**: Exposes a REST API for clients to access the processed data.
15+
- **Application**: Sample frontend application to visualize and interact with the data.
16+
17+
A technical overview of the architecture is shown below:
18+
19+
![Architecture Diagram](./docs/architecture/architecture.png)
20+
21+
_Components in grey are either optional or not implemented yet._
22+
23+
Legend:
24+
25+
- Purple blocks represent external services / devices.
26+
- Orange blocks represent services that are part of the system.
27+
- Blue blocks represent data storage and visualization components.
28+
- Green blocks represent user-facing applications.
29+
30+
> [!NOTE] Kubernetes Autoscaling Kubernetes Autoscaling is an option, which can be implemented in
31+
> the future if the application scales up. This would allow the services to automatically adjust
32+
> their number of instances based on the current load and demand.
1533
1634
## Folder Structure
1735

1836
```text
1937
└── 📁ajdovscina-cloud-software
2038
└── 📁alertmanager
39+
└── 📁application
40+
└── 📁public
41+
├── favicon.ico
42+
├── index.html
43+
└── 📁src
44+
└── 📁components
45+
└── 📁services
46+
└── 📁types
47+
├── Makefile
2148
└── 📁common
2249
└── 📁logging
2350
└── 📁dockerfiles
2451
└── 📁docs
2552
└── 📁architecture
26-
├── ajdovscina-architecture.drawio
2753
└── 📁images
2854
└── 📁grafana
2955
└── 📁dashboards
3056
└── 📁ingest_service
57+
└── 📁common
3158
└── 📁models
3259
└── 📁util
3360
├── Makefile
@@ -36,11 +63,13 @@ specific functionality. The main components include:
3663
└── 📁mock
3764
└── 📁ingest_service
3865
└── 📁processor_service
66+
└── 📁common
3967
└── 📁src
4068
└── 📁util
4169
├── Makefile
4270
└── 📁prometheus
4371
└── 📁rest_api
72+
└── 📁common
4473
└── 📁models
4574
└── 📁src
4675
└── 📁util
@@ -81,7 +110,61 @@ And to stop the production system:
81110
make prod-down
82111
```
83112

84-
> [!IMPORTANT] Each of the services can be deployed independently using their respective makefiles.
113+
> [!IMPORTANT] Service local deployment Each of the services can be deployed independently locally
114+
> using their respective makefiles. See the documentation in each service's directory for more
115+
> details. This should be used in conjunction with the `make dev-up` command to start the
116+
> dependencies.
117+
118+
## Building Blocks
119+
120+
The application is composed of several building blocks, each with its own purpose and functionality.
121+
These blocks are defined in the `docker-compose` files located in the root directory.
122+
123+
These are subject to change as the system evolves, but currently include:
124+
125+
- **PostgreSQL with TimescaleDB**: The primary database for storing sensor data and application
126+
metadata.
127+
- **Kafka**: A message broker used for decoupling the ingestion and processing services.
128+
- **Prometheus**: A monitoring and alerting toolkit used for collecting and querying metrics.
129+
- **Grafana**: A visualization tool used for creating dashboards and visualizing metrics collected
130+
by Prometheus.
131+
- **Alertmanager**: A component of the Prometheus ecosystem used for handling alerts sent by
132+
Prometheus.
133+
- **NodeRED**: A flow-based development tool for visual programming, used for wiring together
134+
hardware devices, APIs, and online services.
135+
- **Ingest Service**: A FastAPI service responsible for receiving and validating incoming sensor
136+
data.
137+
- **Processor Service**: A service that processes the ingested data and stores it in the database.
138+
- **Frontend Application**: A React-based application for visualizing and interacting with the
139+
sensor data.
140+
141+
The [dockerfiles](./dockerfiles) directory contains Dockerfiles for custom services:
142+
143+
- `Dockerfile.ingest_service`: Dockerfile for the Ingest Service.
144+
- `Dockerfile.processor_service`: Dockerfile for the Processor Service.
145+
- `Dockerfile.rest_api`: Dockerfile for the REST API.
146+
- `Dockerfile.application`: Dockerfile for the Frontend Application.
147+
148+
## Service Accessibility
149+
150+
The services are accessible via the following ports when deployed:
151+
152+
| Service | Local Port | External Port Production | Description |
153+
| -------------------- | ---------- | ------------------------ | ------------------------------------------ |
154+
| PostgreSQL | 5432 | 13328 | Database service |
155+
| Prometheus | 9090 | 19290 | Monitoring and alerting toolkit |
156+
| Grafana | 3000 | 13201 | Visualization tool |
157+
| Alertmanager | 9093 | 19193 | Alert management |
158+
| NodeRED | 1880 | 11880 | Flow-based development tool |
159+
| Ingest Service | 5000 | 40005 | Data ingestion endpoint |
160+
| REST API | 5005 | 41005 | REST API for accessing sensor data |
161+
| Frontend Application | 3001 | 8004 | User interface for visualizing sensor data |
162+
163+
External ports are used to access the services from outside the Docker network, while local ports
164+
are used for communication between services within the Docker network.
165+
166+
If the services are run using their respective makefiles, the ports may differ. See the Makefile in
167+
each service's directory for more details.
85168

86169
### Configuration and Constants
87170

@@ -110,3 +193,46 @@ DB_CONFIG = {
110193

111194
API_KEY = "your-secret-api-key" # Replace with your actual key
112195
```
196+
197+
Detailed descriptions of each constant:
198+
199+
- `LOG_LEVEL`: Sets the logging level for the application.
200+
- `DB_CONFIG`: A dictionary containing the database connection parameters:
201+
- `dbname`: The name of the PostgreSQL database. Set to `ajdovscina` by default; This is defined
202+
in the `docker-compose` files - `POSTGRES_DB` variable.
203+
- `user`: The username used to connect to the database. Set to `ajdovscina-geospatial-user` by
204+
default; This is defined in the `docker-compose` files - `POSTGRES_USER` variable.
205+
- `password`: The password for the database user. Set to `password` by default; This is defined in
206+
the `docker-compose` files - `POSTGRES_PASSWORD` variable.
207+
- `host`: The hostname or IP address of the database server. Set to `localhost` for local
208+
development or `geospatial-data` when using Docker Compose - that's the service name defined in
209+
the `docker-compose` files.
210+
- `port`: The port number on which the database server is listening. Set to `5432` for local
211+
deployment or `13328` for Docker Compose - this is defined in the `docker-compose` files -
212+
`ports` mapping in the `geospatial-data` service.
213+
214+
#### ingest_service/constants.py
215+
216+
The constants found in the ingest_service/constants.py file are specific to the Ingest Service.
217+
218+
```python
219+
import os
220+
221+
LOCALHOST = os.environ.get("LOCALHOST") == "true"
222+
223+
KAFKA_HOST = "localhost:9992" if LOCALHOST else "kafka:9993" # Kafka broker to connect to and produce messages to
224+
# kafka:9993 is the service name defined in the docker-compose files
225+
```
226+
227+
#### processor_service/constants.py
228+
229+
The constants found in the processor_service/constants.py file are specific to the Processor
230+
Service.
231+
232+
```python
233+
import os
234+
235+
LOCALHOST = os.environ.get("LOCALHOST") == "true"
236+
KAFKA_HOST = "localhost:9992" if LOCALHOST else "kafka:9993" # Kafka broker to connect to and consume messages from
237+
# kafka:9993 is the service name defined in the docker-compose files
238+
```

application/README.md

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,26 @@
1-
# Getting Started with Create React App
1+
# Sample Frontend Application
22

33
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
44

5-
## Available Scripts
5+
This simple frontend application allows users to visualize and interact with the sensor data
6+
ingested by the system. It fetches data from the REST API and displays it in a user-friendly manner.
67

7-
In the project directory, you can run:
8+
## Configuration
89

9-
### `npm start`
10+
A `.env` file is used to configure the application. The `.env` file should contain the following
11+
variables:
1012

11-
Runs the app in the development mode.\
12-
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
13+
```env
14+
PORT=3001
1315
14-
The page will reload if you make edits.\
15-
You will also see any lint errors in the console.
16+
REACT_APP_API_TOKEN=your-secret-api-key
17+
REACT_APP_API_BASE_URL=http://localhost:51005
18+
```
1619

17-
### `npm test`
20+
When deploying the application, make sure to set `REACT_APP_API_BASE_URL` to the URL where the REST
21+
API is hosted, and `REACT_APP_API_TOKEN` to a secure value that is set by the REST API.
1822

19-
Launches the test runner in the interactive watch mode.\
20-
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests)
21-
for more information.
23+
## Running the Application
2224

23-
### `npm run build`
24-
25-
Builds the app for production to the `build` folder.\
26-
It correctly bundles React in production mode and optimizes the build for the best performance.
27-
28-
The build is minified and the filenames include the hashes.\
29-
Your app is ready to be deployed!
30-
31-
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for
32-
more information.
33-
34-
### `npm run eject`
35-
36-
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
37-
38-
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time.
39-
This command will remove the single build dependency from your project.
40-
41-
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel,
42-
ESLint, etc) right into your project so you have full control over them. All of the commands except
43-
`eject` will still work, but they will point to the copied scripts so you can tweak them. At this
44-
point you’re on your own.
45-
46-
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle
47-
deployments, and you shouldn’t feel obligated to use this feature. However we understand that this
48-
tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
49-
50-
## Learn More
51-
52-
You can learn more in the
53-
[Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
54-
55-
To learn React, check out the [React documentation](https://reactjs.org/).
25+
To run the application locally, run `make run-local-dev` from this directory. This will run the
26+
`npm run start` command and launch the application in development mode.

common/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Common Utilities
2+
3+
The common directory contains shared utilities and modules used across different services in the
4+
project. This includes database connection management, logging setup, and other helper functions.
5+
6+
## Configuration
7+
8+
The [constants.py](./constants.py) file contains configuration constants for the services. These
9+
should be configured based on the deployment environment.
10+
11+
When deploying to the cloud, make sure you change the API key and database credentials to secure
12+
values.

common/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
DB_CONFIG = {
1010
"dbname": "ajdovscina",
1111
"user": "ajdovscina-geospatial-user",
12-
"password": "password",
12+
"password": "password", # In production, use a secure password and manage it safely
1313
"host": "localhost" if localhost else "geospatial-data",
1414
"port": 13328 if localhost else 5432,
1515
}
-260 KB
Binary file not shown.

0 commit comments

Comments
 (0)