This is a hybrid Next.js + Python app that uses Next.js as the frontend and FastAPI as the API backend.
Role | Username | Password |
---|---|---|
Staff | staff | staff123 |
HR | admin | admin123 |
Manager | manager | manager123 |
- How it Works
- Getting Started
- Running Unit and Integration Tests
- Fixing Typescript Linting error
- Staging Commits
- Branching and opening pull requests
- Database Migrations
- Continous Integration
- Continous Deployment
- Scheduled Telegram PR Reminders
- Icons used
- Theming System
The Python/FastAPI server is mapped into to Next.js app under /api/.
This is implemented using next.config.js
rewrites to map any request to /api/:path* to the FastAPI API, which is hosted in the /api
folder.
On localhost, the rewrite will be made to the 127.0.0.1:8000
port, which is where the FastAPI server is running.
In production, the FastAPI server is hosted as Python serverless functions on Vercel.
Automated Doc with Swagger UI has been set up under /docs
route.
The frontend NextJs app is routed by default to the 127.0.0.1:3000
port.
pip install pipenv
or
pip3 install pipenv
brew install pipenv
First, install the dependencies
# nodejs / js
npm i
or
npm install
# python (additional dependencies needed to be specified as an argument after 'install', pipfile will auto update)
pipenv install
To activate the created venv:
pipenv shell
Second, install pre-commit hooks if you are developing
pipenv install pre-commit
pre-commit install
# check that pre-commit file is crated in .git/hooks
# if existing work has not been formatted
pre-commit run --all-files
# if it's been a long time, update hooks to latest ver
pre-commit autoupdate
Following the .env.example
file create a .env
file with the same fields and populate it with the appropriate fields. Please contact us for our AWS RDS string and credentials
# Clerk RBAC
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/dashboard
NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/dashboard
# Database Connection String
AWS_RDS_MYSQL_URL =
Then, run the development server:
npm run dev
By default the FastApi server will be running on http://127.0.0.1:8000, while the NextJs frontend will be running on http://127.0.0.1:3000.
Run the command below to run all backend unit and integration tests, -v and -s are optional flags to show more details about the tests and to show print statements respectively. Ensure pipenv shell
is activated before running the command.
pytest . -v -s
- Install ESLint extension for VSCode, other helpful extensions are Prettier, Tailwind CSS, and Error Lens.
- Run
npm run lint:fix
to check for and fix linting errors. - If there are errors that cannot be fixed automatically, you will have to check the cli for the errors and fix them manually.
Pre-commit
offloads some of the work of github CI unit testing to local dev environment for
- Speed in identifying failed tests
- Ease of use instead of running unit tests manually each time
- Security in case bad code is written - tests are broken and user is notified even before committing
- Standardization of code formatting and linting (for python files)
-
Include issue ID in the branch name to link the issue to a Pull/Merge Request. The fastest way to link to issues is to use Linear's branch name feature by clicking on the top right button 'Copy git branch name action' when viewing an issue.
-
Create a branch from main by pasting the branch name copied from the previous step. The branch name should look like
feature/spm-4-connect-github-or-gitlab
. -
Switch to the new branch locally and make your changes.
-
Commit as you normally would, since we are not tracking commits.
-
When opening or merging a PR, make sure to link the PR on linear.
-
An auto-generated URL to the Linear issue should have been automatically added to the PR description. The Linear issue will be automatically updated accordingly with the new timeline and URL to the Github PR too.
With Alembic, revisions to models via sqlalchemy can be used to automatically migrate the database, reducing the hassle of manual database reconfiguration
View current db version
alembic current
After modifying ORM code / models
alembic revision --autogenerate -m "YOUR MIGRATION MESSAGE"
After checking the generated revisions are okay
alembic upgrade HEAD
# alternatively specify the revision hash initials to upgrade to a specific version
To downgrade to the previous version
alembic downgrade -1
# alternatively specify the revision hash initials to downgrade to a specific version
# or alembic downgrade base to reset to initial state
We have 2 CI workflows: on_main.yaml
and on_pr_open.yaml
. These integrations are run on every push to main and every PR open respectively.
Within each workflow, we run an assortment of checks and tests to ensure that the code is up to standard. These include:
- linting-next
- build-next
- unit-test-next
- linting-fastapi
- build-fastapi
- unit-test-fastapi
We have CD which deploys to preview on every PR open and to production on every push to main. This is done via Vercel's Github integration.
We have a scheduled telegram reminder that sends a message to the telegram group every 4 hours to remind users to review PRs. This is done via Github Actions and a Telegram bot the script for it can be found in the .github/workflows folder labeled PR_notif.yaml
and get-open-prs.js
.
We are using Radix icons or Lucide for our icons.
We are using shadcn's theme for convenience.
Refer to tailwind.config.ts
for list of classes (under theme.extend.colors
) that can be used to style the components. e.g. bg-primary
.
Do not use the default tailwind classes (e.g. bg-blue-500
).