SAHIM API is the backend service that powers the SAHIM platform.
- Prerequisites
- Getting Started
- Start Development Server
- Accessing the Database
- API Documentation
- Troubleshooting
- Contributors
- Node.js (v20 or higher)
- pnpm (v10 or higher)
- Docker
Follow these steps to set up your development environment:
-
Install Dependencies
pnpm i
-
Set Up Docker Environment
docker compose up
This will set up necessary services like the database.
-
Configure Environment Variables
- Copy the example environment file:
cp .env.example .env
- Open
.envand update the variables according to your setup
- Copy the example environment file:
-
Initialize Database
pnpm prisma migrate dev
This command will:
- Create the database if it doesn't exist
- Apply all pending migrations
- Generate the Prisma Client
-
Ensure the
CHECKConstraint is AppliedPrisma does not support
CHECKconstraints, so follow this step to manually enforce it:- First, access the database (see Accessing the Database).
- Then run the following SQL command (Use shift+insert or ctrl+shift-v to paste):
ALTER TABLE "Student" ADD CONSTRAINT study_level_check CHECK ("studyLevel" >= 1 AND "studyLevel" <= 5);
This ensures that
studyLevelis always between 1 and 5.✅ To verify the constraint is applied, run:
\d+ "Student"
You should see:
Check constraints: "study_level_check" CHECK ("studyLevel" >= 1 AND "studyLevel" <= 5) -
Initialize Storage
pnpm init:storage
This will:
- Create a
storagedirectory in the root with its sub directories and files. - Generate JWT keys into
keys/for authentication
- Create a
-
Start Development Server
pnpm start:dev
The API will be available at
http://localhost:5000by default.
If you've already set up the development environment (as mentioned in Getting Started section), follow these steps to run the development server:
-
Start the PostgreSQL database:
docker compose up -d
-
Apply any pending database migrations:
pnpm prisma migrate dev
-
Start the server in development mode:
pnpm start:dev
-
Access the API:
- Default:
http://localhost:5000 - Custom: Use the PORT specified in your
.envfile
- Default:
If you need to connect to the PostgreSQL database running inside Docker, follow these steps:
1. Identify the Running Database Container First, list all running Docker containers to find the database container ID:
docker psThis will display a list of running containers. Look for the CONTAINER ID associated with your PostgreSQL instance.
2. Connect to the Database Once you have the correct CONTAINER ID, use it in the following command to enter the PostgreSQL interactive shell:
docker exec -it <container_id> psql -U postgres -d sahimReplace
<container_id>with the actual ID from Step 1.
3. Verify Connection After running the above command, you should see the PostgreSQL prompt:
sahim=#From here, you can run SQL commands to interact with your database.
Tip: sse
Shift + InsertorCtrl + Shift + Vto paste commands in the terminal.
4. List Available Tables (Optional) To check if your database has been set up correctly, run:
\dtThis will display all tables in the current schema.
When you're done, type:
\qor press Ctrl + D to exit.
SAHIM API provides two ways to access the Swagger documentation:
When running the development server, you can access the interactive Swagger UI at:
http://localhost:5000/docs
Replace
5000with your PORT.
This provides real-time documentation of all available API endpoints, request/response schemas, and authentication requirements.
For offline access or sharing with team members, you can generate static documentation:
-
Generate the static documentation files:
pnpm generate:docs
-
The documentation will be generated in the
docs/__GENERATED__/directory:swagger.json- OpenAPI specification in JSON format (git ignored)swagger.yaml- OpenAPI specification in YAML format (git ignored)index.html- Interactive documentation viewer
-
Open
docs/__GENERATED__/index.htmlin your browser to view the static documentation.
Note: The static documentation is manually generated but does not require the server to be running.
If you encounter database connection problems:
- Verify Docker containers are running:
docker compose ps - Check for conflicting PostgreSQL instances on the same port
- Ensure
.envcredentials matchdocker-compose.yml
Note: Always configure your
.envfile correctly before server startup.
Important: The database uses port 5433 to prevent conflicts. Verify your
DATABASE_URLin.env:DATABASE_URL="postgresql://postgres:postgres@localhost:5433/sahim?schema=public"
This project is developed by a team of undergraduate students at the Department of Information Technology, Faculty of Engineering and Information Technology, Taiz University.
SAHIM (Student Academic Hub for Integrated Management) is a comprehensive academic platform built as part of our final Software Engineering course (L3), applying software development principles, team collaboration practices, and agile methodology.