Skip to content

Commit 0a64226

Browse files
authored
Merge pull request #1 from valeeraZ/dev
Dev
2 parents 93eaefb + 868ddc1 commit 0a64226

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+9709
-11028
lines changed

.github/workflows/python_tests.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Testing Server
2+
3+
on: push
4+
5+
jobs:
6+
black:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: Set up Python
11+
uses: actions/setup-python@v2
12+
with:
13+
python-version: '3.11'
14+
- name: Install and configure Poetry
15+
uses: snok/install-poetry@v1
16+
with:
17+
virtualenvs-create: false
18+
- name: Install deps
19+
run: |
20+
cd server
21+
poetry install
22+
working-directory: ./server
23+
- name: Run black check
24+
run: poetry run --directory server black --check .
25+
flake8:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v2
29+
- name: Set up Python
30+
uses: actions/setup-python@v2
31+
with:
32+
python-version: '3.11'
33+
- name: Install and configure Poetry
34+
uses: snok/install-poetry@v1
35+
with:
36+
virtualenvs-create: false
37+
- name: Install deps
38+
run: |
39+
cd server
40+
poetry install
41+
working-directory: ./server
42+
- name: Run flake8 check
43+
run: |
44+
cd server
45+
poetry run --directory server flake8 --count
46+
mypy:
47+
runs-on: ubuntu-latest
48+
steps:
49+
- uses: actions/checkout@v2
50+
- name: Set up Python
51+
uses: actions/setup-python@v2
52+
with:
53+
python-version: '3.11'
54+
- name: Install and configure Poetry
55+
uses: snok/install-poetry@v1
56+
with:
57+
virtualenvs-create: false
58+
- name: Install deps
59+
run: |
60+
cd server
61+
poetry install
62+
working-directory: ./server
63+
- name: Run mypy check
64+
run: poetry run --directory server mypy .
65+
unittest:
66+
runs-on: ubuntu-latest
67+
steps:
68+
- uses: actions/checkout@v2
69+
- name: Set up Python
70+
uses: actions/setup-python@v2
71+
with:
72+
python-version: '3.11'
73+
- name: Install and configure Poetry
74+
uses: snok/install-poetry@v1
75+
with:
76+
virtualenvs-create: false
77+
- name: Install deps
78+
run: |
79+
cd server
80+
poetry install
81+
working-directory: ./server
82+
- name: Run unittests
83+
run: |
84+
cd server
85+
poetry run python -m unittest discover

README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,34 @@
22

33
This project template using ReactJS & Python that can be used for Descartes Underwriting technical test.
44

5-
To install and run this template, use
5+
To install and run this project:
66

7-
```bash
8-
npm install
9-
npm start
107
```
8+
docker-compose up --build
9+
```
10+
11+
The first install and run will take a while, because it will install all the dependencies and build the images.
12+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
13+
14+
To run separately the server or client, please see the README.md in the server and client folders.
15+
16+
# Demo
17+
18+
https://github.com/valeeraZ/descartes-app/assets/39196828/ec9373bd-5797-46e6-94e8-e57cddd863ba
19+
20+
21+
# Architecture
22+
![archi-descartes](https://github.com/valeeraZ/descartes-app/assets/39196828/c953f735-4668-4f02-87c0-b5f282a30839)
23+
24+
25+
The server is a FastAPI application that uses a PostgreSQL database. The client is a React application with Next.js that uses the server API.
26+
27+
For the server, the FastAPI uses a router to handle the requests. The router uses a query service and a command service to handle the business logic with the contact read model and write model. The service uses a repository to access a PostgreSQL database by CRUD actions with SQLAlchemy models.
28+
29+
# CI/CD
30+
31+
32+
The CI/CD is done with Github Actions. The workflow is triggered on push and pull request on the main branch. The workflow will run the unit tests and the linter of the code in server.
1133

1234
# Instructions
1335

client/.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}

client/.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env*.local
29+
30+
# vercel
31+
.vercel
32+
33+
# typescript
34+
*.tsbuildinfo
35+
next-env.d.ts

client/Dockerfile

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
FROM node:18-alpine AS base
2+
3+
# Install dependencies only when needed
4+
FROM base AS deps
5+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
6+
RUN apk add --no-cache libc6-compat
7+
WORKDIR /app
8+
9+
# Install dependencies based on the preferred package manager
10+
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
11+
RUN \
12+
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
13+
elif [ -f package-lock.json ]; then npm ci; \
14+
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
15+
else echo "Lockfile not found." && exit 1; \
16+
fi
17+
18+
19+
# Rebuild the source code only when needed
20+
FROM base AS builder
21+
WORKDIR /app
22+
COPY --from=deps /app/node_modules ./node_modules
23+
COPY . .
24+
25+
# Next.js collects completely anonymous telemetry data about general usage.
26+
# Learn more here: https://nextjs.org/telemetry
27+
# Uncomment the following line in case you want to disable telemetry during the build.
28+
# ENV NEXT_TELEMETRY_DISABLED 1
29+
30+
RUN yarn build
31+
32+
# If using npm comment out above and use below instead
33+
# RUN npm run build
34+
35+
# Production image, copy all the files and run next
36+
FROM base AS runner
37+
WORKDIR /app
38+
39+
ENV NODE_ENV production
40+
# Uncomment the following line in case you want to disable telemetry during runtime.
41+
# ENV NEXT_TELEMETRY_DISABLED 1
42+
43+
RUN addgroup --system --gid 1001 nodejs
44+
RUN adduser --system --uid 1001 nextjs
45+
46+
COPY --from=builder /app/public ./public
47+
48+
# Automatically leverage output traces to reduce image size
49+
# https://nextjs.org/docs/advanced-features/output-file-tracing
50+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
51+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
52+
53+
USER nextjs
54+
55+
EXPOSE 3000
56+
57+
ENV PORT 3000
58+
59+
# Set the environment variable for the API URL
60+
ARG REACT_APP_API_URL
61+
ENV REACT_APP_API_URL=$REACT_APP_API_URL
62+
63+
64+
# Start the application
65+
CMD ["node", "server.js"]

client/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2+
3+
## Getting Started
4+
5+
First, use the `docker-compose` file in root folder to run the API server for data:
6+
7+
```bash
8+
cd ..
9+
docker-compose up -d db api
10+
```
11+
12+
Then, run the development server:
13+
14+
```bash
15+
npm run dev
16+
# or
17+
yarn dev
18+
# or
19+
pnpm dev
20+
```
21+
22+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

client/next.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
prerender: false,
4+
output: 'standalone',
5+
}
6+
7+
module.exports = nextConfig

0 commit comments

Comments
 (0)