# abirhasankhan/sms-assessment architecture

> Architecture diagram of the GitHub repository abirhasankhan/sms-assessment, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abirhasankhan/sms-assessment
- Repository: https://github.com/abirhasankhan/sms-assessment

## Overview

##### Project Type & Purpose
- This is a full-stack School Management System designed to streamline school operations such as student/teacher management, attendance tracking, exam grading, fee management, and notifications.
- The README describes multiple user roles (Admin, Teacher, and Student) and lists features like schedule management, real-time notifications, and report generation.

##### Analyzing the File Structure
- The project is clearly divided into two major sections:
- /frontend: Contains the React-based client-side code including components, pages, state management (Zustand), and Tailwind CSS configuration.
- /backend: Contains the Node.js/Express server-side code including controllers (business logic), models (MongoDB schemas via Mongoose), routes (API endpoints), middleware (authentication token verification), and utilities (helper functions like token generation and email processing via Mailtrap).
- Key architectural patterns observed:
- MVC structure on the backend:
- Controllers (business logic)
- Models (data representations/schemas)
- Routes (API endpoints linking controllers)
- Separation of concerns by dividing the system into distinct frontend and backend services.
- Environment-based configuration using dotenv.
- Additional configuration files (e.g., package.json, .gitignore, Vite/ESLint/Tailwind configs) indicate standard setup and build processes.

a. Main Components:
- Frontend:
- React application: User Interface, Components (Navbar, Sidebar, pages for Attendance, Class, etc.), State Management (Zustand).
- Routing: React Router DOM for page navigation.
- HTTP Client: Communicates with backend APIs.
- Backend:
- Node.js server running on Express.
- Controllers: Business logic for handling various school management functionalities such as attendance, exam, fee, etc.
- Routes: Specific API endpoints that delegate requests to controllers.
- Models: Data models for students, teachers, classes, etc. via Mongoose.
- Database: MongoDB (accessed via Mongoose ODM) that stores all school-related data.
- Middleware: Authentication (JWT token verification) and email utilities (MailTrap configuration).
- External Services:
- Email Service: Handled by NodeMailer integrated with Mailtrap.
- Authentication: Use of JWT for secure route protection.

b. Relationships & Interactions:
- The frontend communicates with the backend via RESTful API calls.
- The backend, via its controllers and routes, interacts with the MongoDB database (using Mongoose) for CRUD operations on students, teachers, results, etc.
- Authentication flows use JWT for securing endpoints; tokens are generated and verified via middleware.
- An email service is incorporated to trigger notifications and verifications, linking backend routines to external mail services.
- Data flows: User actions on the frontend trigger API calls → Backend controllers process these requests → Database interactions occur → Responses are sent back to the frontend.

c. Highlighting Architectural Patterns & Design Principles:
- Use of MVC pattern on the backend for clear separation of concerns.
- RESTful API principles drive the backend’s design.
- Modular structure: Each major functionality (attendance, exam, fee, etc.) is separated into its own controller, model, and route file.
- State management on the frontend for handling authentication and user data with Zustand.
- Security is enhanced by JWT-based authentication with middleware verifying tokens.

d. Relevant Technologies & Frameworks:
- Frontend: React, Tailwind CSS, React Router DOM, Framer Motion, Zustand, React Toastify.
- Backend: Node.js, Express.js, MongoDB, Mongoose, JWT, NodeMailer, bcryptjs, dotenv.
- Build Tools/Configurations: Vite for frontend bundling, ESLint, PostCSS, and Tailwind configuration.

##### Elements
- Clear labels for each component:
- Frontend/UI, React Components, Pages, State Management (store)
- Backend: Controllers, Routes, Middleware, Models, Utility Functions
- Database (MongoDB)
- External Services (Email via NodeMailer/Mailtrap)
- Data flow from frontend → backend API calls.
- Backend interactions with MongoDB.
- Backend's invocation of external services (e.g., sending emails).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "Frontend"
        FE_App["React Application (App)"]:::frontend
        subgraph "Components"
            Navbar["Navbar"]:::frontend
            Sidebar["Sidebar"]:::frontend
            AddButton["AddButton"]:::frontend
        end
        subgraph "Pages"
            AttendancePage["AttendancePage"]:::frontend
            ClassPage["ClassPage"]:::frontend
        end
        FE_State["Auth Store (Zustand)"]:::frontend
    end

    %% Backend Subgraph
    subgraph "Backend"
        BE_Server["Express Server"]:::backend
        subgraph "API Layer"
            AttRoute["Attendance Route"]:::backend
            ExamRoute["Exam Route"]:::backend
        end
        subgraph "Business Logic"
            AC["Attendance Controller"]:::backend
            EC["Exam Controller"]:::backend
            BE_Middleware["JWT Middleware"]:::backend
            subgraph "Utilities"
                TokenUtil["Token & Cookie Utility"]:::backend
                VerificationUtil["Token Verification Utility"]:::backend
            end
        end
        subgraph "Data Models"
            Student["Student Model"]:::backend
            Teacher["Teacher Model"]:::backend
        end
    end

    %% Database Subgraph
    subgraph "Database"
        DB["MongoDB"]:::database
    end

    %% External Services Subgraph
    subgraph "External Services"
        ES["Email Service (NodeMailer/Mailtrap)"]:::external
        subgraph "Email Templates"
            ET["Email Templates"]:::external
        end
    end

    %% Frontend Connections
    Navbar --> FE_App
    Sidebar --> FE_App
    AddButton --> FE_App
    AttendancePage --> FE_App
    ClassPage --> FE_App
    FE_State --> FE_App
    FE_App -->|"REST_API"| BE_Server

    %% Backend Connections
    BE_Server -->|"Routes"| AttRoute
    BE_Server -->|"Routes"| ExamRoute
    AttRoute -->|"Calls"| AC
    ExamRoute -->|"Calls"| EC
    AttRoute -->|"AuthCheck"| BE_Middleware
    ExamRoute -->|"AuthCheck"| BE_Middleware
    AC -->|"Uses"| Student
    AC -->|"Uses"| Teacher
    EC -->|"Uses"| Student
    EC -->|"Uses"| Teacher
    Student -->|"CRUD"| DB
    Teacher -->|"CRUD"| DB
    AC -->|"SendsEmail"| ES
    EC -->|"SendsEmail"| ES
    AC -->|"TokenUtil"| TokenUtil
    AC -->|"TokenUtil"| VerificationUtil
    EC -->|"TokenUtil"| TokenUtil
    EC -->|"TokenUtil"| VerificationUtil

    %% Click Events for Frontend
    click FE_App "https://github.com/abirhasankhan/sms-assessment/blob/main/frontend/src/App.jsx"
    click Navbar "https://github.com/abirhasankhan/sms-assessment/blob/main/frontend/src/components/Navbar.jsx"
    click Sidebar "https://github.com/abirhasankhan/sms-assessment/blob/main/frontend/src/components/Sidebar.jsx"
    click AddButton "https://github.com/abirhasankhan/sms-assessment/blob/main/frontend/src/components/AddButton.jsx"
    click AttendancePage "https://github.com/abirhasankhan/sms-assessment/blob/main/frontend/src/pages/AttendancePage.jsx"
    click ClassPage "https://github.com/abirhasankhan/sms-assessment/blob/main/frontend/src/pages/ClassPage.jsx"
    click FE_State "https://github.com/abirhasankhan/sms-assessment/blob/main/frontend/src/store/authStore.js"

    %% Click Events for Backend
    click BE_Server "https://github.com/abirhasankhan/sms-assessment/blob/main/backend/index.js"
    click AC "https://github.com/abirhasankhan/sms-assessment/blob/main/backend/controllers/attendance.controller.js"
    click EC "https://github.com/abirhasankhan/sms-assessment/blob/main/backend/controllers/exam.controller.js"
    click AttRoute "https://github.com/abirhasankhan/sms-assessment/blob/main/backend/routes/attendance.route.js"
    click ExamRoute "https://github.com/abirhasankhan/sms-assessment/blob/main/backend/routes/exam.route.js"
    click Student "https://github.com/abirhasankhan/sms-assessment/blob/main/backend/models/student.model.js"
    click Teacher "https://github.com/abirhasankhan/sms-assessment/blob/main/backend/models/teacher.model.js"
    click BE_Middleware "https://github.com/abirhasankhan/sms-assessment/blob/main/backend/middleware/verifyToken.js"
    click TokenUtil "https://github.com/abirhasankhan/sms-assessment/blob/main/backend/utils/generateTokenAndSetCookie.js"
    click VerificationUtil "https://github.com/abirhasankhan/sms-assessment/blob/main/backend/utils/generateVerificationToken.js"

    %% Click Event for Database
    click DB "https://github.com/abirhasankhan/sms-assessment/blob/main/backend/db/connectDB.js"

    %% Click Events for External Services
    click ES "https://github.com/abirhasankhan/sms-assessment/blob/main/backend/mailtrap/mailtrap.config.js"
    click ET "https://github.com/abirhasankhan/sms-assessment/blob/main/backend/mailtrap/emailTemplates.js"

    %% Style Definitions
    classDef frontend fill:#fce5cd,stroke:#d79b00,stroke-width:2px;
    classDef backend fill:#d9e1f2,stroke:#316baf,stroke-width:2px;
    classDef database fill:#d9ead3,stroke:#6aa84f,stroke-width:2px;
    classDef external fill:#f4cccc,stroke:#cc0000,stroke-width:2px;
```
