The app is a full-stack web application designed to be used within a Docker
container. The entire application stack is made up of 4 parts: Frontend, Backend, WebServer, and Backup.
- The frontend is a
React
application built using the open-source javascript module bundlerVite
. - The majority of the frontend codebase is written in
typescript
and its dependencies can be found inside./Frontend/package.json
. - Frontend documentation on patterns used throughout can be found in
./Frontend/docs
. Additional documentation is present throughout various react.tsx
files making up the bulk of the frontend. - The Frontend relies on data from the backend to function properly. The url used to make calls to the database must be correctly configured in
./Frontend/src/api/apiConfig.ts
. Currently it is configured to queryhttps://cyclecount.app/db
. - To run the application in development mode locally, run
npm run dev
inside./Frontend
. A development version of the application be found atlocalhost:5173
. - In production, the frontend source files are not used, and code is compiled by running
npm run build
inside./Frontend
. The compiled static application inhtml
format can be found in./Frontend/dist
when complete. Thisdist
folder is placed within./WebServer
in production to be served withnginx
.
- The backend is built upon the
Django
web framework usingdjangorestframework
to handle requests; it is served usingGunicorn
web server. - The majority of the backend codebase is written in
python
and its dependencies can be found inside./Backend/requirements.txt
. - The backend writes all data to a
.sqlite3
database found in./Backend/data
. - Key files to the backend's functionality include:
settings.py
managing high-level application settings as well as security header settings. Currently the application is configured to host the backend at https://cyclecount.app/db and only accept same-site requests from https://cyclecount.app overhttps
.models.py
determining the various models used in the database, their fields, as well as any relationships between models.- NOTE: All changes made to models must be migrated to the database by running
django manage.py makemigrations
followed bydjango manage.py migrate
, and each model and field must be properly reflected withinserializers.py
.
- NOTE: All changes made to models must be migrated to the database by running
urls.py
which determines the url patterns used by the django REST API framework.views.py
which links each url pattern with an underlying API call to a CRUD action in the database.admin.py
which manages which models should be present on the django administration site.
- In addition, a private key securing the backend must be provided in the root directory with the name
django-private-key.txt
. - In development, the django server can be run locally by running
django manage.py runserver
. Running the server this way in production is bad practice. - In production, the backend is served with
gunicorn
, and its the admin site's static.css
files are served withnginx
.
- The entire application is served to the web using
nginx
. - Currently, nginx is configured to serve the site to https://cyclecount.app using
https
.- Both the
ssl
private key and public certification must be placed in the root directory namedssl-private-key.txt
andssl-public-key.crt
.
- Both the
- The nginx config can be found in
./WebServer/nginx.conf
. - In production, as discussed earlier, the built frontend application should be placed in
./WebServer/dist
.
- This aspect of the application is purely used to backup the
.sqlite3
database bi-weekly. It uses a third-partyDocker
image to backup the database volume within the container. - Backups are saved to
./Backup/archive
and configuration files for various settings such as the time, frequency, and format of backups can be found in./Backup/backup.env
. Backups are currently configured to be pruned after 60 days. - Information on how to use these backups to restore the database can be found in
./Backup/db-restore.md
.
- The application has been developed to be used inside of a docker container.
Docker-Compose
allows the app to nicely break the application down into 3 interdependant services: WebServer, Backend, and Backup. - Each service generates its own image or virtual linux environment that is complete with its own requirements. This top-level configuration can be found in
./compose.yaml
. Additionally, each service has its owndockerfile
outlining the commands needed to properly install requirements and start the service within the virtual container. Volumes
are used within the application to link data within the virtual containers with the local filesystem. Plus, Dockersecrets
allow private keys to be used by containers without them needing to be present within the potentially vulnerable virtual image.
- Clone this repository.
- Build the frontend with
npm run build
and place the generateddist
folder inside the./WebServer
folder. - Place the proper secret
django-private-key.txt
,ssl-private-key.txt
, andssl-public-key.txt
files in the root of the directory. - Run
docker compose up -d
in the home directory to build the docker container (Prior docker installation is required). - Access the app through a browser at https://cyclecount.app (Authentication is required for access).