Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
abb4cf8
chore(backend): initial project setup with NestJS, GraphQL and Prisma
WillianSugiyama Feb 11, 2025
29389fd
feat: add prisma service and base graphql types
WillianSugiyama Feb 11, 2025
fe8c52e
feat: add user module with GraphQL resolver and service
WillianSugiyama Feb 11, 2025
cb49b51
feat(backend): add user module with GraphQL resolver and service
WillianSugiyama Feb 11, 2025
d5c8176
feat: add authentication module with JWT strategy
WillianSugiyama Feb 11, 2025
5c84ee0
feat(backend): add friendship module with GraphQL resolver and service
WillianSugiyama Feb 11, 2025
1e28ffa
test: add user module tests with 100% coverage
WillianSugiyama Feb 11, 2025
f7dd746
test: add authentication module tests with 100% coverage
WillianSugiyama Feb 11, 2025
3eef1d1
test: add friendship module tests with 100% coverage
WillianSugiyama Feb 11, 2025
2579b17
feat: add docker configuration and health check endpoint
WillianSugiyama Feb 11, 2025
576f66e
feat: add docker configuration and health check endpoint
WillianSugiyama Feb 11, 2025
89abeb1
feat(backend): add cache and notifications
WillianSugiyama Feb 11, 2025
28369b2
feat(frontend): add frontend to project
WillianSugiyama Feb 11, 2025
c90908f
feat(frontend): add login and signup page
WillianSugiyama Feb 11, 2025
015225a
fix: solve the issue on signup
WillianSugiyama Feb 11, 2025
e5b726b
feat: add search bar and fix auth logic
WillianSugiyama Feb 11, 2025
1f13234
feat: finish the frontend and refactor to components instead one file
WillianSugiyama Feb 12, 2025
6cdffc6
fix: use-profile-controller
WillianSugiyama Feb 12, 2025
3273097
fix: tests on backend
WillianSugiyama Feb 12, 2025
4a76c23
feat: add ci pipeline to run tests
WillianSugiyama Feb 12, 2025
fbcb471
feat: finish docker build and add how to run
WillianSugiyama Feb 12, 2025
f087f4c
fix: fix socket initialization on login
WillianSugiyama Feb 12, 2025
8d5c212
fix: add env example
WillianSugiyama Feb 12, 2025
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
53 changes: 53 additions & 0 deletions .github/workflows/backend-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Backend Tests

on:
push:
branches: [ main ]
paths:
- 'backend/**'
pull_request:
branches: [ main ]
paths:
- 'backend/**'

jobs:
test:
name: Run Backend Tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
run_install: false

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
working-directory: backend
run: pnpm install

- name: Run Tests
working-directory: backend
run: pnpm test
env:
JWT_SECRET: test_secret
47 changes: 47 additions & 0 deletions RUN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## First Step
copy .env.example to .env on each project folder

## To run this project, you need to have Docker and Docker Compose installed on your machine. Then, run the following command:

```bash
cd backend && pnpm docker:build && pnpm docker:up
```

## To run the frontend, you need to have Node.js and pnpm installed on your machine. Then, run the following command:

```bash
cd frontend && pnpm install && pnpm run dev
```

## Credentials:
```
[
{
email: "jane@example.com",
password: "password123",
},
{
email: "john@example.com",
password: "password123",
},
{
email: "bob@example.com",
password: "password123",
}
]
```

## About the project:
- You can sign up using the `signUp` mutation.
- You can login using the `login` mutation.
- You can create a friendship using the `createFriendship` mutation.
- You can update a friendship status using the `updateFriendship` mutation.
- You can delete a friendship using the `deleteFriendship` mutation.
- You can get a list of friends using the `friends` query.
- You can get a list of pending friend requests using the `pendingFriendRequests` query.
- You can get a list of received friend requests using the `receivedFriendRequests` query.
- You can accept a friend request using the `acceptFriendRequest` mutation.
- You can reject a friend request using the `rejectFriendRequest` mutation.
- You can delete a friend using the `deleteFriend` mutation.
- You have a websocket connection, so you can send friend requests and accept/reject them real-time.
- You have cache for some requests.
6 changes: 6 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DATABASE_URL="postgresql://user:password@localhost:5432/friend_system?schema=public"
JWT_SECRET="your-super-secret-key"
JWT_EXPIRATION="24h"
PORT=3001
REDIS_HOST=localhost
REDIS_PORT=6379
25 changes: 25 additions & 0 deletions backend/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
56 changes: 56 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# compiled output
/dist
/node_modules
/build

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# temp directory
.temp
.tmp

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
4 changes: 4 additions & 0 deletions backend/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
53 changes: 53 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Build stage
FROM node:20-alpine AS builder

# Install necessary tools
RUN apk add --no-cache curl

# Install pnpm using npm instead of corepack
RUN npm install -g pnpm

WORKDIR /app

# Copy package files
COPY package.json pnpm-lock.yaml ./

# Install ALL dependencies (including devDependencies)
RUN pnpm install --frozen-lockfile

# Copy source code and config files
COPY . .

# Generate Prisma Client
RUN pnpm prisma generate

# Clean any previous builds
RUN rm -rf dist

# Build the application
RUN pnpm build

# Production stage
FROM node:20-alpine

WORKDIR /app

# Install pnpm and netcat
RUN npm install -g pnpm && \
apk add --no-cache netcat-openbsd dos2unix

# Copy production files
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/tsconfig.json ./tsconfig.json
COPY package.json pnpm-lock.yaml setup-db.sh ./

RUN chmod +x setup-db.sh

# Expose port 3001
EXPOSE 3001

# Start the application
ENTRYPOINT ["./setup-db.sh"]
CMD ["node", "dist/src/main.js"]
99 changes: 99 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
</p>

[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest

<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg" alt="Donate us"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow" alt="Follow us on Twitter"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->

## Description

[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.

## Project setup

```bash
$ pnpm install
```

## Compile and run the project

```bash
# development
$ pnpm run start

# watch mode
$ pnpm run start:dev

# production mode
$ pnpm run start:prod
```

## Run tests

```bash
# unit tests
$ pnpm run test

# e2e tests
$ pnpm run test:e2e

# test coverage
$ pnpm run test:cov
```

## Deployment

When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information.

If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:

```bash
$ pnpm install -g mau
$ mau deploy
```

With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.

## Resources

Check out a few resources that may come in handy when working with NestJS:

- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework.
- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy).
- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/).
- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks.
- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com).
- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com).
- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs).
- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com).

## Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).

## Stay in touch

- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)

## License

Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE).
8 changes: 8 additions & 0 deletions backend/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
}
}
Loading