# mohamedshawky70/education--management--system architecture

> Architecture diagram of the GitHub repository mohamedshawky70/education--management--system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mohamedshawky70/education--management--system
- Repository: https://github.com/mohamedshawky70/education--management--system

## Overview

##### Project Type and Purpose
- This is a full-stack backend API (Education Management System) built as a layered .NET solution. It exposes RESTful endpoints for managing Students, Teachers, Departments, Subjects, Assignments, Enrollments, and User/Role administration, all secured via JWT.

##### File-Structure Analysis
- Four top-level projects represent distinct layers:
- School.Api   – Web/API layer (Controllers, Program, DI, Templates).
- School.Application – Business-logic and service interfaces (DTOs, Validation, Mapping, Interfaces, Services, Error/Exception handling).
- School.Domain – Core entities and domain models.
- School.Infrastructure – Data access implementations (Entity Framework Core DbContext, Repository & UnitOf-Work, Migrations, Identity configs, external integrations).

##### README Insights
- Tech stack: .NET 9, Entity Framework Core, SQL Server, JWT Authentication, FluentValidation, Automapper/Mapster, Hangfire, Caching, Health Checks, Rate Limiting, CORS.
- Key workflows: Authentication (register, login, refresh/revoke tokens, email confirmation, password reset), Profile Management, Role-based access, CRUD flows for each entity, Enrollment linking.

##### Main Components
a. Client & Entry Points
- Web/Mobile client or Postman → HTTP(S) calls to School.Api (Controllers).
b. API Layer (School.Api)
- Controllers (AuthController, StudentController, etc.)
- Middleware: ExceptionHandler, CORS, RateLimiting, HealthChecks
- Templates/Email engine for confirmations & resets (via Hangfire)
c. Application Layer (School.Application)
- DTOs & Validators (FluentValidation)
- Service Interfaces (IAuthService, IStudentService, etc.)
- Automapper/Mapster mapping profiles
- Unit of Work & Result-pattern error handling
d. Domain Layer (School.Domain)
- Entities: ApplicationUser, Student, Teacher, Subject, Department, Assignment, Enrollment, RefreshToken
e. Infrastructure Layer (School.Infrastructure)
- EF Core DbContext → SQL Server
- Repository implementations (BaseRepo) & UnitOfWork
- Authentication: JwtProvider, AccountService, AuthService, RoleService, UserService
- Background Jobs: Hangfire (EmailSender)
- Caching (in-memory or distributed)
f. External Services
- SMTP/Email provider
- Hangfire dashboard & storage
- Optional Redis or in-memory cache

##### Relationships & Data Flow
1. Client → HTTP Request → API Layer Controllers
2. Controller injects Application-layer Service Interface
3. Service executes business logic, validation, mapping
4. Service calls Repository via UnitOfWork → Infrastructure
5. EF Core DbContext persists or queries SQL Server
6. Response bubbles back: Data → DTO → Controller → HTTP Response
7. For Auth: Controller → AuthService → JwtProvider → DB (RefreshToken) → return JWT + refresh token
8. Background tasks: Controller enqueues Hangfire job → EmailSender sends via SMTP

##### Architectural Patterns & Principles
- Layered (Presentation, Application, Domain, Infrastructure)
- Repository + Unit of Work
- Dependency Injection (centralized in Program.cs / DependencyInjection.cs)
- Result pattern for error handling
- FluentValidation for input validation
- Automapper/Mapster for object mapping
- JWT-based stateless authentication, Role-based authorization
- CQRS-style separation (read/write in services)
- API versioning via route templates

##### Final Recommendations
- Keep it hierarchical: top-level external clients & infra, mid-level API & services, bottom-level persistence & domain.
- Essential flows:
- Authentication sequence (Login → Token → Refresh → Revoke)
- CRUD flow for a sample entity (Student)
- Enrollment linking (StudentService → DepartmentSubjectService → EnrollmentService)
- Be exhaustive with components but avoid clutter: group similar services or controllers into packages.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    Client["Web/Mobile Client\nPostman"]:::ext

    %% API Layer
    subgraph "API Layer"
        Controllers["Controllers\n(AuthController, StudentController, etc.)"]:::api
        Middleware["Middleware\n(ExceptionHandler, CORS, RateLimiting, HealthChecks)"]:::api
        DIStartup["Program.cs\nDependencyInjection.cs"]:::api
        Templates["Email Templates\n(Confirmation, ForgetPassword)"]:::api
    end

    %% Application Layer
    subgraph "Application Layer"
        DTOs["DTOs"]:::app
        Validators["Validation\n(FluentValidation)"]:::app
        Interfaces["Service Interfaces\n(IAuthService, IStudentService, etc.)"]:::app
        Mapping["Mapping Profiles\n(MappingConfig.cs)"]:::app
        ErrorHandling["ErrorHandler &\nGlobalExceptionHandler"]:::app
        AppDI["DependencyInjection.cs"]:::app
    end

    %% Domain Layer
    subgraph "Domain Layer"
        Entities["Entities\n(ApplicationUser, Student, Teacher, etc.)"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        DbContext["ApplicationDbContext.cs"]:::infra
        EntityConfigs["EntitiesConfiguration"]:::infra
        BaseRepo["BaseRepo.cs"]:::infra
        UnitOfWork["UnitOfWork.cs"]:::infra
        AuthImpl["Auth Implementations\n(AccountService, AuthService, JwtProvider, RoleService, UserService, EmailSender)"]:::infra
        ServiceImpl["Service Implementations\n(CRUD)"]:::infra
        Migrations["Migrations"]:::infra
        InfraDI["DependencyInjection.cs"]:::infra
    end

    %% External Dependencies
    SMTP["SMTP/Email Provider"]:::ext
    SQL["SQL Server"]:::ext
    HangfireDB["Hangfire Storage"]:::ext
    HangfireDash["Hangfire Dashboard"]:::ext
    Cache["Cache\n(Redis/In-Memory)"]:::ext

    %% Flows
    Client -->|HTTP Request| Middleware
    Middleware -->|Route to Controller| Controllers
    Controllers -->|Calls Service Interface| Interfaces
    Controllers -->|Enqueue Email Job| AuthImpl
    Controllers -->|Enqueue Hangfire Job| HangfireDB
    Controllers -->|Templates| Templates

    Interfaces -->|Uses DTOs| DTOs
    Interfaces -->|Validates via| Validators
    Interfaces -->|Maps via| Mapping
    Interfaces -->|Error Handling| ErrorHandling
    Interfaces -->|Injected Impl| AuthImpl
    Interfaces -->|Injected Impl| ServiceImpl
    Interfaces -->|UnitOfWork| UnitOfWork

    AuthImpl -->|Saves RefreshToken| DbContext
    AuthImpl -->|Sends Email via| SMTP
    ServiceImpl -->|Uses Repos| BaseRepo
    ServiceImpl -->|Uses Cache| Cache
    UnitOfWork -->|Manages| BaseRepo
    BaseRepo -->|Queries| DbContext
    DbContext <-->|EF Core| SQL

    InfraDI -->|Registers| AuthImpl
    InfraDI -->|Registers| ServiceImpl
    AppDI -->|Registers| Interfaces

    %% Click events
    click Controllers "https://github.com/mohamedshawky70/education--management--system/tree/master/School.Api/Controllers"
    click DIStartup "https://github.com/mohamedshawky70/education--management--system/blob/master/School.Api/DependencyInjection.cs"
    click DIStartup "https://github.com/mohamedshawky70/education--management--system/blob/master/School.Api/Program.cs"
    click Templates "https://github.com/mohamedshawky70/education--management--system/blob/master/School.Api/Templates/EmailConfirmation.html"
    click Templates "https://github.com/mohamedshawky70/education--management--system/blob/master/School.Api/Templates/ForgetPassword.html"
    click DTOs "https://github.com/mohamedshawky70/education--management--system/tree/master/School.Application/DTOs"
    click Validators "https://github.com/mohamedshawky70/education--management--system/tree/master/School.Application/Validation"
    click Interfaces "https://github.com/mohamedshawky70/education--management--system/tree/master/School.Application/Interfaces/IServices"
    click Interfaces "https://github.com/mohamedshawky70/education--management--system/tree/master/School.Application/Interfaces/IAuthentication"
    click Interfaces "https://github.com/mohamedshawky70/education--management--system/tree/master/School.Application/Interfaces/IUser"
    click Mapping "https://github.com/mohamedshawky70/education--management--system/blob/master/School.Application/Mapping/MappingConfig.cs"
    click ErrorHandling "https://github.com/mohamedshawky70/education--management--system/tree/master/School.Application/ErrorHandler"
    click ErrorHandling "https://github.com/mohamedshawky70/education--management--system/blob/master/School.Application/ExceptionHandler/GlobalExceptionHandler.cs"
    click AppDI "https://github.com/mohamedshawky70/education--management--system/blob/master/School.Application/DependencyInjection.cs"
    click Entities "https://github.com/mohamedshawky70/education--management--system/tree/master/School.Domain/Entities"
    click DbContext "https://github.com/mohamedshawky70/education--management--system/blob/master/School.Infrastructure/Data/ApplicationDbContext.cs"
    click EntityConfigs "https://github.com/mohamedshawky70/education--management--system/tree/master/School.Infrastructure/EntitiesConfiguration"
    click BaseRepo "https://github.com/mohamedshawky70/education--management--system/blob/master/School.Infrastructure/Implementation/BaseRepo/BaseRepo.cs"
    click UnitOfWork "https://github.com/mohamedshawky70/education--management--system/blob/master/School.Infrastructure/Implementation/UnitOfWork/UnitOfWork.cs"
    click AuthImpl "https://github.com/mohamedshawky70/education--management--system/tree/master/School.Infrastructure/Implementation/Authentication"
    click ServiceImpl "https://github.com/mohamedshawky70/education--management--system/tree/master/School.Infrastructure/Implementation/Services"
    click Migrations "https://github.com/mohamedshawky70/education--management--system/tree/master/School.Infrastructure/Migrations"
    click InfraDI "https://github.com/mohamedshawky70/education--management--system/blob/master/School.Infrastructure/DependencyInjection.cs"

    %% Styles
    classDef api fill:#D0E7FF,stroke:#0366D6,color:#0366D6,stroke-width:1px;
    classDef app fill:#DFFFE0,stroke:#2E8B57,color:#2E8B57,stroke-width:1px;
    classDef domain fill:#FFF5CC,stroke:#DAA520,color:#DAA520,stroke-width:1px;
    classDef infra fill:#FFE4CC,stroke:#FF8C00,color:#FF8C00,stroke-width:1px;
    classDef ext fill:#E0E0E0,stroke:#666666,color:#333333,stroke-width:1px;
```
