Skip to content

estebanarivasv/DS-2020-SeismologyAngular

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌎 Seismology Proyect

Subject: "DiseΓ±o de sistemas"

This is a mirrored repository of the project I did for "ProgramaciΓ³n I" (Programming) at Universidad de Mendoza. For more information, go to https://github.com/estebanarivasv/Seismology-Flask

The aim of this repository is emphasize software design patterns and best software practices.

🌳 Project's tree structure diagram

Given the task, I've designed my project structure with the Model–view–controller (MVC) software design pattern.

REST Api on Flask

.
β”œβ”€β”€ app.py                                                  -- App instance
β”œβ”€β”€ database                                                -- SQLite db 
β”‚Β Β  └── data.db
β”œβ”€β”€ insomnia_requests.json
β”œβ”€β”€ main
β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”œβ”€β”€ controllers                                         -- HTTP Requests jsons handling
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ seism.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ sensor.py
β”‚Β Β  β”‚Β Β  └── user.py
β”‚Β Β  β”œβ”€β”€ extensions                                          -- Main components initialization
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”œβ”€β”€ mapping                                             -- JSON dictionaries mapping for db
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ seism.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ sensor.py
β”‚Β Β  β”‚Β Β  └── user.py
β”‚Β Β  β”œβ”€β”€ models                                              -- Database models
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ seism.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ sensor.py
β”‚Β Β  β”‚Β Β  └── user.py
β”‚Β Β  β”œβ”€β”€ repositories                                        -- CRUD Methods for the controllers interacting with the db
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ main.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ seism.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ sensor.py
β”‚Β Β  β”‚Β Β  └── user.py
β”‚Β Β  β”œβ”€β”€ resources
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ authentication
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ decorators.py                               -- Controllers restriction
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── routes.py                                   -- Auth routes
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ functions.py                                    -- get_near_seisms() - Pandas
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ pagination.py                                   -- Model used in repositories
β”‚Β Β  β”‚Β Β  └── validators.py                                   -- Objects validation used in repositories
β”‚Β Β  β”œβ”€β”€ services
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ jobs
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ functions.py                                -- get_seisms_from_api(), get_ids_to_delete()
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ __init__.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── tasks.py                                    -- seisms_achiever, data_persistance
β”‚Β Β  β”‚Β Β  └── mail_sending                                    -- Email admins of not working sensors
β”‚Β Β  β”‚Β Β   Β Β  β”œβ”€β”€ controller.py
β”‚Β Β  β”‚Β Β   Β Β  └── resources.py
β”‚Β Β  └── templates                                           -- Email templates
β”‚Β Β      └── mail
β”‚Β Β          β”œβ”€β”€ sensors_status.html
β”‚Β Β          └── sensors_status.txt
└── requirements.txt

Web client on Angular

.
β”œβ”€β”€ app
β”‚Β Β  β”œβ”€β”€ app.component.html                                  -- ROUTER IMPLEMENTATION, Bootstrap CDN
β”‚Β Β  β”œβ”€β”€ app.constants.ts                                    -- API URL
β”‚Β Β  β”œβ”€β”€ app.module.ts                                       -- Dependencies, Bootstrap CDN
β”‚Β Β  β”œβ”€β”€ app-routing.module.ts                               -- ROUTING, Bootstrap CDN
β”‚Β Β  β”œβ”€β”€ app-sorting.directive.ts
β”‚Β Β  β”œβ”€β”€ alerts                                              
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ alerts.service.ts
β”‚Β Β  β”œβ”€β”€ authentication                                      
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ authentication.component.html                   -- Login template
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ authentication.component.ts
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ authentication.service.ts                       -- Api authentication interaction
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ guards                                          -- Limit routing
β”‚Β Β  β”‚Β Β  └── interceptors
β”‚Β Β  β”œβ”€β”€ guards
β”‚Β Β  β”œβ”€β”€ header
β”‚Β Β  β”‚Β Β  └── header.component.html
β”‚Β Β  β”œβ”€β”€ home
β”‚Β Β  β”‚Β Β  └── home.component.html
β”‚Β Β  β”œβ”€β”€ pagination.model.ts
β”‚Β Β  β”œβ”€β”€ seisms
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ seisms-filter.model.ts                          -- Seisms pagination, sorting and filter model
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ seisms.model.ts                                 -- Seisms model for requests mapping
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ seisms.service.ts                               -- Seisms components interaction with HTTP requests
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ unverified-seisms
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ edit-unverified
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ unverified-seisms.component.html
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ unverified-seisms.component.ts
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── view-unverified
β”‚Β Β  β”‚Β Β  └── verified-seisms
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ verified-seisms.component.html
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ verified-seisms.component.ts
β”‚Β Β  β”‚Β Β      └── view-verified
β”‚Β Β  β”œβ”€β”€ sensors
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ add-sensor
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ check-sensor
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ delete-sensor
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ edit-sensor
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ sensors.component.html
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ sensors.component.ts
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ sensors-filter.model.ts                         -- Sensors pagination, sorting and filter model
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ sensors.model.ts                                -- Sensors model for requests mapping
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ sensors.service.ts                              -- Sensors component interaction with HTTP requests
β”‚Β Β  β”‚Β Β  └── view-sensor
β”‚Β Β  β”œβ”€β”€ upper-body                                          -- BREADCRUMBS, TITLE
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ upper-body.component.html
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ upper-body.component.ts
β”‚Β Β  β”‚Β Β  └── upper-body.interfaces.ts
β”‚Β Β  └── users
β”‚Β Β      β”œβ”€β”€ add-user
β”‚Β Β      β”œβ”€β”€ delete-user
β”‚Β Β      β”œβ”€β”€ edit-user
β”‚Β Β      β”œβ”€β”€ users.component.html
β”‚Β Β      β”œβ”€β”€ users.component.ts
β”‚Β Β      β”œβ”€β”€ users.model.ts                                  -- Users model for requests mapping
β”‚Β Β      └── users.service.ts                                -- Users component interaction with HTTP requests
β”œβ”€β”€ assets
β”‚Β Β  β”œβ”€β”€ img
β”‚Β Β  └── videos
β”œβ”€β”€ environments
β”œβ”€β”€ favicon.ico
β”œβ”€β”€ index.html
β”œβ”€β”€ main.ts
β”œβ”€β”€ polyfills.ts
β”œβ”€β”€ styles.scss
└── test.ts

Software design patterns and principles applied in the project

  • DRY, KISS, SOLID
  • Command -> Repositories
  • Observer -> .suscribe() Angular services (async)

πŸ’» Developing stages

At the beginning, I had the REST Api from the base repository from where I started. Here it is the full description of what I did:

Backend

1 - Mapping

DB Models Schemas creation (flask-marshmallow). to_json(), from_json() deletion.

2 - Controllers and repositories

Modularity. Controllers -> HTTP Requests

3 - Filtering, sorting and pagination

General Pagination class

4 - Repositories

Modularity. Repositories -> DB interaction

5 - Resources

Modularity. Reorganizing: auth, various functions for services, validators, pagination

6 - Services

Jobs: data persistance, data obtention

Frontend

1 - Components

Views design: home, seisms, sensors, users

2 - Services

HTTP Requests

3 - Forms and validations

Reactive forms on add and edit views

4 - Alerts

Service that displays alerts

5 - Filtering, sorting, pagination

Template-driven forms. Filter models, NgbdSortableHeader, ngb-pagination

6 - Auth

Auth service, HttpRequestsInterceptor, Guard

What's left to do?

  • CSV download
  • Email sending integration
  • Near seisms from input location
  • Api validation
  • Guards

Problems

  • New framework, new languaje
  • Time

ℹ️ Installation and usage for both API and Web client

Steps to follow in order to get the Flask app and Angular client up and running

1 - Define the environment variables in .env and app.constants.ts files

You can rename the .env-example file to .env

❗ Remember you need to declare all the variables including the database path.

2 - Install dependencies

To begin the instalation of libraries and the frameworks needed: ./install.sh and npm install

3 - Launch Flask application

To get the app running: ./boot.sh and ng serve

3.1 - Import requests file for the api in Insomnia