This repository serves as the monorepo for the Najm Course backend services. It encompasses several main services and libraries:
- najm-backend - Main application entry point that initializes the gateway service.
- najm-gateway - Acts as the API gateway, routing requests to appropriate services and providing unified API documentation.
- najm-iam - Handles identity and access management, including authentication, authorization, users, roles, and permissions.
- najm-cms - Content management system services for handling dynamic content.
- najm-exam - Examination system services including tests, questions, options, answers, and sessions.
- najm-integration - Integration services for external systems and APIs.
- najm-middleware - Middleware components for authentication, CORS, and permissions.
- najm-lib - Core library providing shared utilities for Axum, SurrealDB, JWT, Argon2, environment handling, and email services.
- najm-entity - Shared data transfer objects and error handling entities.
- najm-util - Utility functions for validation, query building, response formatting, and common operations.
- tests - Comprehensive test suite for all services.
-
Clone the repository:
git clone <repository-url> cd najmcourse-backend-service-v2
-
Set up the environment:
-
Copy the example environment file:
cp .env.example .env
For Windows-based systems:
./apply-env.ps1
For Unix-based systems:
source ./apply-env.sh
-
Modify the
.env
file with your specific configuration settings including:PORT
- Application portSURREALDB_URL
- SurrealDB connection URLSURREALDB_USERNAME
andSURREALDB_PASSWORD
- Database credentialsSURREALDB_NAMESPACE
andSURREALDB_DBNAME
- Database namespace and nameACCESS_TOKEN_SECRET
andREFRESH_TOKEN_SECRET
- JWT secrets
-
-
Install dependencies:
Ensure you have Rust installed. Then, run:
cargo fetch
-
Run the seeders (optional):
To populate the database with initial data:
cargo run --bin seeder
To run the services in development mode:
-
Start the database using Docker Compose:
docker-compose up -d surrealdb
This will start SurrealDB on port 8000.
-
Run the main API service:
cargo run --bin api
The API will be available at
http://localhost:{PORT}
where{PORT}
is defined in your.env
file. -
Run with auto-reload during development:
cargo watch -x "run --bin api"
-
Access the API documentation:
Once the service is running, visit
http://localhost:{PORT}/docs
for the Swagger UI documentation.
For production deployment:
-
Build and run using Docker Compose:
docker-compose up -d
This will build the application and start both the API service and SurrealDB.
-
Or build and run manually:
docker build -t najm-backend . docker run --name najm-backend -d --env-file .env -p ${PORT}:${PORT} najm-backend
Make sure to adjust the port mapping according to your
.env
configuration.
-
Run the tests:
cargo test -p tests
-
Fork the repository and clone it locally.
-
Create a new branch for your feature or fix:
git checkout -b feat/your-feature-name
-
Make your changes, commit them, and push to your forked repository.
-
Create a pull request to the
develop
branch of this repository.
If you encounter any issues or have questions, feel free to create a new issue in the repository.
- Language: Rust
- Web Framework: Axum
- Database: SurrealDB
- Authentication: JWT with Argon2 password hashing
- Documentation: OpenAPI/Swagger UI
- Testing: Cargo test with axum-test
- Containerization: Docker & Docker Compose
When the service is running, comprehensive API documentation is available at:
- Swagger UI:
http://localhost:{PORT}/docs
- OpenAPI JSON:
http://localhost:{PORT}/openapi.json
The API documentation includes all available endpoints, request/response schemas, and authentication requirements.
For questions or issues, please create a new issue in this repository.