Skip to content

Commit ffd6879

Browse files
committed
update documentation for root
1 parent 127cb5e commit ffd6879

File tree

9 files changed

+354
-453
lines changed

9 files changed

+354
-453
lines changed

README.md

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,80 @@
11
<div align="center">
22
<h1>Root</h1>
3-
<p>a backend to manage all club information</p>
3+
<p>A GraphQL backend for managing club member information</p>
44
</div>
55

6-
### Overview
7-
**Root** is a backend for managing all club related info; most other projects will be getting or publishing their data to root.
6+
---
87

9-
### Documentation
8+
Root is our club's backend, responsible for collecting and distributing data from and to all the other services including [Home](https://www.github.com/amfoss/home), [amD](https://www.github.com/amfoss/amd) and [Presense](https://www.github.com/amfoss/presense). The idea is to have all our data easily available in one place and to let every other end-user applications to be standalone. This ensures there's no single point of failure for all our infrastructure (as was the case with our previous CMS). Though Root going down would definitely cause a few features to stop working on the other apps.
109

11-
Explore the [Documentation](/docs/docs.md) for detailed information and usage guidelines.
10+
# Quick Setup
1211

13-
---
12+
1. Install prerequisites:
13+
- Rust (latest stable should work fine)
14+
- PostgreSQL
15+
- SQLx CLI: `cargo install sqlx-cli`
16+
17+
2. Configure environment:
18+
```bash
19+
touch .env
20+
```
21+
22+
The following environment variables are required:
23+
* DATABASE_URL: Connection string to your DB.
24+
* RUST_ENV: Use "development" or "production" as applicable.
25+
* ROOT_SECRET: Used to verify the origin of mutation requests on attendance. Ask the maintainers for it.
26+
* BIND_ADDRESS: The IP address for `axum` to serve to. Typically `0.0.0.0:3000` for local deployments.
27+
28+
3. Setup database:
29+
```bash
30+
sqlx database create
31+
sqlx migrate run
32+
```
33+
34+
4. Run server:
35+
```bash
36+
cargo run
37+
```
38+
39+
GraphQL playground should be available at `http://localhost:8000/graphiql` as long as it's in development mode.
40+
41+
# Documentation
42+
43+
See the [documentation](docs/docs.md) for the API reference, database schema and other detailed documentation.
44+
45+
# Contributing
46+
47+
## Reporting Issues
48+
49+
If you encounter a bug, please check existing issues first to avoid duplicates. If none exist, create a new issue with the following details:
50+
51+
* Title: Concise summary.
52+
* Description: A detailed description of the issue.
53+
* Steps to Reproduce: If it's a bug, include steps to reproduce.
54+
* Expected and Actual Behavior: Describe what you expected and what actually happened.
55+
56+
## Suggesting Features
57+
58+
We welcome new ideas! Please open an issue titled "Feature Request: `<Feature Name>`" and provide:
59+
60+
* Problem: What problem does this feature solve?
61+
* Solution: Describe how you envision it working.
62+
* Alternatives Considered: Mention any alternatives you've considered.
63+
64+
## Submitting Code Changes
65+
66+
If you'd like to fix a bug, add a feature, or improve code quality:
67+
68+
* Check the open issues to avoid redundancy.
69+
* Open a draft PR if you'd like feedback on an ongoing contribution.
70+
71+
## Coding Standards
1472

15-
### How to Contribute
73+
* Follow Rust Conventions: Use idiomatic Rust patterns. Use `cargo fmt` and `cargo clippy` to format and lint your code.
74+
* Modularity: Write modular, reusable functions. Avoid monolithic code.
75+
* Descriptive Naming: Use descriptive names for variables, functions, and types.
76+
* Don't worry too much about rules, it just needs to be pretty. Most editors have built-in tools to do this for you.
1677

17-
1. Fork the repository and clone it to your local machine.
18-
2. Set up the project by following the installation instructions above.
19-
3. Identify an issue or feature you'd like to work on, and create an issue to track it.
20-
4. Develop the patch or feature, ensuring it is thoroughly tested.
21-
5. Submit a pull request, referencing the relevant issue number.
78+
# License
2279

23-
### License
2480
This project is licensed under GNU General Public License V3. You are welcome to adapt it, make it yours. Just make sure that you credit us too.

docs/attendance.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Attendance System
2+
3+
Track daily member attendance and generate monthly attendance summaries. The summaries are used for quick access to see how many days a member has attended in a specific month, used in the amD attendance report.
4+
5+
## Models
6+
7+
### Attendance
8+
```rust
9+
struct Attendance {
10+
attendance_id: i32,
11+
member_id: i32,
12+
date: NaiveDate,
13+
is_present: bool,
14+
time_in: Option<NaiveTime>,
15+
time_out: Option<NaiveTime>,
16+
created_at: NaiveDateTime,
17+
updated_at: NaiveDateTime,
18+
}
19+
```
20+
The final two fields are not exposed in the interface for obvious reasons.
21+
22+
### AttendanceSummary
23+
Monthly attendance summary for each member.
24+
```rust
25+
struct AttendanceSummary {
26+
member_id: i32,
27+
year: i32,
28+
month: i32,
29+
days_attended: i32,
30+
}
31+
```
32+
33+
## Queries
34+
35+
### Mark Attendance
36+
Record a member's attendance for the day.
37+
38+
```graphql
39+
mutation {
40+
markAttendance(
41+
input: {
42+
memberId: 1
43+
date: "2025-01-15"
44+
timeIn: "09:00:00"
45+
timeOut: "17:00:00"
46+
}
47+
) {
48+
attendanceId
49+
isPresent
50+
timeIn
51+
timeOut
52+
}
53+
}
54+
```
55+
56+
### Get Attendance Summary
57+
Get monthly attendance summary for a member.
58+
59+
```graphql
60+
query {
61+
attendanceSummary(memberId: 1) {
62+
year
63+
month
64+
daysAttended
65+
}
66+
}
67+
```
68+
69+
## Daily Task
70+
71+
The `src/daily_task/daily_task.rs` system automatically updates attendance summaries at midnight.

docs/database.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Database Migrations
2+
3+
## Overview
4+
Database schema is managed using SQLx migrations. Do not tamper with the database yourself (using clients such as psql) or with the migrations files.
5+
6+
## Current Schema
7+
8+
The entire schema, including constraints, is visible in `migrations/`.
9+
10+
### Member Table
11+
```sql
12+
CREATE TABLE Member (
13+
member_id SERIAL PRIMARY KEY,
14+
roll_no VARCHAR NOT NULL UNIQUE,
15+
name VARCHAR NOT NULL,
16+
email VARCHAR NOT NULL UNIQUE,
17+
sex sex_type NOT NULL,
18+
year INT NOT NULL,
19+
hostel VARCHAR NOT NULL,
20+
mac_address VARCHAR NOT NULL,
21+
discord_id VARCHAR NOT NULL,
22+
group_id INT NOT NULL,
23+
created_at TIMESTAMP NOT NULL
24+
);
25+
```
26+
27+
### Attendance Table
28+
```sql
29+
CREATE TABLE Attendance (
30+
attendance_id SERIAL PRIMARY KEY,
31+
member_id INT REFERENCES Member(member_id),
32+
date DATE NOT NULL,
33+
is_present BOOLEAN NOT NULL,
34+
time_in TIME,
35+
time_out TIME,
36+
created_at TIMESTAMP NOT NULL,
37+
updated_at TIMESTAMP NOT NULL
38+
);
39+
```
40+
41+
### AttendanceSummary Table
42+
```sql
43+
CREATE TABLE AttendanceSummary (
44+
member_id INT REFERENCES Member(member_id),
45+
year INT NOT NULL,
46+
month INT NOT NULL,
47+
days_attended INT NOT NULL DEFAULT 0,
48+
PRIMARY KEY (member_id, year, month)
49+
);
50+
```
51+
52+
### StatusUpdateStreak Table
53+
```sql
54+
CREATE TABLE StatusUpdateStreak (
55+
member_id INT REFERENCES Member(member_id),
56+
current_streak INT NOT NULL DEFAULT 0,
57+
max_streak INT NOT NULL,
58+
PRIMARY KEY (member_id)
59+
);
60+
```
61+
62+
## Managing Migrations
63+
64+
### Create Migration
65+
```bash
66+
sqlx migrate add <migration_name>
67+
```
68+
69+
### Run Migrations
70+
```bash
71+
sqlx migrate run
72+
```
73+
74+
### Revert Migration
75+
```bash
76+
sqlx migrate revert
77+
```

docs/docs.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
1-
# API Documentation
1+
# Root Documentation
22

3-
## Contents
4-
- [Managing Migrations](/docs/migrations.md)
5-
- [GraphQL Queries](/docs/queries.md)
6-
- [GraphQL Mutations](/docs/mutations.md)
3+
## Project Structure
4+
```
5+
src/
6+
├── graphql/ # GraphQL schema definitions
7+
│ ├── mutations/ # Data modification operations
8+
│ └── queries/ # Data retrieval operations
9+
├── models/ # Database models and types
10+
├── daily_task/ # Self explanatory
11+
└── routes.rs # HTTP routing setup
12+
```
13+
14+
## GraphQL API Structure
15+
- [Member Management](member.md) - Managing club member profiles
16+
- [Attendance System](attendance.md) - Daily attendance tracking and summaries
17+
- [Status Streaks](streaks.md) - Tracking daily status update streaks
18+
19+
## Database Schema
20+
- [Database](database.md) - Database structure and migrations
21+
22+
## Core Features
23+
### Member Management
24+
- Query members by ID, roll number, or Discord ID
25+
- Create and update member profiles
26+
27+
### Attendance System
28+
- Mark daily attendance with time tracking
29+
- Generate monthly attendance summaries
30+
31+
### Status Updates
32+
- Track daily status update streaks
33+
- Record maximum streaks achieved

docs/member.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Member Management
2+
3+
Manage club member profiles. This is the central entity for the database. Most things should relate to one or more members.
4+
5+
## Models
6+
7+
### Member
8+
```rust
9+
struct Member {
10+
member_id: i32,
11+
roll_no: String,
12+
name: String,
13+
email: String,
14+
sex: Sex,
15+
year: i32,
16+
hostel: String,
17+
mac_address: String,
18+
discord_id: String,
19+
group_id: i32,
20+
}
21+
```
22+
23+
## Queries
24+
25+
### Get Member
26+
Retrieve member details by ID, roll number, or Discord ID.
27+
28+
```graphql
29+
query {
30+
getMember(rollNo: "AM.XX.U4XXX") {
31+
name
32+
email
33+
year
34+
}
35+
}
36+
```
37+
38+
## Mutations
39+
40+
### Create Member
41+
Add a new member to the database.
42+
43+
```graphql
44+
mutation {
45+
createMember(
46+
input: {
47+
rollNo: "AM.XX.U4XXX"
48+
name: "John Doe"
49+
email: "john@amfoss.in"
50+
sex: "M"
51+
year: 2
52+
hostel: "MH"
53+
macAddress: "XX:XX:XX:XX:XX:XX"
54+
discordId: "123456789"
55+
groupId: 1
56+
}
57+
) {
58+
memberId
59+
name
60+
}
61+
}
62+
```

docs/migrations.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)