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
Reactapplication built using the open-source javascript module bundlerVite. - The majority of the frontend codebase is written in
typescriptand 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.tsxfiles 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 devinside./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 buildinside./Frontend. The compiled static application inhtmlformat can be found in./Frontend/distwhen complete. Thisdistfolder is placed within./WebServerin production to be served withnginx.
- The backend is built upon the
Djangoweb framework usingdjangorestframeworkto handle requests; it is served usingGunicornweb server. - The majority of the backend codebase is written in
pythonand its dependencies can be found inside./Backend/requirements.txt. - The backend writes all data to a
.sqlite3database found in./Backend/data. - Key files to the backend's functionality include:
settings.pymanaging 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.pydetermining 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 makemigrationsfollowed 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.pywhich determines the url patterns used by the django REST API framework.views.pywhich links each url pattern with an underlying API call to a CRUD action in the database.admin.pywhich 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.cssfiles 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
sslprivate key and public certification must be placed in the root directory namedssl-private-key.txtandssl-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
.sqlite3database bi-weekly. It uses a third-partyDockerimage to backup the database volume within the container. - Backups are saved to
./Backup/archiveand 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-Composeallows 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 owndockerfileoutlining the commands needed to properly install requirements and start the service within the virtual container. Volumesare used within the application to link data within the virtual containers with the local filesystem. Plus, Dockersecretsallow 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 buildand place the generateddistfolder inside the./WebServerfolder. - Place the proper secret
django-private-key.txt,ssl-private-key.txt, andssl-public-key.txtfiles in the root of the directory. - Run
docker compose up -din 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).