Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Docs and CI #9

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/backend-linter-and-tester.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Pylint
on: [push]
jobs:
Backend-Linter-and-Test:
runs-on: ubuntu-latest
env:
PYTHON_VERSION: "3.10.12"
defaults:
run:
working-directory: ./backend
steps:
- uses: actions/checkout@v4
- name: Set up Python $PYTHON_VERSION
uses: actions/setup-python@v3
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
- name: Run tests
run: |
pytest
29 changes: 0 additions & 29 deletions .github/workflows/backend-linter.yml

This file was deleted.

30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
BACKEND_CONTAINER_NAME=python_backend

.PHONY: docker/start docker/start-build docker/clean backend/test backend/migrate backend/upgrade

# Docker commands:

docker/start:
docker compose up

docker/start-build:
docker compose up --build

docker/clean:
docker compose down --volumes --rmi all

# Backend commands:

backend/migrate:
@if [ "$(message)" = "" ]; then \
echo "Please provide a migration message. Usage: make migrate message='Your migration message'"; \
exit 1; \
else \
docker compose exec $(BACKEND_CONTAINER_NAME) python3 -m flask --app main db migrate -m "$(message)"; \
fi

backend/upgrade:
docker compose exec $(BACKEND_CONTAINER_NAME) python3 -m flask --app main db upgrade

backend/test:
docker compose exec $(BACKEND_CONTAINER_NAME) pytest
77 changes: 54 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,76 @@
# Bookstore Management System
The Bookstore Management System is designed to showcase the integration of various technologies for building a web application

![Concept Map](assets/concept-map.png)
The Bookstore Management System is a web application designed to demonstrate the integration of various modern technologies and best practices in software development. This project serves as a showcase of how to effectively combine multiple tools and frameworks to create a robust, maintainable, and scalable application.

## Overview
It consists of the following components:
## Key Features

### Deployment and CI/CD

- _Docker and Docker Compose_: Containerization of the application for consistent and isolated environments, enabling easy deployment and scaling.
- _GitHub Actions_: Automated pipeline for continuous integration and continuous deployment (CI/CD), ensuring code quality and rapid delivery of updates.

Backend API (Python Flask + Postgres): Implements CRUD (Create, Read, Update, Delete) operations for managing books. Utilizes PostgresSQL for data storage, demonstrating the integration of Flask with a NoSQL database.
### Backend

Frontend Application (React): Provides a user-friendly interface for browsing and managing books. Interacts with the Flask backend via RESTful API to fetch and update data.
- _MVCS Architecture_: Implementation of Model-View-Controller-Service architecture for a well-structured and modular backend.
- _Flask_: A lightweight and flexible web framework for building the server-side application.
- _PostgreSQL with Flask-SQLAlchemy_: Powerful ORM for database management and seamless interaction with a PostgreSQL database.
- _Marshmallow_: Schema validation and serialization/deserialization library for managing input/output data integrity.
- _Pytest_: Unit testing framework to ensure the reliability and correctness of the backend code.

This POC was developed do demonstrate the CI/CD Github actions working together with the following AWS Services:
1. AWS Elastic Beanstalk for Flask
2. AWS RDS for Postgress
3. AWS Amplify for the React web app
4. Docker was used for AWS local development
### Frontend

- _React with TypeScript_: Modern frontend library combined with TypeScript for type safety and robust application development.
- _Reusable Components_: Building blocks for creating maintainable and scalable UI.
- _ESLint and Prettier_: Tools for code linting and formatting, ensuring consistent and clean codebase.

## Project Structure

It consists of the following components:

Backend API (Python Flask + Postgres): Implements CRUD (Create, Read, Update, Delete) operations for managing books. Utilizes PostgresSQL for data storage, demonstrating the integration of Flask with a SQL database.

Frontend Application (React): Provides a user-friendly interface for browsing and managing books. Interacts with the Flask backend via RESTful API to fetch and create data.

## Installation

1. Install and set up the backend, follow the instructions in the [`backend/README.md`](./backend/README.md) file.
1. Docker is being used to run the backend, frontend, database and even the database manager (PgAdmin). In order to install it make sure to have both docker and docker-compose installed.

2. To start the services run `make docker/start`

### Makefile Commands

2. Docker is being used to run the backend, frontend, database and even the database manager (PgAdmin). In order to install it make sure to have both docker and docker-compose installed.
This Makefile provides convenient targets to automate common development tasks.

3. To start the services run `docker compose up`
- **docker/start**: Starts Docker containers.

- **docker/start-build**: Starts Docker containers and rebuilds images.

- **docker/clean**: Remove volumes and delete all images associated with the containers defined in the `docker-compose.yml` file.

- **backend/migrate**: Runs Flask migration with a specified message.

- **backend/upgrade**: Upgrades the database schema using Flask.

- **backend/test**: Runs pytest for testing.

### PgAdmin

PgAdmin is a popular open-source administration and development platform for PostgreSQL, a relational database management system. It provides a graphical interface for users to manage their PostgreSQL databases, execute SQL queries, monitor database activity, and perform various administrative tasks.

If you want to see your database on PgAdmin, you'll need to follow a few steps:

1. Access to PgAdmin:
- **URL:** http://localhost:5050
- **Username:** [email protected]
- **Password:** admin

- **URL:** http://localhost:5050
- **Username:** [email protected]
- **Password:** admin

2. Add a new server in PgAdmin:
- **Host:** name/address postgres
- **Port:** 5432
- **Username:** postgres
- **Password:** changeme
- **Host:** name/address postgres
- **Port:** 5432
- **Username:** postgres
- **Password:** changeme

## References

# References
1. The database docker configuration was retrieved from [khezen/compose-postgres](https://github.com/khezen/compose-postgres/tree/master)
1. The database docker configuration was retrieved from [khezen/compose-postgres](https://github.com/khezen/compose-postgres/tree/master)
Binary file removed assets/concept-map.png
Binary file not shown.
2 changes: 1 addition & 1 deletion backend/.pylintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[MASTER]
disable=
C0114, C0115, R0903, C0413, C0116, C0415
C0114, C0115, R0903, C0413, C0116, C0415, F0001
ignore-paths=migrations/
24 changes: 0 additions & 24 deletions backend/Makefile

This file was deleted.

49 changes: 0 additions & 49 deletions backend/README.md

This file was deleted.

51 changes: 0 additions & 51 deletions backend/migrations/versions/17eb199d7416_initial_commit.py

This file was deleted.

10 changes: 5 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ volumes:

services:
python_backend:
container_name: python_backend
build: ./backend
ports:
- "5000:5000"
Expand Down Expand Up @@ -40,13 +41,13 @@ services:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
PGDATA: /data/postgres
volumes:
- postgres:/data/postgres
- postgres:/data/postgres
ports:
- "5432:5432"
networks:
- my_network
restart: unless-stopped

pgadmin:
container_name: pgadmin_container
logging:
Expand All @@ -55,13 +56,12 @@ services:
environment:
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:[email protected]}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin}
PGADMIN_CONFIG_SERVER_MODE: 'False'
PGADMIN_CONFIG_SERVER_MODE: "False"
volumes:
- pgadmin:/var/lib/pgadmin
- pgadmin:/var/lib/pgadmin

ports:
- "${PGADMIN_PORT:-5050}:80"
networks:
- my_network
restart: unless-stopped

1 change: 0 additions & 1 deletion frontend/.env.example

This file was deleted.

2 changes: 2 additions & 0 deletions frontend/src/pages/Books/BookForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ const BookForm: React.FC = () => {

return (
<div className="col-span-12">
<h1 className="text-base font-semibold leading-7 text-gray-900">Book&apos;s Authors</h1>
<hr className="mb-4" />
<Table {...tableProps} />
</div>
);
Expand Down
Loading