A comprehensive multi-file Sentra project demonstrating real-world application structure with imports, modules, and proper separation of concerns.
example-project/
├── main.sn # Entry point
├── sentra.toml # Project configuration
├── config/
│ └── settings.sn # Application configuration
├── src/
│ ├── app.sn # Application core logic
│ ├── controllers/ # Business logic controllers
│ │ ├── task_controller.sn
│ │ └── user_controller.sn
│ ├── models/ # Data models
│ │ ├── task.sn
│ │ └── user.sn
│ ├── services/ # External services
│ │ ├── auth.sn
│ │ └── database.sn
│ └── utils/ # Utility functions
│ ├── hash.sn
│ ├── id_generator.sn
│ ├── logger.sn
│ └── validator.sn
├── tests/ # Unit tests
│ └── task_controller_test.sn
└── lib/ # Shared libraries
This project showcases Sentra's import system:
import "./src/app.sn" as app
import "./config/settings.sn" as config
import "../models/task.sn" as Task
import "../services/database.sn" as db
import "./controllers/task_controller.sn" as TaskController
import "./utils/logger.sn" as logger
Each module exports functions and variables:
// In task_controller.sn
export fn create_task(title, priority, user_id) { ... }
export fn get_all_tasks() { ... }
// Used in app.sn
let task = TaskController.create_task("New Task", "High", user_id)
- User authentication and management
- Task creation and management
- Priority-based task organization
- Task statistics and reporting
- Mock database with CRUD operations
- Structured logging system
- Input validation and sanitization
- Models: Define data structures (User, Task)
- Controllers: Handle business logic
- Services: External service integration (auth, database)
- Utils: Reusable utility functions
- Config: Centralized configuration management
sentra run main.snsentra test tests/task_controller_test.snsentra build
./task-manager # or task-manager.exe on Windowssentra fmt src/**/*.snsentra check main.sn- Module System: Each file is a module that can export functions and variables
- Namespace Management: Using aliases to avoid naming conflicts
- Separation of Concerns: Clear separation between models, controllers, and services
- Mock Services: Database service demonstrates how external services would be integrated
- Error Handling: Try-catch blocks for error handling
- Validation: Input validation before processing
- Logging: Structured logging with different log levels
- Configuration: Centralized configuration management
- Testing: Unit tests for controllers
Sentra resolves imports in the following order:
- Relative paths (starting with
./or../) - Project root paths
- Standard library modules
- External packages (from sentra.mod)
- Use clear module aliases:
import "./long/path/to/module.sn" as Module - Export only what's needed: Keep internal functions private
- Organize by feature: Group related functionality together
- Validate inputs: Always validate external inputs
- Handle errors gracefully: Use try-catch for error handling
- Log important events: Use structured logging for debugging
- Write tests: Test critical business logic
To add new features:
- Create new model in
src/models/ - Add controller in
src/controllers/ - Update services if needed
- Import and use in
app.sn - Add tests in
tests/
Example: Adding a Comment feature
// src/models/comment.sn
export fn new(id, task_id, user_id, text) {
return {
"id": id,
"task_id": task_id,
"user_id": user_id,
"text": text,
"created_at": now()
}
}
// src/controllers/comment_controller.sn
import "../models/comment.sn" as Comment
export fn create_comment(task_id, user_id, text) {
return Comment.new(generate_id(), task_id, user_id, text)
}
MIT License - Feel free to use this as a template for your Sentra projects!