This is a modular Rust web application built using Actix-web
for the backend, Tera
for templating, and HTMX
for client-side interactivity. It features structured routing, authentication, and logging with tracing
. The app serves static files, handles dynamic page rendering, and integrates easily with databases.
- Backend: Built with
Actix-web
for high-performance web server. - Templating: Uses
Tera
for flexible HTML rendering. - Dynamic Interactivity: Uses
HTMX
to add dynamic behavior without JavaScript frameworks. - Logging: Integrated with
tracing
andtracing-actix-web
for structured logging. - Modular Structure: Separated concerns for web routes, authentication, and API management.
- Error Handling: Custom 404 pages with detailed error reporting.
- Static Files: Serving static files (CSS, JS, images) with
actix-files
.
To run this project, you need the following:
-
Clone the repository:
git clone https://github.com/IAmKushagraSharma/tda-web.git cd tda-web
-
Install dependencies:
The dependencies will be installed automatically when you run the application, but you can update them with:
cargo build
-
Set up environment variables:
Create a
.env
file in the root of the project and define any necessary environment variables, such as:DATABASE_URL=your_database_url SECRET_KEY=your_secret_key
-
Run the app:
Start the server with the following command:
cargo run
By default, the server will be running on
http://127.0.0.1:3000
.
src/main.rs
: The entry point for the application, where Actix-web is configured.src/routes/
: Contains route definitions for different parts of the application, such as API, web pages, and authentication.src/services/
: Business logic and services for interacting with the database or handling specific tasks.src/models/
: Contains data models, such asUser
,Post
, etc.src/utils/
: Utility functions for validation, formatting, etc.templates/
: HTML templates for rendering pages (Tera templates).static/
: Directory for static files like CSS, JS, and images.logs/
: Log files generated during app execution.config/
: Configuration files for different environments (development, production).
This project uses HTMX
to enhance user interaction with server-side rendering. You can make dynamic requests (GET, POST) to the server without needing to reload the page. Here's an example of how HTMX is used:
<button hx-get="/some-endpoint" hx-target="#response">Fetch Data</button>
<div id="response"></div>
When the button is clicked, an HTTP request is made to /some-endpoint
, and the response will be inserted into the #response
div.
The application uses tracing
and tracing-actix-web
to handle structured logging. It logs requests, errors, and other important events. Logs are output to the console and can be configured to be written to a file.
Log levels:
INFO
: General information about the app's state.ERROR
: Logs errors encountered during execution.TRACE
: Detailed logs for debugging.
[INFO] 2024-11-29T10:00:00Z: GET /about
[ERROR] 2024-11-29T10:00:01Z: Database connection failed
If a user navigates to a non-existent route, a custom 404 page will be rendered, ensuring a smooth user experience with relevant error information.
We welcome contributions! If you'd like to contribute to this project:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make the changes and commit them.
- Push your branch and open a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
### Key Sections:
1. **Features** - Highlights the primary features of the application.
2. **Prerequisites** - Lists what is needed to run the app.
3. **Getting Started** - A step-by-step guide on setting up the app locally.
4. **Project Structure** - Explains the folder structure and where different components are located.
5. **HTMX Integration** - Describes how HTMX is used for dynamic interactions.
6. **Logging** - Explains the logging system using `tracing`.
7. **Custom 404 Pages** - Mentions the custom error pages for non-existent routes.
8. **Contributing** - Provides instructions for contributing to the project.
9. **License** - Provides licensing information.
This README covers all important aspects of your project and should be comprehensive for anyone who wishes to understand, use, or contribute to your app.