Skip to content

Commit

Permalink
added postman docs, and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
myspace20 committed Jun 4, 2024
1 parent 28c618c commit e9388b3
Show file tree
Hide file tree
Showing 55 changed files with 2,232 additions and 263 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 100,
"printWidth": 80,
"tabWidth": 2
}
59 changes: 59 additions & 0 deletions DECISION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
## Architectural notes and Decisions

1.Diagram

![Alt text](./thread.png 'architecture diagram')

2.Database

- Used postgres due to it level of ACID compliance, scalability and community support.Redis to store temporal or data that does not need to be persisted, and also incase we ever need caching for optimizations.

3.Authentication and authorization

- Cookie and tokens with jwt tokens are used to minimize the effort of the sever in trying to manage user session, this way the browser and the server share the responsibility.

4.File storage and uploads

- Used multer for file uploads from the client and supabase storage for
as a bucket for storing the file, this way the database only stores the reference to the file as a url string, keeping the database "clean".

5.Testing

- Jest is used as the main testing library due to the robustness, and efficieny. It has a large support base too.
- Sinon is used for stubbing and mocking, because it is efficient
- Redis-mock is used for mocking redis interactions because redis works in a different way and has no clear directions on how to do this.
- The AAA pattern is used to keep the tests organised.
- Repositories are tested with a live database to ensure consistency another way would be to spy on the queries to ensure that the right sql statements are being made.
the services or use cases use stubbed versions of dependencies they rely on.

6.Data validation/Input validation

- Joi is used because it has a lot of features, mature and has a large community.

7.Job queues and workers

- Using job queues and workers to defer tasks from the main thread and bull is used due to it robustness.

8.Email Services

- Nodemailer is due to its maturity and support base.

9.Encryption standards

- RSA is used provides a safer way of encryption because keys are not shared between parties.

10.CI/CD

- Github actions is used it because the code recides in github and in this way we don't have to use another platform.

11.Monitoring

- Promclient because is the goto client library for prometheus and it has a large community.

12.Documentation

- Postman because it is feature rich and offers a platform where we can test our endpoints if the need arises.

13.Containerization

- Docker will allow devs to run code and infrasture together and most importantly to ensure consistency accross board and eliminate the "it only runs on my pc" problem.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ iii. The Infrastructure layer is responsible for communication with databases, t
- Knex with Objection Js
- Redis for Job Queues


## Development Toolkit

- typescript
Expand Down Expand Up @@ -123,7 +122,10 @@ Private Key:
```javascript
import path from 'path';

require('dotenv').config({ path: path.resolve(__dirname, '../.env'), override: true });
require('dotenv').config({
path: path.resolve(__dirname, '../.env'),
override: true,
});
```

## Workflow with Github Actions
Expand Down
11 changes: 10 additions & 1 deletion config/default.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import path = require('path');

require('dotenv').config({ path: path.resolve(__dirname, '../.env'), override: true });
require('dotenv').config({
path: path.resolve(__dirname, '../.env'),
override: true,
});

const accessTokenSigningOptions = {
issuer: 'mychats',
Expand Down Expand Up @@ -55,6 +58,10 @@ const mail = {
supportMail: process.env.REG_EMAIL as string,
};

const supabaseConnString = process.env.SUPA_BASE_CONN_STRING as string;

const supabaseKey = process.env.SUPA_BASE_KEY as string;

export default {
accessTokenSigningOptions,
accessTokenVerifyOptions,
Expand All @@ -67,4 +74,6 @@ export default {
port,
database,
mail,
supabaseKey,
supabaseConnString,
};
47 changes: 39 additions & 8 deletions database/migrations/20240218171841_initial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export async function up(knex: Knex): Promise<void> {
table.string('description', 80);
table.string('image_url');
table.enum('active', [true, false]).defaultTo(false).notNullable();
table.enum('role', ['basic', 'moderator', 'admin']).defaultTo('basic').notNullable();
table
.enum('role', ['basic', 'moderator', 'admin'])
.defaultTo('basic')
.notNullable();
table.boolean('profile_complete').defaultTo(false).notNullable();
table.timestamp('created_at').defaultTo(knex.fn.now());
table.timestamp('updated_at').defaultTo(null);
Expand All @@ -24,7 +27,11 @@ export async function up(knex: Knex): Promise<void> {
.notNullable()
.defaultTo(knex.raw('uuid_generate_v4()'));
table.boolean('valid').defaultTo(false);
table.uuid('user_id').references('users.id').notNullable().onDelete('CASCADE');
table
.uuid('user_id')
.references('users.id')
.notNullable()
.onDelete('CASCADE');
table.timestamp('created_at').defaultTo(knex.fn.now());
table.timestamp('updated_at').defaultTo(null);
})
Expand All @@ -35,7 +42,11 @@ export async function up(knex: Knex): Promise<void> {
.defaultTo(knex.raw('uuid_generate_v4()'));
table.string('title', 120).notNullable();
table.string('text', 400).notNullable();
table.uuid('user_id').references('users.id').notNullable().onDelete('CASCADE');
table
.uuid('user_id')
.references('users.id')
.notNullable()
.onDelete('CASCADE');
table.timestamp('created_at').defaultTo(knex.fn.now());
table.timestamp('updated_at').defaultTo(null);
})
Expand All @@ -46,8 +57,16 @@ export async function up(knex: Knex): Promise<void> {
.defaultTo(knex.raw('uuid_generate_v4()'));
table.string('text', 400).notNullable();
table.boolean('is_accepted').defaultTo(false);
table.uuid('thread_id').references('threads.id').notNullable().onDelete('CASCADE');
table.uuid('user_id').references('users.id').notNullable().onDelete('CASCADE');
table
.uuid('thread_id')
.references('threads.id')
.notNullable()
.onDelete('CASCADE');
table
.uuid('user_id')
.references('users.id')
.notNullable()
.onDelete('CASCADE');
table.timestamp('created_at').defaultTo(knex.fn.now());
table.timestamp('updated_at').defaultTo(null);
})
Expand All @@ -57,7 +76,11 @@ export async function up(knex: Knex): Promise<void> {
.notNullable()
.defaultTo(knex.raw('uuid_generate_v4()'));
table.string('text', 150).notNullable();
table.uuid('user_id').references('users.id').notNullable().onDelete('CASCADE');
table
.uuid('user_id')
.references('users.id')
.notNullable()
.onDelete('CASCADE');
table.uuid('thread_id').references('threads.id').onDelete('CASCADE');
table.uuid('post_id').references('posts.id').onDelete('CASCADE');
table.timestamp('created_at').defaultTo(knex.fn.now());
Expand Down Expand Up @@ -86,8 +109,16 @@ export async function up(knex: Knex): Promise<void> {
table.timestamp('updated_at').defaultTo(null);
})
.createTable('thread_tags', (table) => {
table.uuid('thread_id').references('threads.id').notNullable().onDelete('CASCADE');
table.uuid('tag_id').references('tags.id').notNullable().onDelete('CASCADE');
table
.uuid('thread_id')
.references('threads.id')
.notNullable()
.onDelete('CASCADE');
table
.uuid('tag_id')
.references('tags.id')
.notNullable()
.onDelete('CASCADE');
});
}

Expand Down
Loading

0 comments on commit e9388b3

Please sign in to comment.