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

Auth features completed #13

Merged
merged 15 commits into from
Nov 28, 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
69 changes: 35 additions & 34 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
name: Trust CI

on:
push:
branches:
- main
pull_request:
branches:
- main
push:
branches:
- main
pull_request:
branches:
- main

jobs:
# Bun CI
build:
runs-on: ubuntu-latest

steps:
# Check out the repository
- name: Checkout code
uses: actions/checkout@v2

# Install Bun
- name: Install Bun
run: |
curl -fsSL https://bun.sh/install | bash
echo "$HOME/.bun/bin" >> $GITHUB_PATH

# Use Bun to install dependencies
- name: Install dependencies with Bun
run: bun install

# Run linting (optional but recommended)
- name: Run lint
run: bun run lint # If you have a linting script

# Run tests
# - name: Run tests
# run: bun test # Use Bun for running tests

# Additional jobs (e.g., for linting, testing, or other services) can be added here.
# Bun CI
build:
runs-on: ubuntu-latest

steps:
# Check out the repository
- name: Checkout code
uses: actions/checkout@v2

# Install Bun
- name: Install Bun
run: |
curl -fsSL https://bun.sh/install | bash
echo "$HOME/.bun/bin" >> $GITHUB_PATH

# Use Bun to install dependencies
- name: Install dependencies with Bun
run: bun install

# Run linting (optional but recommended)
- name: Run lint
run: bun run lint # If you have a linting script


# Run tests
# - name: Run tests
# run: bun test # Use Bun for running tests

# Additional jobs (e.g., for linting, testing, or other services) can be added here.
8 changes: 4 additions & 4 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true
"trailingComma": "es5",
"tabWidth": 4,
"semi": true,
"singleQuote": false
}
106 changes: 57 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# Trust API

Trust API is part of the **Trust** software suite build base-on REST API, designed with a **monolithic client-server architecture**. Trust API serves as the **main server**, built with high-performance technologies and leveraging built-in framework design patterns such as:
Trust API is part of the **Trust** software suite build base-on REST API, designed with a ** client-server architecture**. Trust API serves as the **main server**, built with high-performance technologies and leveraging built-in framework design patterns such as:

- Middleware Pattern
- Routing Pattern
- Dependency Injection (DI)
- Chain of Responsibility
- Modular Pattern
- Functional Programming Pattern
- Middleware Pattern
- Routing Pattern
- Dependency Injection (DI)
- Chain of Responsibility
- Modular Pattern
- Functional Programming Pattern

---

## Table of Contents

- [Entity Relationship Diagram/Database Design](#entity-relationship-diagramdatabase-design)
- [Software Architecture](#software-architecture)
- [Tech Stack](#tech-stack)
- [Setup Project](#setup-project)
- [Install Dependencies](#install-dependencies)
- [Setup `.env` File](#setup-env-file)
- [Setup Docker Compose and Dockerfile](#setup-docker-compose-and-dockerfile)
- [Run Docker](#run-docker)
- [Generate and Migrate Prisma](#generate-and-migrate-prisma)
- [API Endpoints](#api-endpoints)
- [License](#license)
- [Entity Relationship Diagram/Database Design](#entity-relationship-diagramdatabase-design)
- [Software Architecture](#software-architecture)
- [Tech Stack](#tech-stack)
- [Setup Project](#setup-project)
- [Install Dependencies](#install-dependencies)
- [Setup `.env` File](#setup-env-file)
- [Setup Docker Compose and Dockerfile](#setup-docker-compose-and-dockerfile)
- [Run Docker](#run-docker)
- [Generate and Migrate Prisma](#generate-and-migrate-prisma)
- [API Endpoints](#api-endpoints)
- [License](#license)

---

Expand All @@ -41,14 +41,14 @@ Trust using Monolithic Client-Server Architecture connected each other, see the

## Tech Stack

- **Hono**: A lightweight, high-performance web framework ideal for creating fast APIs with built-in middleware and routing.
- **PostgreSQL**: A powerful, open-source relational database used for reliable and efficient data storage.
- **Prisma**: An ORM (Object-Relational Mapping) tool that simplifies database management and queries in a type-safe manner.
- **TypeScript**: A superset of JavaScript providing static typing and better tooling for large codebases.
- **ESLint**: A code linter that helps maintain code quality and consistency by detecting and fixing problematic patterns.
- **Prettier**: An opinionated code formatter to ensure consistent code style across the project.
- **OpenAPI Swagger**: A tool to design and document APIs, ensuring clear and structured API specifications.
- **Scalar**: A library for defining GraphQL scalar types, enabling custom data types for API development.
- **Hono**: A lightweight, high-performance web framework ideal for creating fast APIs with built-in middleware and routing.
- **PostgreSQL**: A powerful, open-source relational database used for reliable and efficient data storage.
- **Prisma**: An ORM (Object-Relational Mapping) tool that simplifies database management and queries in a type-safe manner.
- **TypeScript**: A superset of JavaScript providing static typing and better tooling for large codebases.
- **ESLint**: A code linter that helps maintain code quality and consistency by detecting and fixing problematic patterns.
- **Prettier**: An opinionated code formatter to ensure consistent code style across the project.
- **OpenAPI Swagger**: A tool to design and document APIs, ensuring clear and structured API specifications.
- **Scalar**: A library for defining GraphQL scalar types, enabling custom data types for API development.

---

Expand All @@ -57,13 +57,15 @@ Trust using Monolithic Client-Server Architecture connected each other, see the
### Install Dependencies

Run the following command to install the required dependencies:

```bash
bun install
```

### Setup .env file

Create a .env file in the root directory with the following values:

```yaml
TOKEN_SECRET=

Expand All @@ -77,32 +79,35 @@ DATABASE_URL=
### Setup Docker Compose and Dockerfile

Use the configuration below for docker-compose.yml:

```yaml
services:
backend:
build: .
ports:
- "3000:3000"
env_file:
- path: .env.render
required: true
depends_on:
- database
database:
image: postgres:alpine
ports:
- "5432:5432"
env_file:
- path: .env
required: true
command: ["postgres", "-c", "log_statement=all"]
backend:
build: .
ports:
- "3000:3000"
env_file:
- path: .env.render
required: true
depends_on:
- database
database:
image: postgres:alpine
ports:
- "5432:5432"
env_file:
- path: .env
required: true
command: ["postgres", "-c", "log_statement=all"]
# volumes:
# - postgres-data:/var/lib/postgresql/data

# volumes:
# postgres-data:
```

.dockerfile:

```yaml
# Use Bun image from the Docker Hub
FROM oven/bun:debian
Expand All @@ -126,13 +131,15 @@ CMD ["bun", "start"]
### Run docker

To start the services, run the following command:

```bash
docker-compose up -d
```

### Generate and Migrate Prisma

Run the following commands to generate the Prisma client and apply database migrations:

```bash
bun run generate
bun run db:migrate:dev
Expand All @@ -142,13 +149,14 @@ bun run db:migrate:dev

The following table lists the available authentication-related endpoints:

| Method | Endpoint | Description |
|--------|----------------|---------------------------|
| POST | `/auth/register` | Register a new user |
| POST | `/auth/login` | Login to an account |
| GET | `/auth/me` | Get user information |
| Method | Endpoint | Description |
| ------ | ---------------- | -------------------- |
| POST | `/auth/register` | Register a new user |
| POST | `/auth/login` | Login to an account |
| GET | `/auth/me` | Get user information |

---

## License
This project is licensed under the MIT License. See the [License](LICENSE) file for details.

This project is licensed under the MIT License. See the [License](LICENSE) file for details.
Binary file modified bun.lockb
Binary file not shown.
43 changes: 26 additions & 17 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
services:
backend:
build: .
ports:
- "3000:3000"
env_file:
- path: .env.render
required: true
depends_on:
- database
database:
image: postgres:alpine
ports:
- "5432:5432"
env_file:
- path: .env
required: true
command: ["postgres", "-c", "log_statement=all"]
# backend:
# build: .
# ports:
# - "3000:3000"
# env_file:
# - path: .env.render
# required: true
# depends_on:
# - database
# - cache
database:
image: postgres:alpine
ports:
- "5432:5432"
env_file:
- path: .env
required: true
command: ["postgres", "-c", "log_statement=all"]
redis:
image: redis:latest
container_name: redis
restart: always
# volumes:
# - redis_volume_data:/data
ports:
- 6380:6380
# volumes:
# - postgres-data:/var/lib/postgresql/data

Expand Down
8 changes: 4 additions & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
eslint.configs.recommended,
...tseslint.configs.recommended
);
Loading