β οΈ Project under active development: Some features may be incomplete, unstable, or not working as expected. Please open an issue for any bug or suggestion!
A robust and modern database management API built with Hono, Sequelize, and TypeScript. JamesDBBApi provides a powerful RESTful interface to manage multiple databases, create dynamic schemas, and execute queries securely.
- Multiple DBMS support: SQLite, PostgreSQL, MySQL, MariaDB, MSSQL
- Simultaneous connections: Manage multiple databases in parallel
- Health checks: Real-time monitoring of connection status
- Dynamic configuration: Add/remove databases on the fly
- Dynamic table creation: REST API to define your schemas
- Advanced validation: Strict validation of data structures
- Extended types: Support for 25+ SQL data types
- Constraints and indexes: Complete management of constraints and indexes
- JWT authentication: Token-based authentication system
- Role-based authorization: Granular access control
- Rate limiting: Protection against abuse and DDoS attacks
- Security headers: CORS, CSRF, HSTS, and more
- Structured logging: Detailed logs with configurable levels
- Real-time metrics: Monitoring endpoints and metrics
- Optimizations: Connection pooling, cache, and SQL optimizations
- Node.js >= 18.0.0 or Bun >= 1.0.0
- A supported database (optional, SQLite by default)
Not using Bun yet ?
Windows : powershell -c "irm bun.sh/install.ps1 | iex"
Linux/Macos : curl -fsSL https://bun.sh/install | bash# Clone the project
git clone https://github.com/Nokaji/JamesDBBApi
cd JamesDBBApi
# Install dependencies
bun install
# Copy configuration
cp .env.example .env
# Start in development mode
bun run devEdit the .env file according to your needs:
# Application configuration
NODE_ENV=development
APP_PORT=3000
APP_HOST=localhost
API_VERSION=v1
# Primary database (SQLite by default)
DB_DIALECT=sqlite
SQLITE_PATH=./data/james.db
# Security
# IMPORTANT : Ne pas mettre de guillemets autour de la valeur !
JWT_SECRET=your-super-secret-jwt-key-here
CORS_ORIGINS=http://localhost:3000# Development with auto-reload
bun run dev
# Production
bun run prod
# With Docker
docker build -t JamesDBBApi .
docker run -p 3000:3000 JamesDBBApi# Health check
curl http://localhost:3000/health
# API info
curl http://localhost:3000/apicurl -X POST http://localhost:3000/api/_schema/primary/tables \
-H "Content-Type: application/json" \
-d '{
"table_name": "users",
"columns": [
{
"name": "id",
"type": "integer",
"primary_key": true,
"auto_increment": true
},
{
"name": "email",
"type": "email",
"unique": true,
"nullable": false
},
{
"name": "name",
"type": "string",
"length": 100,
"nullable": false
},
{
"name": "created_at",
"type": "timestamp",
"default_value": "CURRENT_TIMESTAMP"
}
]
}'| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Root endpoint (Welcome + info) |
| GET | /api |
API information |
| GET | /health |
Health check |
| GET | /metrics |
System metrics |
| GET | /docs |
Documentation (Swagger UI) |
| GET | /swagger.json |
OpenAPI/Swagger spec |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/v1/ |
API info (versionnΓ©) |
| GET | /api/v1/schema |
Schema routes |
| GET | /api/v1/database |
Database routes |
| GET | /api/v1/relation |
Relation routes |
Les routes
/api/v1/schema,/api/v1/database,/api/v1/relationsont des points d'entrΓ©e pour les sous-routes dΓ©finies dansroutes/schema.routes.ts,routes/database.routes.ts,routes/relation.routes.ts.
The authtification is in the header:
Authorization : Bearer {JWT_SECRET IN YOUR .ENV}
/api/v1/schema: gestion des schΓ©mas de BDD/api/v1/database: gestion des connexions et opΓ©rations BDD/api/v1/relation: gestion des relations entre tables
curl -X POST http://localhost:3000/api/_database/connect \
-H "Content-Type: application/json" \
-d '{
"name": "postgres_main",
"config": {
"dialect": "postgres",
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "password",
"database": "my_app"
}
}'curl -X POST http://localhost:3000/api/_schema/postgres_main/tables \
-H "Content-Type: application/json" \
-d '{
"table_name": "products",
"columns": [
{
"name": "id",
"type": "uuid",
"primary_key": true,
"default_value": "uuid_generate_v4()"
},
{
"name": "name",
"type": "string",
"length": 255,
"nullable": false
},
{
"name": "price",
"type": "decimal",
"precision": 10,
"scale": 2,
"validate": {
"min": 0
}
},
{
"name": "category_id",
"type": "integer",
"foreign_key": {
"table": "categories",
"column": "id",
"on_delete": "CASCADE"
}
}
],
"indexes": [
{
"name": "idx_products_name",
"columns": ["name"],
"unique": false
},
{
"name": "idx_products_category",
"columns": ["category_id"],
"type": "BTREE"
}
]
}'curl -X POST http://localhost:3000/api/_database/postgres_main/query \
-H "Content-Type: application/json" \
-d '{
"query": "SELECT * FROM products WHERE price > 100 ORDER BY name LIMIT 10",
"type": "SELECT"
}'| Variable | Description | Default | Example |
|---|---|---|---|
NODE_ENV |
Runtime environment | development |
production |
APP_PORT |
Listening port | 3000 |
8080 |
LOG_LEVEL |
Log level | info |
debug |
JWT_SECRET |
JWT secret key | Auto-generated | your-secret-key |
RATE_LIMIT_MAX_REQUESTS |
Request limit | 100 |
1000 |
integer,int- Standard integersmallint- Small integerbigint- Large integerfloat,double- Floating point numbersdecimal,numeric- Precise decimal numbers
string,varchar- Variable character stringchar- Fixed character stringtext- Long textemail- Email with validationurl- URL with validation
timestamp,datetime- Date and timedate- Date onlytime- Time only
boolean- Booleanuuid- Unique identifierjson,jsonb- JSON datablob- Binary data
// Client-side example
const response = await fetch("/api/auth/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
username: "admin",
password: "password",
}),
});
const { token } = await response.json();
// Using the token
const apiResponse = await fetch("/api/_database", {
headers: {
Authorization: `Bearer ${token}`,
},
});
```javascript
#### Authorization Middleware
```typescript
import { authenticate, authorize, requireRole } from "./middlewares/auth";
// Protected routes
app.use("/api/_database/*", authenticate());
app.use("/api/_schema/*/tables", authorize("database:write"));
app.use("/api/admin/*", requireRole("admin"));# Development
bun run dev # Start with auto-reload
bun run build # Build for production
bun run start # Run built version
# Testing
bun run test # Run tests
bun run test:watch # Tests in watch mode
# Code quality
bun run lint # Check code style
bun run format # Format code
# Database
bun run db:migrate # Apply migrations
bun run db:seed # Seed with test data
bun run db:reset # Reset database
# Docker
bun run docker:build # Build Docker image
bun run docker:run # Run containerJamesDBBApi/
βββ controllers/ # Controllers (to be implemented)
βββ managers/
β βββ ConfigManager.ts # Configuration manager
βββ middlewares/
β βββ auth.ts # JWT authentication
β βββ databaseManager.ts # Database manager
β βββ rateLimiter.ts # Rate limiting
βββ routes/
β βββ _database.routes.ts # Database routes
β βββ _schema.routes.ts # Schema routes
βββ utils/
β βββ convert.ts # Schema conversion
β βββ logging.ts # Logging system
β βββ runtime.ts # Runtime detection
β βββ types.ts # TypeScript types
βββ index.ts # Entry point
βββ package.json
βββ tsconfig.json
βββ .env.example
# Detailed health check
curl http://localhost:3000/health
# System metrics
curl http://localhost:3000/metrics
# Rate limiter status
curl http://localhost:3000/api/_database/rate-limit-statusLogs are structured and include:
- Timestamp: Precise timestamp
- Logger: Log source (DatabaseManager, AuthManager, etc.)
- Level: Log level (DEBUG, INFO, WARN, ERROR)
- Message: Detailed message
Example:
[2025-07-11T10:30:45.123Z] [DatabaseManager] [INFO]: Database 'primary' added and connected successfully
[2025-07-11T10:30:45.456Z] [AuthManager] [WARN]: Token expired for user john.doe
- HTTPS required in production
- Strict input validation
- Rate limiting by IP and user
- Automatic security headers
- SQL sanitization via Sequelize
- Change default secrets in production
- Use HTTPS only in production
- Limit database user permissions
- Monitor logs regularly
- Update dependencies regularly
- Fork the project
- Create a branch for your feature
- Develop following conventions
- Test your code
- Create a Pull Request
- Strict TypeScript enabled
- ESLint and Prettier for style
- Unit tests required for new features
- Public API documentation
- GraphQL interface
- Integrated Redis cache
- Automatic migrations
- Web administration interface
- Clustering and load balancing
- Complete audit trail
- Automatic backup
- API Analytics
# Check configuration
curl http://localhost:3000/health
# Check logs
tail -f logs/app.log# Adjust in .env
RATE_LIMIT_MAX_REQUESTS=1000
RATE_LIMIT_WINDOW_MS=3600000# Generate new secret
JWT_SECRET=$(openssl rand -base64 32)- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Wiki
This project is licensed under the MIT License. See the LICENSE file for more details.
JamesDBBApi - A modern database API for your applications π
Developed with β€οΈ by Nokaji