Giter Site home page Giter Site logo

techlog-article's Introduction

techlog-article-service

Introduction

  • This is the repository of the APIs that my TechLog blog will use in order to do the CRUD operations on the article data

History

  • Initially this project was planned to be implemented as an Express.js backend service.
  • However, having decided to be a Python/ML expert, I have decided to use FastAPI.
  • Hence this project has been migrated from the previous TS codebase into the Python codebase using FastAPI, which you currently see as of now.

Tech Stack

Project Design

Architecture

This project tries to adopt what is called Hexagonal pattern. This may be a little bit of overkill for this small project. However, this pattern allows us to follow the SOLID principle easier, and the code becomes more readable and testable.

Above of all, I am very happy with this pattern since it forces the developer to think the business logic(the "domain" layer) first, so that we can quickly adjust to any frequent changes in the codebase.

Serverless

This project is based on the serverless technologies, such as AWS Lambda and serverless database services.

techlog-article's People

Contributors

uponthesky avatar

Watchers

 avatar

techlog-article's Issues

use case: user

  • user sign up

    • the user inputs form data: username, email, and password(POST)
    • data validation check(format) at the web adapter
    • the application checks whether there is a user with the same email or name(including deleted)
    • if there is, raise 400 error, otherwise, respond with 201 created
    • the server stores the values in the DB(password => hashed)
  • user sign out

    • the user provides his/her token
    • if the token is valid, the server sets the value of user.deleted_at and auth.deleted_at as datetime.now(timezone.utc)
  • user account update

    • email, username, or password only(PATCH)
    • data validation check at the web adapter
    • the application checks whether there is a user with the same email or name(including deleted)
    • if there is, raise 400 error, otherwise respond with 200
    • the server updates the values in the DB(password => hashed)

unit testing

  • only domain logics are our targets of unit testing

  • article

    • create: pass all the data to db
    • read single => db 404 response / list => list + count (check call)
    • update: pass only unset values to db
    • delete: call db
  • user

    • sign up: hash password functions are invoked
    • update account: db 404 / hash password if password is reset / exclude unset
    • sign out: call db
  • auth

    • token check: invalid, expired
    • login: 404 / password not valid / issue access token & update the auth
    • logout: call db

user security(jwt token)

We should fetch a given user's data from the database and authenticate a user.

We will follow the security guide provided by FastAPI docs.

  • security - 1
  • security - 2
  • security - 3
  • security - 4
  • security - 5

use case: auth

User Story

  1. a user(already signed up) logs in by sending username and password to the server
  • checks whether the given data is valid
  • if valid, issues a jwt token to the user(just token, not expiry data)
  • if not, raises an 400/404 error
  1. a user logged in sends its token to the server
  • checks whether the token is valid => dependency
  • either invalid or expired: 401/400 error respectively
  • if valid: allows the user to do what is allowed for her/him
  1. a user tries to log out
  • deactivate the token

  • implement public interface of 1

  • implement public interface of 2

  • implement public interface of 3

  • revisit: after DB adapter

  • revisit: after common utils

  • (optional) implement a cache server for the user tokens(Redis) => currently, we only focus on the overall implementation of the application.

Setup Dev Environment

On branch develop, finish the basic development environment setup.

In detail:

  • initialize node.js project via yarn --init
  • initialize TypeScript project via tsc --init
  • configure the project in package.json and tsconfig.json
  • install basic packages:
    • TS developement: typescript, ts-node-dev(instead of nodemon)
    • linter: eslint(with pre-commit hook)
    • testing: ts-jest(with pre-commit hook)
    • formatting: prettier(with pre-commit hook)

frontend: vercel

Originally intending to work with GCP. However due to the time limit, we'll deploy it to vercel

system testing

make some senarios and do e2e testings

Currently, we would like to do manually. But in the future we want to convert them into code.

  • #58

  • user signs up

    • unhappy case: already existing user / form validation error
  • user logs in

    • unhappy: password, username wrong
  • user reads an article

    • unhappy: article doesn't exist
  • user reads a list of articles

  • user creates an article

  • user updates an article

    • unhappy: not an owner of this article
  • user deletes an article

    • unhappy: not an owner of this article
  • user logs out

  • user signs out

backend - api/admin

Implement the backend api for the login page, solely dedicated to the owner user(the author)

backend - api/me

Implement the backend api for the self introduction(about me) page

This page consists mainly of static data, so not much works to be done: the root directory is public/me

  • main picture: /profile
  • a short introduction about myself: /shortIntro
  • education: /education
  • work experience: /workExperience
  • comp.sci: /compSci
  • hobbies: /hobbies
  • (possibly in a near future) related pictures

Deploy

Edit(May 18th, 2023)
We're going to choose the following path:

router

Roadmap: Read and implement the FastAPI docs basic tutorial part, before Error handling.

Article

  • create
  • read
  • update
  • delete

User

  • create
  • read
  • update
  • delete
  • anything involving security issues related to the router part

add github action for cicd

  • set a precommit hook to generate requirements.txt
  • setup a basic cicd pipeline
    • checkout
    • basic setup: python setup => install dependency
    • test
  • #61
    • db migration
    • backend deploy

backend - api/main

Rewrite the DB to Firestore

Replace the current postgres DB part with Firestore due to the high cost of either AWS RDS or GCP Cloud SQL.

  • #76
  • implementing the code
  • make the transactional annotation abstract
  • #77
  • #79
  • #80
  • Setup the infra using terraform

use case: article

Basic CRUD jobs

  • create

    • input: title(str), content(Optional[str]), and user(author) id(dependency injected)
    • validate at the web adapter => service stage: title should be not null
    • store the data into the database(update both article and user using relationship)
    • return None(201 created)
  • read

    • input: article id
    • db query: both article and the author
    • output: title, content, created_at, updated_at, user.name, user.email(200 ok)
  • read all

    • input: query string -> offset & limit(pagination)
    • db query: both article and the author(join)
    • output: a list of articles with the same dto as "read"(200 ok)
  • update

    • input: article_id, title(optional), content(optional)
    • update the article(update)
    • output: None(200 ok)
  • delete

    • input: article_id
    • set deleted_at = now
    • output: None(204 no content)

refactor the structure before unit testing

Check:

  • naming & responsibilities

  • duplicates in code

  • article

    • in port
    • out port
    • service
    • web adapter
    • persistence adapter
  • user

    • in port
    • out port
    • service
    • web adapter
    • persistence adapter
  • auth

    • in port
    • out port
    • service
    • web adapter
    • persistence adapter

backend - deploy to GCP

Currently the backend service has very limited performance & devops features.

We will move to GCP for better features.

  • frontend: Cloud Run
  • #73
  • postgres: Neon
  • api gateway
  • connect all the components together

TBA:

  • cloud storage
  • redis

service layer

  • Finish implementing the service layer:
    • article service
    • user service
    • unit testings

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.