An open API service indexing awesome lists of open source software.

https://github.com/devklick/to-do


https://github.com/devklick/to-do

Last synced: 11 months ago
JSON representation

Awesome Lists containing this project

README

          

# To-do List

This is a web app and API written in TypeScript, which utilises:
- [Nx Workspace](https://nx.dev/) as a monorepo
- [React](https://reactjs.org/) as the UI framework
- [Express](https://expressjs.com/) as the API framework
- [Zod](https://github.com/colinhacks/zod) for schema parsing & validation
- [Prisma](https://www.prisma.io/) as an ORM
- [Autmapper](https://automapperts.netlify.app/) to map between API and DB objects
- [Postgres](https://www.postgresql.org/) as the data store

## Purpose
It's purpose is purely for eduction and fun - I wanted to experiment with the technologies mentioned above. Because of that, it's an extremely simple application that is it's **intentionally completely over-engineered**. Because, why not?!

## The application
The app is a simple to-do tracker, where users can register accounts to create and track to-do's. Check out the [screenshots](/docs/images/screenshots/) for an idea of what it looks like.

---

# Getting started
You will need a Postgres DB instance - see [Postgres Instructions](https://www.postgresql.org/download/) (or you can try teaking the `prisma.schema` to use a different DB server).
After cloning/forking the code, you'll need an `.env` file with the following variables:
| Name | Type | Description | Example | Default |
|----------|----------|-------------------------|-------------------------|-------------------------|
| PORT | Integer | The port the API listen on for requests | 3000 | 3023 |
| DATABASE_URL | String | The URL of the database as required by Prisma. See [Postgresql Database Connectors](https://www.prisma.io/docs/concepts/database-connectors/postgresql) | `postgresql://dbuser:dbpassword@localhost:5432/todo`
| SYSTEM_USER_PASSWORD | String | A "system" user will be automatically added to the DB in a later step. This variable specifies the password for the system user. | `S00perS3cretP4ssw()rd!` | |
| JWT_SECRET | String | A secret key that will be used to sign and verify JWT's | `83TT3R_M4k3it_4G00d1` | |

## Installing dependencies
Now you have your environment variables set up, install the dependencies:
```
npm i
```
## Deploy DB schema
After installing the dependencies, youll need to deplot the latest schema:
```
npx prisma migrate dev
```
Performing the schema migration will also run the relevant processes to seed any required data in the database. If you need to re-run the seed process for whatever reason, you can do so with:
```
npx nx seed repositories-prisma-repo
```
Note that we have to execute the seed process via `nx` rather than `prisma`, as it references dependencies using the `npmScope` defined in [nx.json](nx.json).

See the [seed script](libs/repositories/prisma-repo/src/data/seed) for an idea of the data that will be added.

## Running the API
To run the API, run:
```
npx nx serve to-do-api
```

# Repo Structure
As mentioned previously, this is completely over-engineered. Below is an idea of the different areas of code in the repo and what other areas of code they depend on. Note that his can be generated by running:
```
npx nx graph
```
![Image](docs/images/nx-graph-2022-03-22.png)
## [to-do-api](apps/to-do-api/)
This is obviously the API. It is currently the main entry point in the repo.
## [api-schemas](libs/api-schemas/)
This is a folder containing multiple libraries. Each library contains the schemas that define the API contract for a specific entity.
## [service-framework](libs/service-framework/)
This is a folder which contains multiple libraries, each containing some "base" functionality that will be shared between, for example, all of ths services, or all of the controllers etc. Obviously, the API and the services depend on this.

## [services](libs/services/)
This folder contains multiple libraries, and each library is a service responsible for a specific entity.

## [mapper](libs/mapper/)
This is a lonely little library - the only one that isnt nested away inside another folder. This is the mapper that the services use to map to/from api/db models.

## [validators](libs/validators/)
This folder containes multiple libraries, and each library is a validator. Validators are similar to services, but hey are intended to be used only by the API schemas. They are for the schema to use to access the databse in order to perform certain validations, like checking whether an email address is available. Having the schemas access the database via the services would cause a circular dependency (service -> schema, schema -> service), so the validators sole purpose is for the schema to use during data validation.

## [repositories](libs/repositories/)
This folder contains libraries that are intended to provide data access. At he time of writing this, the only repository is the prisma repo, providing access to the postgres DB.

## [utilities](/libs/utilities/)
Again, a folder containng multiple libraries, where each library is a collection of utilities that provide convenient access to an area of functionality.